Add optional parentheses for expressions
This commit is contained in:
parent
c6ec1ff6ea
commit
0b6c6b7e25
@ -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))))))))))))))
|
||||
|
@ -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,
|
||||
|
@ -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": {
|
||||
|
9255
src/parser.c
9255
src/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user