Add binary expression
This commit is contained in:
parent
5489bd5380
commit
25924c3c5c
|
@ -71,6 +71,8 @@ module.exports = grammar({
|
|||
// Composites
|
||||
$.list_expression,
|
||||
$.map_expression,
|
||||
// Operators
|
||||
$.binary_expression,
|
||||
),
|
||||
|
||||
// The Blueprint scanner makes use of Go's lexer, so copy their rule
|
||||
|
@ -185,6 +187,12 @@ module.exports = grammar({
|
|||
"}",
|
||||
),
|
||||
|
||||
binary_expression: ($) => prec.left(seq(
|
||||
field("left", $._expr),
|
||||
field("operator", "+"),
|
||||
field("right", $._expr),
|
||||
)),
|
||||
|
||||
// }}}
|
||||
|
||||
// Properties {{{
|
||||
|
|
37
src/grammar.json
generated
37
src/grammar.json
generated
|
@ -279,6 +279,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "map_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "binary_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -830,6 +834,39 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"binary_expression": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expr"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expr"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"_colon_property": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
|
124
src/node-types.json
generated
124
src/node-types.json
generated
|
@ -31,6 +31,110 @@
|
|||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "interpreted_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "list_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "map_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "raw_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "select_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"left": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "interpreted_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "list_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "map_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "raw_string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "select_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"operator": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"right": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
|
@ -95,6 +199,10 @@
|
|||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
|
@ -163,6 +271,10 @@
|
|||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
|
@ -269,6 +381,10 @@
|
|||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
|
@ -327,6 +443,10 @@
|
|||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
|
@ -528,6 +648,10 @@
|
|||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+=",
|
||||
"named": false
|
||||
|
|
2000
src/parser.c
generated
2000
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -344,3 +344,27 @@ foo = {
|
|||
(identifier)
|
||||
(map_expression
|
||||
(ERROR))))
|
||||
|
||||
================================================================================
|
||||
Binary operators
|
||||
================================================================================
|
||||
|
||||
foo = [
|
||||
-12 + -27 + 42,
|
||||
"a" + "b",
|
||||
]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment
|
||||
(identifier)
|
||||
(list_expression
|
||||
(binary_expression
|
||||
(binary_expression
|
||||
(integer_literal)
|
||||
(integer_literal))
|
||||
(integer_literal))
|
||||
(binary_expression
|
||||
(interpreted_string_literal)
|
||||
(interpreted_string_literal)))))
|
||||
|
|
Loading…
Reference in a new issue