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:
parent
869b0bf79a
commit
21172e21e7
12
grammar.js
12
grammar.js
|
@ -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({
|
||||
|
|
|
@ -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": [
|
||||
|
|
2386
src/parser.c
2386
src/parser.c
File diff suppressed because it is too large
Load diff
16
test/corpus/regressions.txt
Normal file
16
test/corpus/regressions.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
================================================================================
|
||||
Assignment precedence
|
||||
================================================================================
|
||||
|
||||
a := b | c
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(assignment_expression
|
||||
(identifier)
|
||||
(operator)
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(operator)
|
||||
(identifier))))
|
Loading…
Reference in a new issue