diff --git a/demo/demo.ts b/demo/demo.ts index e45c1a4..2676090 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -1,4 +1,4 @@ -// ? run "pnpm tsx demo.ts" in the terminal to see the output +// ? run "pnpm tsx demo" in the terminal to see the output import { evaluate, parse } from 'cel-js' diff --git a/demo/package.json b/demo/package.json index 8b06ef8..11d264d 100644 --- a/demo/package.json +++ b/demo/package.json @@ -4,7 +4,7 @@ "description": "A simple usage of the CEL library", "type": "module", "dependencies": { - "cel-js": "0.1.2" + "cel-js": "0.1.3" }, "devDependencies": { "tsx": "4.7.0" diff --git a/demo/pnpm-lock.yaml b/demo/pnpm-lock.yaml index 2cfd901..f574cef 100644 --- a/demo/pnpm-lock.yaml +++ b/demo/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: cel-js: - specifier: 0.1.2 - version: 0.1.2 + specifier: 0.1.3 + version: 0.1.3 devDependencies: tsx: @@ -250,8 +250,8 @@ packages: dev: true optional: true - /cel-js@0.1.2: - resolution: {integrity: sha512-SX0hlAjzZf2D6JGFoMcQX86VIy5gxEZ0/mzQxK0hRn/bSoM/qL7WZ6QcdybNYXgl0iSsDE5M/EIACJd+rgcshw==} + /cel-js@0.1.3: + resolution: {integrity: sha512-vHe2q1mbkLplKpOybOMo4Cy8OYTMeN8z3yrQXnPijRx6/Lpwt8TP0LKuPfaxOKbY+sclJUNuTEO5/Lf6BjFbpw==} engines: {node: '>=18.0.0'} dependencies: chevrotain: 11.0.3 diff --git a/src/parser.ts b/src/parser.ts index 15e8e52..cedde8a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -19,6 +19,7 @@ import { Dot, CloseBracket, OpenBracket, + Comma, } from './tokens.js' export class CelParser extends CstParser { @@ -91,7 +92,7 @@ export class CelParser extends CstParser { { ALT: () => this.SUBRULE(this.identifierDotExpression) }, { ALT: () => this.SUBRULE(this.identifierIndexExpression) }, ]) - }) + }) }) private identifierDotExpression = this.RULE('identifierDotExpression', () => { @@ -108,6 +109,18 @@ export class CelParser extends CstParser { } ) + private arrayExpression = this.RULE('arrayExpression', () => { + this.CONSUME(OpenBracket) + this.OPTION(() => { + this.SUBRULE(this.expr) + this.MANY(() => { + this.CONSUME(Comma) + this.SUBRULE2(this.expr) + }) + }) + this.CONSUME(CloseBracket) + }) + private atomicExpression = this.RULE('atomicExpression', () => { this.OR([ { ALT: () => this.SUBRULE(this.parenthesisExpression) }, diff --git a/src/tokens.ts b/src/tokens.ts index 72942f4..49eb4c2 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -21,6 +21,7 @@ export const OpenBracket = createToken({ name: 'OpenBracket', pattern: /\[/ }) export const CloseBracket = createToken({ name: 'CloseBracket', pattern: /\]/ }) export const Dot = createToken({ name: 'Dot', pattern: /\./ }) +export const Comma = createToken({ name: 'Comma', pattern: /,/ }) export const Float = createToken({ name: 'Float', @@ -196,6 +197,7 @@ export const allTokens = [ OpenBracket, CloseBracket, Dot, + Comma, Float, Integer,