Skip to content

Commit 23179c3

Browse files
committed
spec: fix precedence
Swap precedence of ADD and SUB and treat the first subexpression of a SUB differently
1 parent c895bac commit 23179c3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

spec/expr.typ

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
"div": 5, // /
5757
"sum": 6, // Σ
5858
"not": 7, // not
59-
"add": 8, // +
60-
"sub": 9, // -
59+
"sub": 8, // -
60+
"add": 9, // +
6161
"eq": 10, // = and :=
6262
"MAX": 11, // <the void outside every expression>
6363
)
@@ -187,7 +187,10 @@
187187
mwrap($-#rec(PREC.neg, e.at(1))$, pp < PREC.neg)
188188
} else {
189189
// Subtraction
190-
mwrap($#e.slice(1).map(rec.with(PREC.sub)).join($-$)$, pp < PREC.sub)
190+
mwrap(
191+
$#rec(PREC.add, e.at(1))-#e.slice(2).map(rec.with(PREC.sub)).join($-$)$,
192+
pp <= PREC.sub
193+
)
191194
}
192195
},
193196
"cast": (pp, rec, e) => {

0 commit comments

Comments
 (0)