alixinne / glsl-lang

LALR parser for GLSL
https://alixinne.github.io/glsl-lang/glsl_lang/
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

fix(transpiler): add missing brackets for array expressions #25

Closed AlexTMjugador closed 1 year ago

AlexTMjugador commented 1 year ago

As defined in the GLSL grammar, postfix expressions may be suffixed by an integer expression between brackets to index primary expressions such as matrices and arrays. The AST represents such suffix with a Bracket node.

This node was slightly refactored when ported from the glsl crate to contain an expression instead of an array specifier, which better follows the GLSL grammar, but introduced a regression due to not explicitly writing the necessary brackets. For example, this input:

void main() { ProjMat[0][0] = 0.0; }

Would transpile to the following incorrect output:

void main() { ProjMat00 = 0.0; }

To fix this, surround the integer expression between brackets and add the corresponding regression test.