handle identifiers better
This commit is contained in:
@@ -31,7 +31,8 @@ The aim is to build unit testcases from selected failure classes and slowly get
|
||||
|
||||
## Todo
|
||||
|
||||
* [ ] use [Unicode® Standard Annex #31](https://www.unicode.org/reports/tr31/) (augmented with '-') for identifiers
|
||||
* [x] use [Unicode® Standard Annex #31](https://www.unicode.org/reports/tr31/) (augmented with '-') for identifiers
|
||||
* allow starting '_' also, not to spec but terraform allows it
|
||||
* [ ] add [template expressions](https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#template-expressions)
|
||||
* [x] add quoted templates
|
||||
* [x] add quoted template interpolations
|
||||
|
||||
10
grammar.js
10
grammar.js
@@ -34,14 +34,13 @@ module.exports = grammar({
|
||||
],
|
||||
|
||||
rules: {
|
||||
config_file: $ => optional($.body),
|
||||
// also allow objects to handle .tfvars in json format
|
||||
config_file: $ => optional(choice($.body, $.object)),
|
||||
|
||||
body: $ => repeat1(
|
||||
choice(
|
||||
$.attribute,
|
||||
$.block,
|
||||
// not to spec but handles .tfvars in json format
|
||||
$.object,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -62,10 +61,9 @@ module.exports = grammar({
|
||||
_block_start: $ => '{',
|
||||
_block_end: $ => '}',
|
||||
|
||||
// TODO: not to spec but good enough for now
|
||||
identifier: $ => token(seq(
|
||||
choice(/\p{L}/, '_'),
|
||||
repeat(choice(/\p{L}/, /[0-9]/, /(-|_)/)),
|
||||
choice(/\p{ID_Start}/, '_'),
|
||||
repeat(choice(/\p{ID_Continue}/, '-')),
|
||||
)),
|
||||
|
||||
expression: $ => prec.right(choice(
|
||||
|
||||
@@ -5,8 +5,17 @@
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "body"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "body"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
@@ -25,10 +34,6 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -113,7 +118,7 @@
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\p{L}"
|
||||
"value": "\\p{ID_Start}"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
@@ -128,15 +133,11 @@
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\p{L}"
|
||||
"value": "\\p{ID_Continue}"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[0-9]"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "(-|_)"
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -130,10 +130,6 @@
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -188,6 +184,10 @@
|
||||
{
|
||||
"type": "body",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
26131
src/parser.c
26131
src/parser.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user