add precedence to splat operators; test for associativity

This commit is contained in:
mhoffm
2021-06-18 07:29:00 +02:00
parent b793cd7c37
commit 9b79cbda48
5 changed files with 6585 additions and 6476 deletions

View File

@@ -16,8 +16,6 @@ module.exports = grammar({
name: 'hcl', name: 'hcl',
conflicts: $ => [ conflicts: $ => [
[$.attr_splat],
[$.full_splat],
// string literals are just quoted template without template stuff // string literals are just quoted template without template stuff
[$.string_lit, $.quoted_template], [$.string_lit, $.quoted_template],
], ],
@@ -145,18 +143,15 @@ module.exports = grammar({
splat: $ => choice($.attr_splat, $.full_splat), splat: $ => choice($.attr_splat, $.full_splat),
attr_splat: $ => seq( attr_splat: $ => prec.right(seq(
'.', '.*',
'*',
repeat($.get_attr), repeat($.get_attr),
), )),
full_splat: $ => seq( full_splat: $ => prec.right(seq(
'[', '[*]',
'*',
']',
repeat(choice($.get_attr, $.index)), repeat(choice($.get_attr, $.index)),
), )),
for_expr: $ => choice($.for_tuple_expr, $.for_object_expr), for_expr: $ => choice($.for_tuple_expr, $.for_object_expr),

View File

@@ -480,15 +480,14 @@
] ]
}, },
"attr_splat": { "attr_splat": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "." "value": ".*"
},
{
"type": "STRING",
"value": "*"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@@ -498,21 +497,17 @@
} }
} }
] ]
}
}, },
"full_splat": { "full_splat": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "[" "value": "[*]"
},
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "]"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@@ -531,6 +526,7 @@
} }
} }
] ]
}
}, },
"for_expr": { "for_expr": {
"type": "CHOICE", "type": "CHOICE",
@@ -1210,12 +1206,6 @@
} }
], ],
"conflicts": [ "conflicts": [
[
"attr_splat"
],
[
"full_splat"
],
[ [
"string_lit", "string_lit",
"quoted_template" "quoted_template"

View File

@@ -756,6 +756,10 @@
"type": ".", "type": ".",
"named": false "named": false
}, },
{
"type": ".*",
"named": false
},
{ {
"type": "/", "type": "/",
"named": false "named": false
@@ -800,6 +804,10 @@
"type": "[", "type": "[",
"named": false "named": false
}, },
{
"type": "[*]",
"named": false
},
{ {
"type": "]", "type": "]",
"named": false "named": false

12900
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@@ -52,9 +52,9 @@ foo = bar.*.foo
(variable_expr (variable_expr
(identifier)) (identifier))
(splat (splat
(attr_splat)) (attr_splat
(get_attr (get_attr
(identifier)))))) (identifier))))))))
================================================================================ ================================================================================
full splat full splat
@@ -72,6 +72,36 @@ foo = bar[*].foo
(variable_expr (variable_expr
(identifier)) (identifier))
(splat (splat
(full_splat)) (full_splat
(get_attr (get_attr
(identifier)))))) (identifier))))))))
================================================================================
full splat repeated
================================================================================
foo = bar[*][*].a.b.c[d]
--------------------------------------------------------------------------------
(config_file
(body
(attribute
(identifier)
(expression
(variable_expr
(identifier))
(splat
(full_splat))
(splat
(full_splat
(get_attr
(identifier))
(get_attr
(identifier))
(get_attr
(identifier))
(index
(expression
(variable_expr
(identifier))))))))))