From 801575e8ab62ff5c55bf6499d1cee0a1f1f7d1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lichtenth=C3=A4ler?= Date: Sun, 7 Aug 2022 15:55:53 +0200 Subject: [PATCH] refactor: remove redundant type annotations (#163) #162 --- src/combinators/anyOf.ts | 4 ++-- src/combinators/between.ts | 4 ++-- src/combinators/many.ts | 2 +- src/combinators/many1.ts | 2 +- src/combinators/separatedBy.ts | 4 ++-- src/combinators/sequenceOf.ts | 2 +- src/parsers/endOfInput.ts | 4 ++-- src/parsers/endOfLine.ts | 4 ++-- src/parsers/number.ts | 4 ++-- src/parsers/regex.ts | 4 ++-- src/parsers/string.ts | 4 ++-- src/parsers/whitespace.ts | 4 ++-- src/parsers/word.ts | 4 ++-- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/combinators/anyOf.ts b/src/combinators/anyOf.ts index d85895c..a64151b 100644 --- a/src/combinators/anyOf.ts +++ b/src/combinators/anyOf.ts @@ -1,5 +1,5 @@ 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. @@ -7,7 +7,7 @@ import { ParserState, updateParserError, updateParserResult } from "../ParserSta * @see https://rudus.pages.dev/docs/api/combinators/anyOf */ export const anyOf = (parsers: Array) => - new Parser((state: ParserState): ParserState => { + new Parser(state => { if (state.isError) return state; for (const parser of parsers) { diff --git a/src/combinators/between.ts b/src/combinators/between.ts index 9223856..cda8d42 100644 --- a/src/combinators/between.ts +++ b/src/combinators/between.ts @@ -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`. @@ -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); diff --git a/src/combinators/many.ts b/src/combinators/many.ts index 26ea75c..40d03c1 100644 --- a/src/combinators/many.ts +++ b/src/combinators/many.ts @@ -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 = []; diff --git a/src/combinators/many1.ts b/src/combinators/many1.ts index 66e3de1..fdcfa60 100644 --- a/src/combinators/many1.ts +++ b/src/combinators/many1.ts @@ -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 = []; let nextState: ParserState = state; let done = false; diff --git a/src/combinators/separatedBy.ts b/src/combinators/separatedBy.ts index 3c5e06d..83fdaa4 100644 --- a/src/combinators/separatedBy.ts +++ b/src/combinators/separatedBy.ts @@ -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` @@ -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); diff --git a/src/combinators/sequenceOf.ts b/src/combinators/sequenceOf.ts index 8373961..8d0a328 100644 --- a/src/combinators/sequenceOf.ts +++ b/src/combinators/sequenceOf.ts @@ -8,7 +8,7 @@ import { ParserState, updateParserError, updateParserResult } from "../ParserSta * @see https://rudus.pages.dev/docs/api/combinators/sequenceOf */ export const sequenceOf = (parsers: Array) => - new Parser((state: ParserState): ParserState => { + new Parser(state => { let i = 0; const results: Array = []; let nextState: ParserState = state; diff --git a/src/parsers/endOfInput.ts b/src/parsers/endOfInput.ts index 66bd5e5..e2abf84 100644 --- a/src/parsers/endOfInput.ts +++ b/src/parsers/endOfInput.ts @@ -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, diff --git a/src/parsers/endOfLine.ts b/src/parsers/endOfLine.ts index 036c17a..1b85ac8 100644 --- a/src/parsers/endOfLine.ts +++ b/src/parsers/endOfLine.ts @@ -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]; diff --git a/src/parsers/number.ts b/src/parsers/number.ts index fa00fa6..6c9dffa 100644 --- a/src/parsers/number.ts +++ b/src/parsers/number.ts @@ -1,5 +1,5 @@ import { Parser } from "../Parser"; -import { ParserState, updateParserError, updateParserState } from "../ParserState"; +import { updateParserError, updateParserState } from "../ParserState"; /** * Tries to match a given number. @@ -7,7 +7,7 @@ import { ParserState, updateParserError, updateParserState } from "../ParserStat * @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); diff --git a/src/parsers/regex.ts b/src/parsers/regex.ts index cc0042b..3fc4425 100644 --- a/src/parsers/regex.ts +++ b/src/parsers/regex.ts @@ -1,5 +1,5 @@ import { Parser } from "../Parser"; -import { ParserState, updateParserError, updateParserState } from "../ParserState"; +import { updateParserError, updateParserState } from "../ParserState"; /** * Tries to match a given regex. @@ -7,7 +7,7 @@ import { ParserState, updateParserError, updateParserState } from "../ParserStat * @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) { diff --git a/src/parsers/string.ts b/src/parsers/string.ts index 694c5ab..136cd9c 100644 --- a/src/parsers/string.ts +++ b/src/parsers/string.ts @@ -1,5 +1,5 @@ import { Parser } from "../Parser"; -import { ParserState, updateParserError, updateParserState } from "../ParserState"; +import { updateParserError, updateParserState } from "../ParserState"; /** * Tries to match a given string. @@ -7,7 +7,7 @@ import { ParserState, updateParserError, updateParserState } from "../ParserStat * @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) diff --git a/src/parsers/whitespace.ts b/src/parsers/whitespace.ts index 86721bb..35e01e8 100644 --- a/src/parsers/whitespace.ts +++ b/src/parsers/whitespace.ts @@ -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]; diff --git a/src/parsers/word.ts b/src/parsers/word.ts index 7864ba8..3ddb54c 100644 --- a/src/parsers/word.ts +++ b/src/parsers/word.ts @@ -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];