aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md3
-rw-r--r--src/eval/index.ts11
-rw-r--r--tests/eval.spec.ts13
3 files changed, 27 insertions, 0 deletions
diff --git a/TODO.md b/TODO.md
index 37b7449..b471dc5 100644
--- a/TODO.md
+++ b/TODO.md
@@ -10,3 +10,6 @@
- [ ] Func: match
- [ ] Func: replace
+## Issues
+ - [ ] . should not match for empty list
+
diff --git a/src/eval/index.ts b/src/eval/index.ts
index b4dcf48..d5c56c2 100644
--- a/src/eval/index.ts
+++ b/src/eval/index.ts
@@ -1,4 +1,5 @@
import { pipe } from 'fp-ts/function'
+import {takeLeftWhile} from 'fp-ts/lib/Array'
import { Expr, ListExpr } from '../types'
import { match } from '../utils'
@@ -18,6 +19,16 @@ export const find = <T>([startO, exprs, endO]: ListExpr, list: T[]): any => {
Group: ({ exprs }) => exprs.every(e => check(e)(x, i, ls)),
PropertyMatch: ({ name, exprs }) =>
name in x && exprs.every(e => check(e)(x[name], i, ls)),
+ OneOrMore: ({ expr }) => {
+ // TODO: Nested quantified expression
+ const x = pipe(
+ list.slice(i),
+ takeLeftWhile(x => check(expr)(x, i, list)),
+ )
+ console.log(x)
+
+ return true
+ },
_: _ => false,
}),
)
diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts
index dada762..8c79375 100644
--- a/tests/eval.spec.ts
+++ b/tests/eval.spec.ts
@@ -60,4 +60,17 @@ describe('Eval', () => {
expect(find(liexp, list)).toEqual([{ name: 'gello', age: 20 }])
})
+
+ xit('with groups', () => {
+ const list = [0, 1, 1, 1, '2', 3, 4, [4], 5, '']
+
+ const liexp: ListExpr = [
+ none,
+ [
+ Expr.OneOrMore({ expr: Expr.AnyNumber(null) }),
+ ],
+ none,
+ ]
+ expect(find(liexp, list)).toEqual([1, 3, 5])
+ })
})