language-glsl
language-glsl copied to clipboard
GLSL preprocessor: support for #define, #ifdef etc.
The preprocessor is part of the GLSL spec, section 3.4 of https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
Is it even possible to handle #define and #ifdef properly in language-glsl?
Being a preprocessor, I thought it could (or even should) be implemented separately from the main parser (provided by language-glsl). But it seems it would be better to include it in language-glsl: for instance error messages have to take the #line
directive into account.
I don't think it should be a problem for language-glsl to parse the preprocessor directives and expose them as top-level data types in the resulting parse tree. Or maybe even interpret them and push the result (e.g. optimization hint) into the existing (but then enriched) data types.
Conceptually mixing the line-oriented nature of the preprocessor with the rest of the language is a bit weird but I don't think it would prevent it to be part of the parser.
@noteed @kfish Did anybody get a chance to look into this more? I was blocked by this issue recently, but I am not comfortable enough with Haskell to fix it
@nphollon I don't think I will have time to work on this but would happily accept a patch.