stackgl / glsl-parser

transform streamed glsl tokens into an ast
MIT License
98 stars 15 forks source link

error parsing comma operator float c = (0.0, 1.0); #22

Open AndrewRayCode opened 5 years ago

AndrewRayCode commented 5 years ago

I didn't realize this was valid glsl code, but apparently it is:

float c = (0.0, 1.0);

and it evaluates to the last statement.

So this fails:

console.log( deparse( parse( tokenize(` void main(void) { float c = (1.0, 2.0); }`) ) ) );
expected `)`, got `,` at line 4
      at Array.unexpected (node_modules/glsl-parser/lib/index.js:737:11)
      at advance (node_modules/glsl-parser/lib/expr.js:219:18)
      at Object.nud (node_modules/glsl-parser/lib/expr.js:87:3)
      at expression (node_modules/glsl-parser/lib/expr.js:156:12)
      at Object.<anonymous>.module.exports (node_modules/glsl-parser/lib/expr.js:116:12)
      at parseexpr (node_modules/glsl-parser/lib/index.js:681:9)
      at parse_expr (node_modules/glsl-parser/lib/index.js:650:14)
      at write (node_modules/glsl-parser/lib/index.js:220:11)
      at reader (node_modules/glsl-parser/lib/index.js:181:5)
      at parseArray (node_modules/glsl-parser/direct.js:9:5)

Same with things like:

vec2 q = vec2((1.0, 2.0));