diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 17:44:05 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 17:45:18 +0530 |
| commit | e1092bfca260412ab716710d31c24c86d3a818e1 (patch) | |
| tree | 05ea30f8899fed36f6b644733a644bd71ee30dcc | |
| parent | 173b249d9a91d8fee7c3cc18946e8fda188295c2 (diff) | |
| download | elxr-e1092bfca260412ab716710d31c24c86d3a818e1.tar.gz elxr-e1092bfca260412ab716710d31c24c86d3a818e1.zip | |
chore: prettier config change + formatting
| -rw-r--r-- | .prettierrc | 5 | ||||
| -rw-r--r-- | src/parser/index.ts | 34 | ||||
| -rw-r--r-- | src/parser/utils.ts | 48 | ||||
| -rw-r--r-- | src/utils.ts | 2 | ||||
| -rw-r--r-- | tsconfig.json | 1 |
5 files changed, 46 insertions, 44 deletions
diff --git a/.prettierrc b/.prettierrc index f491fe1..8a955a2 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,6 +1,7 @@ { "semi": false, - "trailingComma": "es5", + "trailingComma": "all", "singleQuote": true, - "printWidth": 80 + "printWidth": 80, + "arrowParens": "avoid", } diff --git a/src/parser/index.ts b/src/parser/index.ts index 9e284f6..ec29099 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -13,35 +13,35 @@ import { } from './utils' import { Expr } from '../types' -export const start = mapTo(symbol('^'), () => Expr.Start(null)) -export const end = mapTo(symbol('$'), () => Expr.End(null)) -export const anyItem = mapTo(symbol('.'), () => Expr.AnyItem(null)) -export const nextItem = mapTo(symbol(','), () => Expr.NextItem(null)) -export const anyString = mapTo(symbol('\\s'), () => Expr.AnyString(null)) -export const anyNumber = mapTo(symbol('\\n'), () => Expr.AnyNumber(null)) -export const anyBool = mapTo(symbol('\\b'), () => Expr.AnyBool(null)) -export const truthy = mapTo(symbol('\\T'), () => Expr.Truthy(null)) -export const falsey = mapTo(symbol('\\F'), () => Expr.Falsey(null)) +export const start = mapTo(symbol('^'), _ => Expr.Start(null)) +export const end = mapTo(symbol('$'), _ => Expr.End(null)) +export const anyItem = mapTo(symbol('.'), _ => Expr.AnyItem(null)) +export const nextItem = mapTo(symbol(','), _ => Expr.NextItem(null)) +export const anyString = mapTo(symbol('\\s'), _ => Expr.AnyString(null)) +export const anyNumber = mapTo(symbol('\\n'), _ => Expr.AnyNumber(null)) +export const anyBool = mapTo(symbol('\\b'), _ => Expr.AnyBool(null)) +export const truthy = mapTo(symbol('\\T'), _ => Expr.Truthy(null)) +export const falsey = mapTo(symbol('\\F'), _ => Expr.Falsey(null)) export const wrapQuantifiers: (e: ParserResult<Expr>) => ParserResult<Expr> = chain(([expr, input]) => pipe( input, or([ - mapTo(symbol('*'), () => Expr.ZeroOrMore({ expr })), - mapTo(symbol('+'), () => Expr.OneOrMore({ expr })), - mapTo(symbol('?'), () => Expr.Optional({ expr })), + mapTo(symbol('*'), _ => Expr.ZeroOrMore({ expr })), + mapTo(symbol('+'), _ => Expr.OneOrMore({ expr })), + mapTo(symbol('?'), _ => Expr.Optional({ expr })), ]), - orElse(() => right([expr, input])) - ) + orElse(_ => right([expr, input])), + ), ) export const expressionP: Parser<Expr> = (input: string) => pipe( input, or([ - mapTo(delimited(symbol('('), many1(expressionP), symbol(')')), (exprs) => - Expr.Group({ exprs }) + mapTo(delimited(symbol('('), many1(expressionP), symbol(')')), exprs => + Expr.Group({ exprs }), ), nextItem, anyItem, @@ -51,7 +51,7 @@ export const expressionP: Parser<Expr> = (input: string) => truthy, falsey, ]), - wrapQuantifiers + wrapQuantifiers, ) export const parser = tuple3(optional(start), many1(expressionP), optional(end)) diff --git a/src/parser/utils.ts b/src/parser/utils.ts index 00b50f8..a06b6c9 100644 --- a/src/parser/utils.ts +++ b/src/parser/utils.ts @@ -29,14 +29,14 @@ export const many0 = <T>(parser: Parser<T>): Parser<Array<T>> => flow( parser, chain(([a, nextInput]) => - pipe(nextInput, many0(parser), map(mapFst((ls) => [a, ...ls]))) + pipe(nextInput, many0(parser), map(mapFst(ls => [a, ...ls]))), ), orElse( flow( - mapFst((_) => [] as T[]), - right - ) - ) + mapFst(_ => [] as T[]), + right, + ), + ), ) export const many1 = <T>(parser: Parser<T>): Parser<Array<T>> => @@ -45,8 +45,8 @@ export const many1 = <T>(parser: Parser<T>): Parser<Array<T>> => chain(([res, inp]) => res.length > 0 ? right([res, inp]) - : left([`many1 failed to parse at ${inp}`, inp]) - ) + : left([`many1 failed to parse at ${inp}`, inp]), + ), ) const recoverInput = @@ -57,10 +57,10 @@ const recoverInput = p, orElseW( flow( - mapSnd((_) => input), - left - ) - ) + mapSnd(_ => input), + left, + ), + ), ) export const prefixed = <T>(a: Parser<any>, b: Parser<T>): Parser<T> => @@ -70,14 +70,14 @@ export const suffixed = <T>(a: Parser<T>, b: Parser<any>): Parser<T> => recoverInput( flow( a, - chain(([out, inp]) => pipe(inp, b, map(mapFst((_) => out)))) - ) + chain(([out, inp]) => pipe(inp, b, map(mapFst(_ => out)))), + ), ) export const delimited = <T>( p: Parser<any>, a: Parser<T>, - s: Parser<any> + s: Parser<any>, ): Parser<T> => suffixed(prefixed(p, a), s) export const satifyChar = @@ -88,18 +88,18 @@ export const satifyChar = return left([`Expected to satisfy ${f}, got "${c}"`, input]) } -export const digit = satifyChar((c) => /^[0-9]$/g.test(c)) +export const digit = satifyChar(c => /^[0-9]$/g.test(c)) export const integer: Parser<number> = flow( many1(digit), - map(mapFst((ds) => parseInt(ds.join(''), 10))) + map(mapFst(ds => parseInt(ds.join(''), 10))), ) export const or = <T>(parsers: Parser<T>[]): Parser<T> => { const run = ([p, ...ps]: Parser<T>[]) => flow( p, - orElse(([_, inp]) => or(ps)(inp)) + orElse(([_, inp]) => or(ps)(inp)), ) return parsers.length > 0 @@ -134,7 +134,7 @@ export const andThen = (p: Parser<I>): Parser<R> => flow( p, - chain(([v, inp]) => f(v)(inp)) + chain(([v, inp]) => f(v)(inp)), ) export const optional = <T>(p: Parser<T>): Parser<Option<T>> => @@ -142,21 +142,21 @@ export const optional = <T>(p: Parser<T>): Parser<Option<T>> => p, fold( flow( - mapFst((_) => none), - right + mapFst(_ => none), + right, ), - flow(mapFst(some), right) - ) + flow(mapFst(some), right), + ), ) export const pair = <A, B>(a: Parser<A>, b: Parser<B>): Parser<[A, B]> => pipe( a, - andThen((ra) => mapTo(b, (rb) => [ra, rb])) + andThen(ra => mapTo(b, rb => [ra, rb])), ) export const tuple3 = <A, B, C>( a: Parser<A>, b: Parser<B>, - c: Parser<C> + c: Parser<C>, ): Parser<[A, B, C]> => mapTo(pair(pair(a, b), c), ([[a, b], c]) => [a, b, c]) diff --git a/src/utils.ts b/src/utils.ts index 6591050..7e3009f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -20,5 +20,5 @@ export const constructors = <T extends Record<string, any>>(): { get(_, k) { return (value: any) => ({ tag: k, value }) }, - } + }, ) as any diff --git a/tsconfig.json b/tsconfig.json index cc1f11b..aa7207d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": false, "esModuleInterop": true, "moduleResolution": "node", + "noImplicitReturns": true, "checkJs": false, "outDir": "lib", "baseUrl": "." |
