Previously, the '\r' character was not explicitly matched by any rule. With the recent addition of the catch-all rule for unrecognized characters, this means glcpp would generate an internal-compiler error for any occurrence of '\r' in a shader source string.
Prior to the internal error, glcpp would have been using the default flex rule to match '\r' characters, (where they would have been printed to stdout rather than actually correctly handled). With this commit, we treat '\r' as equivalent to '\n'. This is clearly an improvement over the internal error. The resulting behavior is be compliant with the GLSL specification for any source file that uses exclusively '\r' or '\n' to separate lines. For shaders that use a multiple-character line separator, (such as "\r\n"), glcpp won't be precisely compliant with the specification, (treating these as two newline characters rather than one), but this should not introduce any semantic changes to the shader programs. --- src/glsl/glcpp/glcpp-lex.l | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index 721d8ae..539b46c 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -169,7 +169,6 @@ glcpp_lex_update_state_per_token (glcpp_parser_t *parser, int token) SPACE [[:space:]] NONSPACE [^[:space:]] -NEWLINE [\n] HSPACE [ \t] HASH # IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* @@ -250,15 +249,15 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } /* Single-line comments */ -"//"[^\n]* { +"//"[^\r\n]* { } /* Multi-line comments */ -<DEFINE,HASH,INITIAL>"/*" { yy_push_state(COMMENT, yyscanner); } -<COMMENT>[^*\n]* -<COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; parser->commented_newlines++; } -<COMMENT>"*"+[^*/\n]* -<COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; parser->commented_newlines++; } +<DEFINE,HASH,INITIAL>"/*" { yy_push_state(COMMENT, yyscanner); } +<COMMENT>[^*\r\n]* +<COMMENT>[^*\r\n]*[\r\n] { yylineno++; yycolumn = 0; parser->commented_newlines++; } +<COMMENT>"*"+[^*/\r\n]* +<COMMENT>"*"+[^*/\r\n]*[\r\n] { yylineno++; yycolumn = 0; parser->commented_newlines++; } <COMMENT>"*"+"/" { yy_pop_state(yyscanner); /* In the <HASH> start condition, we don't want any SPACE token. */ @@ -289,7 +288,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* glcpp doesn't handle #extension, #version, or #pragma directives. * Simply pass them through to the main compiler's lexer/parser. */ -<HASH>(extension|pragma)[^\n]* { +<HASH>(extension|pragma)[^\r\n]* { BEGIN INITIAL; yylineno++; yycolumn = 0; @@ -380,7 +379,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? RETURN_TOKEN (UNDEF); } -<HASH>\n { +<HASH>[\r\n] { BEGIN INITIAL; RETURN_TOKEN (HASH_TOKEN); } @@ -517,7 +516,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* We preserve all newlines, even between #if 0..#endif, so no skipping.. */ -\n { +[\r\n] { if (parser->commented_newlines) { BEGIN NEWLINE_CATCHUP; } -- 2.0.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev