Add optional parentheses for expressions
This commit is contained in:
parent
c6ec1ff6ea
commit
0b6c6b7e25
@ -59,7 +59,7 @@ Complex Assignment
|
|||||||
|
|
||||||
x = 1 + 1
|
x = 1 + 1
|
||||||
|
|
||||||
--
|
---
|
||||||
|
|
||||||
(root
|
(root
|
||||||
(item
|
(item
|
||||||
@ -67,6 +67,7 @@ x = 1 + 1
|
|||||||
(assignment
|
(assignment
|
||||||
(identifier)
|
(identifier)
|
||||||
(assignment_operator)
|
(assignment_operator)
|
||||||
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(math
|
(math
|
||||||
(expression
|
(expression
|
||||||
@ -75,4 +76,41 @@ x = 1 + 1
|
|||||||
(math_operator)
|
(math_operator)
|
||||||
(expression
|
(expression
|
||||||
(value
|
(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(/[#]+.*/),
|
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,
|
||||||
|
@ -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": {
|
||||||
|
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