stackgl / glsl-parser

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

const float d[3] = float[](5.0, 7.2, 1.1); #13

Open dy opened 8 years ago

dy commented 8 years ago
var parse = require('glsl-parser/direct');
var tokenize = require('glsl-tokenizer/string');

parse(tokenize(
    'const float d[3] = float[](5.0, 7.2, 1.1);'
));
//Error: unexpected at line 1

Though it is valid GLSL syntax.

AndrewRayCode commented 5 years ago

Hmm, I'm not sure what version of GLSL this parser is supposed to support, but if it's WebGL GLSL, which is glsl 1.0, then this isn't valid syntax. @chrisdickinson do you have a thought on which version of GLSL this parser is built for?

Under the hood, this is happening because:

This parser doesn't seem to follow the GLSL language grammar spec, so it's hard to compare the top down operator precedence setup with what the spec expects. For example, is it correct that [ is an infix node in this case (infixed between float and expression)? I'm not sure

I tried making the infix call into a unary type instead, but the printer for the compiler doesn't print the closing [ correctly.