diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-13 21:20:35 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-13 21:42:11 +0530 |
| commit | ba94e799aa352c2fd472b694c745388e3e9feee8 (patch) | |
| tree | e27c99304ed0268f6c9f8c438ae1d17dd269557a /src | |
| parent | 016821207f1f2294dd09935a4c1d14d78ff3aed1 (diff) | |
| download | elxr-ba94e799aa352c2fd472b694c745388e3e9feee8.tar.gz elxr-ba94e799aa352c2fd472b694c745388e3e9feee8.zip | |
feat(eval): implements or
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/index.ts | 15 | ||||
| -rw-r--r-- | src/types.ts | 2 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/eval/index.ts b/src/eval/index.ts index 4c47adf..d0d7363 100644 --- a/src/eval/index.ts +++ b/src/eval/index.ts @@ -82,6 +82,14 @@ const checkExpr = <T>( ) }, + Or: ({ exprs }) => { + const match = exprs.find(expr => checkExpr(expr, item, list, index).length > 0) + return pipe( + match ? [group(item, index)] : [], + skip(1), + ) + }, + PropertyMatch: ({ name, expr }) => pipe( Object.prototype.hasOwnProperty.call(item ?? {}, name) @@ -103,13 +111,6 @@ const checkExpr = <T>( ) }, - // Or: ({ left, right }) => { - // return pipe( - // [], - // skip(1), - // ) - // }, - _: _ => { throw new Error(`TODO: ${expr.tag} not implemented for match`) }, }), ) diff --git a/src/types.ts b/src/types.ts index 97ff81d..bc30453 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,7 +16,6 @@ export type Expr = Union<{ Optional: { expr: Expr }, OneOrMore: { expr: Expr }, ZeroOrMore: { expr: Expr }, - NextItem: _, AnyItem: _, Or: { exprs: Expr[] }, AnyString: _, @@ -27,6 +26,7 @@ export type Expr = Union<{ Group: { exprs: Expr[] }, PropertyMatch: { name: string, expr: Expr }, Literal: Literal, + NextItem: _, }> export const Expr = constructors<Expr>() |
