Add binary expression

This commit is contained in:
Bruno BELANYI 2024-04-08 02:12:22 +01:00
parent 5489bd5380
commit 25924c3c5c
5 changed files with 1259 additions and 934 deletions

View file

@ -71,6 +71,8 @@ module.exports = grammar({
// Composites // Composites
$.list_expression, $.list_expression,
$.map_expression, $.map_expression,
// Operators
$.binary_expression,
), ),
// The Blueprint scanner makes use of Go's lexer, so copy their rule // 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 {{{ // Properties {{{

37
src/grammar.json generated
View file

@ -279,6 +279,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "map_expression" "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": { "_colon_property": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

124
src/node-types.json generated
View file

@ -31,6 +31,110 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "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", "type": "boolean_literal",
"named": true "named": true
@ -95,6 +199,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -163,6 +271,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -269,6 +381,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -327,6 +443,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binary_expression",
"named": true
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true "named": true
@ -528,6 +648,10 @@
"type": ")", "type": ")",
"named": false "named": false
}, },
{
"type": "+",
"named": false
},
{ {
"type": "+=", "type": "+=",
"named": false "named": false

2000
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -344,3 +344,27 @@ foo = {
(identifier) (identifier)
(map_expression (map_expression
(ERROR)))) (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)))))