Skip to content

Commit

Permalink
refactor: remove redundant type annotations (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikossor authored Aug 7, 2022
1 parent 619d17c commit 801575e
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/combinators/anyOf.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserResult } from "../ParserState";
import { updateParserError, updateParserResult } from "../ParserState";

/**
* Tries to match all `parsers` and returns the first successful one.
* @param parsers
* @see https://rudus.pages.dev/docs/api/combinators/anyOf
*/
export const anyOf = (parsers: Array<Parser>) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
if (state.isError) return state;

for (const parser of parsers) {
Expand Down
4 changes: 2 additions & 2 deletions src/combinators/between.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserResult } from "../ParserState";
import { updateParserError, updateParserResult } from "../ParserState";

/**
* Tries to match a given `inner` surrounded by a given `outerLeft` and `outerRight`. The `outerRight` parser is optional and defaults to `outerLeft`.
Expand All @@ -8,7 +8,7 @@ import { ParserState, updateParserError, updateParserResult } from "../ParserSta
export const between =
(outerLeft: Parser, outerRight: Parser = outerLeft) =>
(inner: Parser) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
//#region outerLeft: Parser
const outerLeftParserState = outerLeft.transformState(state);

Expand Down
2 changes: 1 addition & 1 deletion src/combinators/many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ParserState, updateParserResult } from "../ParserState";
* @param parser
*/
export const many = (parser: Parser) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
if (state.isError) return state;

const results: Array<ParserStateResult> = [];
Expand Down
2 changes: 1 addition & 1 deletion src/combinators/many1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ParserState, updateParserResult, updateParserError } from "../ParserSta
* @see https://rudus.pages.dev/docs/api/combinators/many1
*/
export const many1 = (parser: Parser) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const results: Array<ParserStateResult> = [];
let nextState: ParserState = state;
let done = false;
Expand Down
4 changes: 2 additions & 2 deletions src/combinators/separatedBy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserResult } from "../ParserState";
import { updateParserError, updateParserResult } from "../ParserState";

/**
* - Tries to match a given `value` separated by a given `separator`
Expand All @@ -9,7 +9,7 @@ import { ParserState, updateParserError, updateParserResult } from "../ParserSta
* @see https://rudus.pages.dev/docs/api/combinators/separatedBy
*/
export const separatedBy = (separator: Parser) => (value: Parser) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
//#region value: Parser
const valueParserState = value.transformState(state);

Expand Down
2 changes: 1 addition & 1 deletion src/combinators/sequenceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ParserState, updateParserError, updateParserResult } from "../ParserSta
* @see https://rudus.pages.dev/docs/api/combinators/sequenceOf
*/
export const sequenceOf = (parsers: Array<Parser>) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
let i = 0;
const results: Array<ParserStateResult> = [];
let nextState: ParserState = state;
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/endOfInput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserResult } from "../ParserState";
import { updateParserError, updateParserResult } from "../ParserState";

/**
* Checks if there is nothing left to parse otherwise it fails.
* @see https://rudus.pages.dev/docs/api/parsers/endOfInput
*/
export const endOfInput = () =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
if (state.input.slice(state.offset) !== "") {
return updateParserError(
state,
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/endOfLine.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match an end of line (either `\r\n`, `\r` or `\n`)
* @see https://rudus.pages.dev/docs/api/parsers/endOfLine
*/
export const endOfLine = () =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const endOfLineRegex = new RegExp(/(\r\n|\r|\n)/);
const [fullMatch] = endOfLineRegex.exec(state.input.slice(state.offset)) || [null];

Expand Down
4 changes: 2 additions & 2 deletions src/parsers/number.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match a given number.
* @param searchString
* @see https://rudus.pages.dev/docs/api/parsers/number
*/
export const number = (searchString: number) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const asString = searchString.toString();
const matched = state.input.slice(state.offset).startsWith(asString);

Expand Down
4 changes: 2 additions & 2 deletions src/parsers/regex.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match a given regex.
* @param searchString
* @see https://rudus.pages.dev/docs/api/parsers/regex
*/
export const regex = (searchString: RegExp) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const [fullMatch] = searchString.exec(state.input.slice(state.offset)) || [null];

if (fullMatch === null) {
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/string.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match a given string.
* @param searchString
* @see https://rudus.pages.dev/docs/api/parsers/string
*/
export const string = (searchString: string) =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const matched = state.input.slice(state.offset).startsWith(searchString);

if (!matched)
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/whitespace.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match one or more whitespaces (regex: `/[\r\n\t\f\v ]+/`).
* @see https://rudus.pages.dev/docs/api/parsers/whitespace
*/
export const whitespace = () =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const regexWhitespace = /\s+/;
const [fullMatch] = regexWhitespace.exec(state.input.slice(state.offset)) || [null];

Expand Down
4 changes: 2 additions & 2 deletions src/parsers/word.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Parser } from "../Parser";
import { ParserState, updateParserError, updateParserState } from "../ParserState";
import { updateParserError, updateParserState } from "../ParserState";

/**
* Tries to match one or more words (regex: `/[a-zA-Z0-9_]+/`).
* @see https://rudus.pages.dev/docs/api/parsers/word
*/
export const word = () =>
new Parser((state: ParserState): ParserState => {
new Parser(state => {
const regexWord = /\w+/;
const [fullMatch] = regexWord.exec(state.input.slice(state.offset)) || [null];

Expand Down

0 comments on commit 801575e

Please sign in to comment.