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,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))))))))))))))
|
||||||
|
@ -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