aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-13 17:54:27 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-13 17:54:35 +0530
commit1a281a717fe5bab2694bf51c1b03a7569d8facb4 (patch)
treeea0ff4e5ee4d579aed4750d53503b33aab5cb818 /src
parentfc548093f151355842122912c582fc10a2d5acb2 (diff)
downloadelxr-1a281a717fe5bab2694bf51c1b03a7569d8facb4.tar.gz
elxr-1a281a717fe5bab2694bf51c1b03a7569d8facb4.zip
feat(eval): adds literal equality check
Diffstat (limited to 'src')
-rw-r--r--src/eval/index.ts16
1 files changed, 13 insertions, 3 deletions
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<T = any> {
@@ -33,7 +33,9 @@ const checkExpr = <T>(
item: T,
list: T[],
index: number,
- skip: (n: index) => (m: MatchGroupIndexed<T | T[]>[]) => MatchGroupIndexed<T | T[]>[] = _ =>
+ skip: (
+ n: index,
+ ) => (m: MatchGroupIndexed<T | T[]>[]) => MatchGroupIndexed<T | T[]>[] = _ =>
identity,
): MatchGroupIndexed<T | T[]>[] => {
return pipe(
@@ -48,6 +50,11 @@ 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),
+ ),
Group: ({ exprs }) => {
const [head, ...tail] = exprs
@@ -90,7 +97,10 @@ const checkExpr = <T>(
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),
+ )
},
_: _ => [],