Add optional parentheses for expressions

This commit is contained in:
Jeff 2023-10-13 11:20:09 -04:00
parent c6ec1ff6ea
commit 0b6c6b7e25
4 changed files with 4957 additions and 4389 deletions

View File

@ -59,7 +59,7 @@ Complex Assignment
x = 1 + 1 x = 1 + 1
-- ---
(root (root
(item (item
@ -67,12 +67,50 @@ x = 1 + 1
(assignment (assignment
(identifier) (identifier)
(assignment_operator) (assignment_operator)
(expression (statement
(math (expression
(expression (math
(value (expression
(integer))) (value
(math_operator) (integer)))
(expression (math_operator)
(value (expression
(integer))))))))) (value
(integer))))))))))
==================
Expression Precedence
==================
x = (3 == (1 + (2 + 2)))
---
(root
(item
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(logic
(expression
(value
(integer)))
(logic_operator)
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer))))))))))))))

View File

@ -20,7 +20,12 @@ module.exports = grammar({
comment: $ => seq(/[#]+.*/), comment: $ => seq(/[#]+.*/),
expression: $ => prec.right(choice( expression: $ => choice(
$._expression_kind,
seq('(', $._expression_kind, ')'),
),
_expression_kind: $ => prec.right(choice(
$.value, $.value,
$.identifier, $.identifier,
$.function_call, $.function_call,

View File

@ -63,6 +63,32 @@
] ]
}, },
"expression": { "expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression_kind"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression_kind"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"_expression_kind": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {

File diff suppressed because it is too large Load Diff