stackgl / glsl-parser

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

Can't parse this GLSL code which compiles #4

Closed gre closed 10 years ago

gre commented 10 years ago

This GLSL line of code compiles, but is not parsed by glsl-parser

...
  vec4 c = any(lessThan(p, vec2(0.0)))||any(lessThan(vec2(1.0), p)) ? vec4(0.0): vec4(1.0);
...
Error: unexpected at line 26
    at Array.unexpected (/Users/gre/Desktop/node_modules/glsl-parser/lib/index.js:637:26)
    at /Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:264:36
    at Object.original_symbol.nud (/Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:7:95)
    at expression (/Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:156:12)
    at Object.sym.led (/Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:168:28)
    at expression (/Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:160:14)
    at module.exports (/Users/gre/Desktop/node_modules/glsl-parser/lib/expr.js:116:12)
    at parseexpr (/Users/gre/Desktop/node_modules/glsl-parser/lib/index.js:587:14)
    at parse_expr (/Users/gre/Desktop/node_modules/glsl-parser/lib/index.js:565:14)
    at Stream.write (/Users/gre/Desktop/node_modules/glsl-parser/lib/index.js:181:18)

I first experimented the bug on glsl.io, then I was able to reproduce it from NodeJS with:

var tokenizer = require('glsl-tokenizer')(), fs=require("fs"), parser=require("glsl-parser")
fs.createReadStream('test.glsl').pipe(tokenizer).pipe(parser()).on('data', function (x) { console.log(x); })

Also it works if you put a space before the ||

... any(lessThan(p, vec2(0.0))) ||any(lessThan(vec2(1.0), p)) ...
chrisdickinson commented 10 years ago

This was actually a problem with glsl-tokenizer, and should be fixed as of 0.0.9. Thanks for bringing it to my attention!