aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-13 21:20:35 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-13 21:42:11 +0530
commitba94e799aa352c2fd472b694c745388e3e9feee8 (patch)
treee27c99304ed0268f6c9f8c438ae1d17dd269557a /src
parent016821207f1f2294dd09935a4c1d14d78ff3aed1 (diff)
downloadelxr-ba94e799aa352c2fd472b694c745388e3e9feee8.tar.gz
elxr-ba94e799aa352c2fd472b694c745388e3e9feee8.zip
feat(eval): implements or
Diffstat (limited to 'src')
-rw-r--r--src/eval/index.ts15
-rw-r--r--src/types.ts2
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>()