Fix assignment priority

The assignment operator is lower priority than any other binary
operator.

Otherwise the following:

```tiger
a := b | c
```

Would be parsed as:

```tiger
(a := b) | c
```

Instead of the expected:

```tiger
a := (b | c)
```
This commit is contained in:
Bruno BELANYI 2022-06-04 20:41:23 +02:00
parent 869b0bf79a
commit 21172e21e7
4 changed files with 1223 additions and 1203 deletions

View file

@ -7,12 +7,12 @@ function sepBy(sep, rule) {
}
const PREC = {
assign: 6,
multiplicative: 5,
additive: 4,
comparative: 3,
and: 2,
or: 1,
multiplicative: 6,
additive: 5,
comparative: 4,
and: 3,
or: 2,
assign: 1,
};
module.exports = grammar({

View file

@ -412,7 +412,7 @@
"members": [
{
"type": "PREC_LEFT",
"value": 5,
"value": 6,
"content": {
"type": "SEQ",
"members": [
@ -459,7 +459,7 @@
},
{
"type": "PREC_LEFT",
"value": 4,
"value": 5,
"content": {
"type": "SEQ",
"members": [
@ -506,7 +506,7 @@
},
{
"type": "PREC_LEFT",
"value": 3,
"value": 4,
"content": {
"type": "SEQ",
"members": [
@ -569,7 +569,7 @@
},
{
"type": "PREC_LEFT",
"value": 2,
"value": 3,
"content": {
"type": "SEQ",
"members": [
@ -607,7 +607,7 @@
},
{
"type": "PREC_LEFT",
"value": 1,
"value": 2,
"content": {
"type": "SEQ",
"members": [
@ -830,7 +830,7 @@
},
"assignment_expression": {
"type": "PREC_RIGHT",
"value": 6,
"value": 1,
"content": {
"type": "SEQ",
"members": [

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
================================================================================
Assignment precedence
================================================================================
a := b | c
--------------------------------------------------------------------------------
(source_file
(assignment_expression
(identifier)
(operator)
(binary_expression
(identifier)
(operator)
(identifier))))