Skip to content

Commit

Permalink
fix(parser): allow true, false, null as identifiers
Browse files Browse the repository at this point in the history
Fix #1
  • Loading branch information
larsgw committed Aug 31, 2021
1 parent 9cae560 commit 3813139
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 11 additions & 9 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ class KdlParser extends EmbeddedActionsParser {
})

this.RULE('node', () => {
const name = this.OR([
{ ALT: () => this.CONSUME(Identifier).image },
{ ALT: () => this.SUBRULE(this.string) },
{ ALT: () => this.SUBRULE(this.rawString) }
])

const name = this.SUBRULE(this.identifier)
const properties = {}
const values = []

Expand Down Expand Up @@ -201,11 +196,18 @@ class KdlParser extends EmbeddedActionsParser {
return { name, properties, values, children }
})

this.RULE('property', () => {
const key = this.OR([
this.RULE('identifier', () => {
return this.OR([
{ ALT: () => this.CONSUME(Identifier).image },
{ ALT: () => this.SUBRULE(this.string) }
{ ALT: () => this.SUBRULE(this.string) },
{ ALT: () => this.SUBRULE(this.rawString) },
{ ALT: () => this.CONSUME(Boolean).image },
{ ALT: () => this.CONSUME(Null).image }
])
})

this.RULE('property', () => {
const key = this.SUBRULE(this.identifier)
this.CONSUME(Equals)
const value = this.SUBRULE(this.value)
return [key, value]
Expand Down
3 changes: 3 additions & 0 deletions test/kdl/identifier_boolean_null.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
true
false
null
5 changes: 5 additions & 0 deletions test/suite.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@
{ "name": "node", "values": [true] },
{ "name": "node", "values": [false] },
{ "name": "node", "values": [null] }
],
"identifier_boolean_null": [
{ "name": "true" },
{ "name": "false" },
{ "name": "null" }
]
}

0 comments on commit 3813139

Please sign in to comment.