stackgl / glsl-parser

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

Can't parse user defined structs in fn args #24

Closed AndrewRayCode closed 5 years ago

AndrewRayCode commented 5 years ago

Here's a line from a Three.js shader which fails parsing:

const str = `vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight ) {;}`;
const t = tokenize(str);
const p = parse(t);

Error:

expected user defined type, struct or keyword, gotIncidentLight at line 1

It's failing in struct_or_type on this line

return unexpected('expected user defined type, struct or keyword, got '+token.data)

It might be failing this check

     if(token.data === 'struct') {
        if(!(stmt.flags & DECL_ALLOW_STRUCT)) {
          return unexpected('cannot nest structs')
        }
        state.unshift(struct())
        return Advance
      }

Because the token.data isn't 'struct' even though it's a user defined struct

AndrewRayCode commented 5 years ago

Actually I think this is an issue with glsl-token-descope. It doesn't descope struct names used in fn arguments