Skip to content

Commit

Permalink
first blood
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromeGG committed Feb 5, 2024
1 parent f2fd48f commit a9eea19
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
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

0 comments on commit a9eea19

Please sign in to comment.