From 4757c74c840460f387a466894baf1c45624467c7 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 26 Jun 2014 14:04:01 -0700 Subject: [PATCH] glsl/glcpp: Treat carriage return as equivalent to line feed. Previously, the '\r' character was not explicitly matched by any lexer rule. This means that 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 the bogus printing to stdout. The resulting behavior is 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. Reviewed-by: Jordan Justen --- src/glsl/glcpp/glcpp-lex.l | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index d0894c1515b..cb5ee9984f8 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -165,7 +165,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]* @@ -246,15 +245,15 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } /* Single-line comments */ -"//"[^\n]* { +"//"[^\r\n]* { } /* Multi-line comments */ -"/*" { yy_push_state(COMMENT, yyscanner); } -[^*\n]* -[^*\n]*\n { yylineno++; yycolumn = 0; parser->commented_newlines++; } -"*"+[^*/\n]* -"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; parser->commented_newlines++; } +"/*" { yy_push_state(COMMENT, yyscanner); } +[^*\r\n]* +[^*\r\n]*[\r\n] { yylineno++; yycolumn = 0; parser->commented_newlines++; } +"*"+[^*/\r\n]* +"*"+[^*/\r\n]*[\r\n] { yylineno++; yycolumn = 0; parser->commented_newlines++; } "*"+"/" { yy_pop_state(yyscanner); /* In the start condition, we don't want any SPACE token. */ @@ -285,7 +284,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. */ -(extension|pragma)[^\n]* { +(extension|pragma)[^\r\n]* { BEGIN INITIAL; yylineno++; yycolumn = 0; @@ -513,7 +512,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.30.2