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
--
---
(root
(item
@ -67,6 +67,7 @@ x = 1 + 1
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(math
(expression
@ -75,4 +76,41 @@ x = 1 + 1
(math_operator)
(expression
(value
(integer)))))))))
(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(/[#]+.*/),
expression: $ => prec.right(choice(
expression: $ => choice(
$._expression_kind,
seq('(', $._expression_kind, ')'),
),
_expression_kind: $ => prec.right(choice(
$.value,
$.identifier,
$.function_call,

View File

@ -63,6 +63,32 @@
]
},
"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",
"value": 0,
"content": {

File diff suppressed because it is too large Load Diff