From 35930fd49039ec48680c9240cfdb39b6e1101bfa Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 25 Jan 2022 00:21:07 +0530 Subject: feat(eval): adds eval for regex --- src/eval/index.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/eval/index.ts') 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 { @@ -52,11 +52,15 @@ const checkExpr = ( 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({ + 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 -- cgit v1.3.1