add precedence to splat operators; test for associativity
This commit is contained in:
17
grammar.js
17
grammar.js
@@ -16,8 +16,6 @@ module.exports = grammar({
|
||||
name: 'hcl',
|
||||
|
||||
conflicts: $ => [
|
||||
[$.attr_splat],
|
||||
[$.full_splat],
|
||||
// string literals are just quoted template without template stuff
|
||||
[$.string_lit, $.quoted_template],
|
||||
],
|
||||
@@ -145,18 +143,15 @@ module.exports = grammar({
|
||||
|
||||
splat: $ => choice($.attr_splat, $.full_splat),
|
||||
|
||||
attr_splat: $ => seq(
|
||||
'.',
|
||||
'*',
|
||||
attr_splat: $ => prec.right(seq(
|
||||
'.*',
|
||||
repeat($.get_attr),
|
||||
),
|
||||
)),
|
||||
|
||||
full_splat: $ => seq(
|
||||
'[',
|
||||
'*',
|
||||
']',
|
||||
full_splat: $ => prec.right(seq(
|
||||
'[*]',
|
||||
repeat(choice($.get_attr, $.index)),
|
||||
),
|
||||
)),
|
||||
|
||||
for_expr: $ => choice($.for_tuple_expr, $.for_object_expr),
|
||||
|
||||
|
||||
@@ -480,57 +480,53 @@
|
||||
]
|
||||
},
|
||||
"attr_splat": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ".*"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"full_splat": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "index"
|
||||
}
|
||||
]
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "[*]"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "get_attr"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "index"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"for_expr": {
|
||||
"type": "CHOICE",
|
||||
@@ -1210,12 +1206,6 @@
|
||||
}
|
||||
],
|
||||
"conflicts": [
|
||||
[
|
||||
"attr_splat"
|
||||
],
|
||||
[
|
||||
"full_splat"
|
||||
],
|
||||
[
|
||||
"string_lit",
|
||||
"quoted_template"
|
||||
|
||||
@@ -756,6 +756,10 @@
|
||||
"type": ".",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ".*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/",
|
||||
"named": false
|
||||
@@ -800,6 +804,10 @@
|
||||
"type": "[",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[*]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "]",
|
||||
"named": false
|
||||
|
||||
12900
src/parser.c
12900
src/parser.c
File diff suppressed because it is too large
Load Diff
@@ -52,9 +52,9 @@ foo = bar.*.foo
|
||||
(variable_expr
|
||||
(identifier))
|
||||
(splat
|
||||
(attr_splat))
|
||||
(get_attr
|
||||
(identifier))))))
|
||||
(attr_splat
|
||||
(get_attr
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
full splat
|
||||
@@ -64,6 +64,26 @@ foo = bar[*].foo
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
(variable_expr
|
||||
(identifier))
|
||||
(splat
|
||||
(full_splat
|
||||
(get_attr
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
full splat repeated
|
||||
================================================================================
|
||||
|
||||
foo = bar[*][*].a.b.c[d]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(attribute
|
||||
@@ -73,5 +93,15 @@ foo = bar[*].foo
|
||||
(identifier))
|
||||
(splat
|
||||
(full_splat))
|
||||
(get_attr
|
||||
(identifier))))))
|
||||
(splat
|
||||
(full_splat
|
||||
(get_attr
|
||||
(identifier))
|
||||
(get_attr
|
||||
(identifier))
|
||||
(get_attr
|
||||
(identifier))
|
||||
(index
|
||||
(expression
|
||||
(variable_expr
|
||||
(identifier))))))))))
|
||||
|
||||
Reference in New Issue
Block a user