add precedence to conditionals; add test for conditional associativity
This commit is contained in:
@@ -20,7 +20,7 @@ module.exports = grammar({
|
|||||||
[$.object_elem, $.variable_expr],
|
[$.object_elem, $.variable_expr],
|
||||||
[$.attr_splat],
|
[$.attr_splat],
|
||||||
[$.full_splat],
|
[$.full_splat],
|
||||||
[$.conditional],
|
// string literals are just quoted template without template stuff
|
||||||
[$.string_lit, $.quoted_template],
|
[$.string_lit, $.quoted_template],
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -215,13 +215,13 @@ module.exports = grammar({
|
|||||||
|
|
||||||
ellipsis: $ => token('...'),
|
ellipsis: $ => token('...'),
|
||||||
|
|
||||||
conditional: $ => seq(
|
conditional: $ => prec.left(seq(
|
||||||
$.expression,
|
$.expression,
|
||||||
'?',
|
'?',
|
||||||
$.expression,
|
$.expression,
|
||||||
':',
|
':',
|
||||||
$.expression,
|
$.expression,
|
||||||
),
|
)),
|
||||||
|
|
||||||
operation: $ => choice($.unary_operation, $.binary_operation),
|
operation: $ => choice($.unary_operation, $.binary_operation),
|
||||||
|
|
||||||
|
|||||||
@@ -798,29 +798,33 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"conditional": {
|
"conditional": {
|
||||||
"type": "SEQ",
|
"type": "PREC_LEFT",
|
||||||
"members": [
|
"value": 0,
|
||||||
{
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SEQ",
|
||||||
"name": "expression"
|
"members": [
|
||||||
},
|
{
|
||||||
{
|
"type": "SYMBOL",
|
||||||
"type": "STRING",
|
"name": "expression"
|
||||||
"value": "?"
|
},
|
||||||
},
|
{
|
||||||
{
|
"type": "STRING",
|
||||||
"type": "SYMBOL",
|
"value": "?"
|
||||||
"name": "expression"
|
},
|
||||||
},
|
{
|
||||||
{
|
"type": "SYMBOL",
|
||||||
"type": "STRING",
|
"name": "expression"
|
||||||
"value": ":"
|
},
|
||||||
},
|
{
|
||||||
{
|
"type": "STRING",
|
||||||
"type": "SYMBOL",
|
"value": ":"
|
||||||
"name": "expression"
|
},
|
||||||
}
|
{
|
||||||
]
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"operation": {
|
"operation": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
@@ -1228,9 +1232,6 @@
|
|||||||
[
|
[
|
||||||
"full_splat"
|
"full_splat"
|
||||||
],
|
],
|
||||||
[
|
|
||||||
"conditional"
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"string_lit",
|
"string_lit",
|
||||||
"quoted_template"
|
"quoted_template"
|
||||||
|
|||||||
1290
src/parser.c
1290
src/parser.c
File diff suppressed because it is too large
Load Diff
@@ -56,3 +56,37 @@ foo = ( true ? false : true ) ? "yes" : "no"
|
|||||||
(literal_value
|
(literal_value
|
||||||
(string_lit
|
(string_lit
|
||||||
(template_literal)))))))))
|
(template_literal)))))))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
nested conditional expression expression without parentheses
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
foo = true ? false : true ? "yes" : "no"
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(config_file
|
||||||
|
(body
|
||||||
|
(attribute
|
||||||
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(conditional
|
||||||
|
(expression
|
||||||
|
(conditional
|
||||||
|
(expression
|
||||||
|
(literal_value
|
||||||
|
(bool_lit)))
|
||||||
|
(expression
|
||||||
|
(literal_value
|
||||||
|
(bool_lit)))
|
||||||
|
(expression
|
||||||
|
(literal_value
|
||||||
|
(bool_lit)))))
|
||||||
|
(expression
|
||||||
|
(literal_value
|
||||||
|
(string_lit
|
||||||
|
(template_literal))))
|
||||||
|
(expression
|
||||||
|
(literal_value
|
||||||
|
(string_lit
|
||||||
|
(template_literal)))))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user