From e26086fef3cf142cffd145836a4c7c12cfeb9656 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 13 Jan 2022 17:58:36 +0530 Subject: refactor: propertymatch changed to use single expression (group) --- src/eval/index.ts | 8 ++++---- src/parser/index.ts | 2 +- src/types.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/eval/index.ts b/src/eval/index.ts index 075ff81..0579579 100644 --- a/src/eval/index.ts +++ b/src/eval/index.ts @@ -82,10 +82,10 @@ const checkExpr = ( ) }, - PropertyMatch: ({ name, exprs }) => + PropertyMatch: ({ name, expr }) => pipe( Object.prototype.hasOwnProperty.call(item ?? {}, name) - ? checkExpr(Expr.Group({ exprs }), item[name], list, index) + ? checkExpr(expr, item[name], list, index) : [], res => (res.length > 0 ? [group(item, index)] : []), // FIXME: doesn't allow nested matching skip(1), @@ -146,8 +146,8 @@ export const find = ([startO, exprs, endO]: ListExpr, list: T[]): any => { Truthy: _ => !!x, Falsey: _ => !x, Group: ({ exprs }) => exprs.every(e => check(e)(x, i, ls)), - PropertyMatch: ({ name, exprs }) => - name in x && exprs.every(e => check(e)(x[name], i, ls)), + PropertyMatch: ({ name, expr }) => + name in x && check(expr)(x[name], i, ls), OneOrMore: ({ expr }) => { // TODO: Nested quantified expression const x = pipe( diff --git a/src/parser/index.ts b/src/parser/index.ts index 3943848..e815334 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -76,7 +76,7 @@ const objectProperty = (input: string) => pair(propertyName, many0(expressionP)), symbol(']'), ), - ([name, exprs]) => Expr.PropertyMatch({ name, exprs }), + ([name, exprs]) => Expr.PropertyMatch({ name, expr: Expr.Group({ exprs }) }), ), ) diff --git a/src/types.ts b/src/types.ts index ac577a1..b09bde5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -25,7 +25,7 @@ export type Expr = Union<{ Truthy: _, Falsey: _, Group: { exprs: Expr[] }, - PropertyMatch: { name: string, exprs: Expr[] }, + PropertyMatch: { name: string, expr: Expr }, Literal: Literal, }> export const Expr = constructors() -- cgit v1.3.1