diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/index.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/eval/index.ts b/src/eval/index.ts index ed757e7..96ccbef 100644 --- a/src/eval/index.ts +++ b/src/eval/index.ts @@ -108,6 +108,23 @@ const checkExpr = <T>( ) }, + MinMax: ({ expr, min, max }) => { + const { localSkip, getSkips } = accumulateSkip() + const result = checkExpr(Expr.ZeroOrMore({ expr }), item, list, index, localSkip) + // TODO: Use nested skips + + const matches = result[0].value.length + const capturedMatchCount = matches < min ? 0 : Math.min(matches, max) + // const skipCount = getSkips().reduce((a, b) => a + b, 0) + + return pipe( + result + .map(r => ({ ...r, value: r.value.slice(0, capturedMatchCount) })) + .filter(r => r.value.length > 0), + skip(capturedMatchCount || 1), + ) + }, + ZeroOrMore: ({ expr }) => { // TODO: Nested quantified expressions? const matches = pipe( |
