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 = { const PREC = {
assign: 6, multiplicative: 6,
multiplicative: 5, additive: 5,
additive: 4, comparative: 4,
comparative: 3, and: 3,
and: 2, or: 2,
or: 1, assign: 1,
}; };
module.exports = grammar({ module.exports = grammar({

View file

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