Skip to content

Commit f2f230a

Browse files
authored
TSL Transpiler: Add grouped precedence levels (mrdoob#31581)
1 parent 7d8b148 commit f2f230a

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

examples/jsm/transpiler/GLSLDecoder.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ const arithmeticOperators = [
1111
];
1212

1313
const precedenceOperators = [
14-
'/', '*', '%',
15-
'-', '+',
16-
'<<', '>>',
17-
'<', '>', '<=', '>=',
18-
'==', '!=',
19-
'&',
20-
'^',
21-
'|',
22-
'&&',
23-
'^^',
24-
'||',
25-
'?',
26-
'=',
27-
'+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '<<=', '>>=',
28-
','
29-
].reverse();
14+
[ ',' ],
15+
[ '=', '+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '<<=', '>>=' ],
16+
[ '?' ],
17+
[ '||' ],
18+
[ '^^' ],
19+
[ '&&' ],
20+
[ '|' ],
21+
[ '^' ],
22+
[ '&' ],
23+
[ '==', '!=' ],
24+
[ '<', '>', '<=', '>=' ],
25+
[ '<<', '>>' ],
26+
[ '+', '-' ],
27+
[ '*', '/', '%' ]
28+
];
3029

3130
const associativityRightToLeft = [
3231
'=',
@@ -334,7 +333,7 @@ class GLSLDecoder {
334333

335334
let groupIndex = 0;
336335

337-
for ( const operator of precedenceOperators ) {
336+
for ( const operators of precedenceOperators ) {
338337

339338
const parseToken = ( i, inverse = false ) => {
340339

@@ -351,7 +350,9 @@ class GLSLDecoder {
351350

352351
}
353352

354-
if ( groupIndex === 0 && token.str === operator ) {
353+
if ( groupIndex === 0 && operators.includes( token.str ) ) {
354+
355+
const operator = token.str;
355356

356357
if ( operator === '?' ) {
357358

@@ -396,7 +397,9 @@ class GLSLDecoder {
396397

397398
};
398399

399-
if ( associativityRightToLeft.includes( operator ) ) {
400+
const isRightAssociative = operators.some( op => associativityRightToLeft.includes( op ) );
401+
402+
if ( isRightAssociative ) {
400403

401404
for ( let i = 0; i < tokens.length; i ++ ) {
402405

0 commit comments

Comments
 (0)