From 1a281a717fe5bab2694bf51c1b03a7569d8facb4 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 13 Jan 2022 17:54:27 +0530 Subject: feat(eval): adds literal equality check --- src/eval/index.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/eval') diff --git a/src/eval/index.ts b/src/eval/index.ts index 276f686..075ff81 100644 --- a/src/eval/index.ts +++ b/src/eval/index.ts @@ -9,7 +9,7 @@ import { Option, some, } from 'fp-ts/lib/Option' -import { Expr, ListExpr } from '../types' +import { Expr, ListExpr, Literal } from '../types' import { match } from '../utils' export interface MatchGroupIndexed { @@ -33,7 +33,9 @@ const checkExpr = ( item: T, list: T[], index: number, - skip: (n: index) => (m: MatchGroupIndexed[]) => MatchGroupIndexed[] = _ => + skip: ( + n: index, + ) => (m: MatchGroupIndexed[]) => MatchGroupIndexed[] = _ => identity, ): MatchGroupIndexed[] => { return pipe( @@ -48,6 +50,11 @@ 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), + ), Group: ({ exprs }) => { const [head, ...tail] = exprs @@ -90,7 +97,10 @@ const checkExpr = ( list, takeLeftWhile(a => checkExpr(expr, a, list, index).length > 0), ) - return pipe(matches.length > 0 ? [group(matches, index)] : [], skip(matches.length || 1)) + return pipe( + matches.length > 0 ? [group(matches, index)] : [], + skip(matches.length || 1), + ) }, _: _ => [], -- cgit v1.3.1