Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: arrays support #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/demo.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions demo/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Dot,
CloseBracket,
OpenBracket,
Comma,
} from './tokens.js'

export class CelParser extends CstParser {
Expand Down Expand Up @@ -91,7 +92,7 @@ export class CelParser extends CstParser {
{ ALT: () => this.SUBRULE(this.identifierDotExpression) },
{ ALT: () => this.SUBRULE(this.identifierIndexExpression) },
])
})
})
})

private identifierDotExpression = this.RULE('identifierDotExpression', () => {
Expand All @@ -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) },
Expand Down
2 changes: 2 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -196,6 +197,7 @@ export const allTokens = [
OpenBracket,
CloseBracket,
Dot,
Comma,

Float,
Integer,
Expand Down
Loading