diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 18:14:59 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 18:16:48 +0530 |
| commit | e8322ca988fc20baf7892915e6ccb069b11c608e (patch) | |
| tree | eaef108f21389268d42218eacde2256884a62f64 /src/parser/index.ts | |
| parent | e1092bfca260412ab716710d31c24c86d3a818e1 (diff) | |
| download | elxr-e8322ca988fc20baf7892915e6ccb069b11c608e.tar.gz elxr-e8322ca988fc20baf7892915e6ccb069b11c608e.zip | |
feat(parser): implements or syntax
Diffstat (limited to '')
| -rw-r--r-- | src/parser/index.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/parser/index.ts b/src/parser/index.ts index ec29099..b8e6764 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -8,6 +8,7 @@ import { or, Parser, ParserResult, + prefixed, symbol, tuple3, } from './utils' @@ -36,6 +37,17 @@ export const wrapQuantifiers: (e: ParserResult<Expr>) => ParserResult<Expr> = ), ) +export const wrapAlt: (e: ParserResult<Expr>) => ParserResult<Expr> = chain( + ([expr, input]) => + pipe( + input, + mapTo(prefixed(symbol('|'), many1(expressionP)), rest => + Expr.Or({ left: expr, right: rest }), + ), + orElse(_ => right([expr, input])), + ), +) + export const expressionP: Parser<Expr> = (input: string) => pipe( input, @@ -52,6 +64,7 @@ export const expressionP: Parser<Expr> = (input: string) => falsey, ]), wrapQuantifiers, + wrapAlt, ) export const parser = tuple3(optional(start), many1(expressionP), optional(end)) @@ -62,7 +75,6 @@ export const parser = tuple3(optional(start), many1(expressionP), optional(end)) (> 5) => number greater than (< 5) => number less than [name x] => apply x on property `name` -| => or /x/ => match regular expression (string values in list) */ |
