aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-25 00:21:07 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-25 00:21:07 +0530
commit35930fd49039ec48680c9240cfdb39b6e1101bfa (patch)
tree7c5196a0952d91349ac8b35e5a3553c39305f646 /src
parentea0baf1bb82d40ebfcaca1de6a2a0f6d56c709e7 (diff)
downloadelxr-35930fd49039ec48680c9240cfdb39b6e1101bfa.tar.gz
elxr-35930fd49039ec48680c9240cfdb39b6e1101bfa.zip
feat(eval): adds eval for regex
Diffstat (limited to 'src')
-rw-r--r--src/eval/index.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/eval/index.ts b/src/eval/index.ts
index 96ccbef..f8d14d3 100644
--- a/src/eval/index.ts
+++ b/src/eval/index.ts
@@ -1,7 +1,7 @@
import { identity, pipe } from 'fp-ts/function'
import { filter, takeLeftWhile, zip, zipWith } from 'fp-ts/Array'
import * as Option from 'fp-ts/Option'
-import { index, Expr, ListExpr } from '../types'
+import { index, Expr, ListExpr, Literal } from '../types'
import { match } from '../utils'
export interface MatchGroupIndexed<T = any> {
@@ -52,11 +52,15 @@ const checkExpr = <T>(
pipe(typeof item === 'boolean' ? [group(item, index)] : [], skip(1)),
Truthy: _ => pipe(!!item ? [group(item, index)] : [], skip(1)),
Falsey: _ => pipe(!item ? [group(item, index)] : [], skip(1)),
- Literal: literal =>
- pipe(
- (literal.value as any) === item ? [group(item, index)] : [],
- skip(1),
- ),
+ Literal: literal => pipe(
+ literal,
+ match<boolean, Literal>({
+ RegExp: regex => regex && typeof item === 'string' && regex.test(item),
+ _: () => (literal.value as any) === item,
+ }),
+ passed => passed ? [group(item, index)] : [],
+ skip(1),
+ ),
Group: ({ exprs }) => {
const [head, ...tail] = exprs