noteed / language-glsl

Haskell package for representation, parsing, and pretty-printing of GLSL
Other
31 stars 9 forks source link

Parser for array size expressions in block declarations seems to reject valid syntax #2

Closed leino closed 10 years ago

leino commented 10 years ago

The Language.GLSL.Parser.parse function rejects the following code:

''' layout (std140) uniform PatternBlock { float pattern[100]; }; void main () { gl_FragColor = vec4 (1.0, 1.0, 0.0, 1.0); } '''

with the error:

''' Left "GLSL" (line 2, column 17): unexpected "1" expecting "/", space or "]" '''

From reading a bit in the specification (https://www.opengl.org/registry/doc/GLSLangSpec.1.50.11.pdf), I'm fairly sure that it should accept this syntax.

More precisely, it seems that the 'conditionalExpression' parser does not accept '100', which I believe it should (in spite of the name!), see *.

Looking at the implementation of 'conditionalExpression', it seems quite clear to me that Parsec's 'buildExpressionParser' function may not be the right fit, but I have not looked into why it fails yet.

I intend to investigate this a bit more in-depth shortly. I'll send you a pull request if I figure out a valid fix. Just thought I'd let you know in case I never get around to it.

*Note that it is not immediately obvious from the grammar in the spec that '100' should be accepted. Here are the rewrites to get to '100' starting from conditional_expression: conditional_expression, logical_or_expression, logical_xor_expression, logical_and_expression, inclusive_or_expression, exclusive_or_expression, and_expression, equality_expression, relational_expression, shift_expression, additive_expression, multiplicative_expression, unary_expression, postfix_expression, primary_expression, which includes INTCONSTANT.