Add assignment expressions

This commit is contained in:
Bruno BELANYI 2022-06-01 20:11:52 +02:00
parent 6a3e4663ed
commit 93cd163707
5 changed files with 1316 additions and 1023 deletions

View file

@ -7,6 +7,7 @@ function sepBy(sep, rule) {
}
const PREC = {
assign: 6,
multiplicative: 5,
additive: 4,
comparative: 3,
@ -44,6 +45,8 @@ module.exports = grammar({
$.unary_expression,
$.binary_expression,
$.sequence_expression,
$.assignment_expression,
),
nil_literal: (_) => "nil",
@ -155,6 +158,15 @@ module.exports = grammar({
),
"}",
),
assignment_expression: ($) => prec.right(
PREC.assign,
seq(
field("left", $._lvalue),
":=",
field("right", $._expr),
),
),
}
});

View file

@ -53,6 +53,10 @@
{
"type": "SYMBOL",
"name": "sequence_expression"
},
{
"type": "SYMBOL",
"name": "assignment_expression"
}
]
},
@ -752,6 +756,35 @@
"value": "}"
}
]
},
"assignment_expression": {
"type": "PREC_RIGHT",
"value": 6,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "left",
"content": {
"type": "SYMBOL",
"name": "_lvalue"
}
},
{
"type": "STRING",
"value": ":="
},
{
"type": "FIELD",
"name": "right",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
}
}
},
"extras": [

View file

@ -15,6 +15,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -69,6 +73,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -157,6 +165,92 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "record_value",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
}
]
}
}
},
{
"type": "assignment_expression",
"named": true,
"fields": {
"left": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_value",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "record_value",
"named": true
}
]
},
"right": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -217,6 +311,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -281,6 +379,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -345,6 +447,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -425,6 +531,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -529,6 +639,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -588,6 +702,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -662,6 +780,10 @@
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
@ -736,6 +858,10 @@
"type": ".",
"named": false
},
{
"type": ":=",
"named": false
},
{
"type": ";",
"named": false

File diff suppressed because it is too large Load diff

View file

@ -138,3 +138,22 @@ f(12,)
function: (identifier)
arguments: (integer_literal)
(ERROR)))
================================================================================
Assignments
================================================================================
a := array[12] := record.field
--------------------------------------------------------------------------------
(source_file
(assignment_expression
left: (identifier)
right: (assignment_expression
left: (array_value
array: (identifier)
index: (integer_literal))
right: (record_value
record: (identifier)
field: (identifier)))))