Mesa (master): glcpp: Don' t include the newline when discarding single-line comments

Carl Worth cworth at kemper.freedesktop.org
Wed Aug 18 05:25:17 UTC 2010


Module: Mesa
Branch: master
Commit: eb26f0d5b68f0218d4c79c1825d0d9e6a905e199
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb26f0d5b68f0218d4c79c1825d0d9e6a905e199

Author: Carl Worth <cworth at cworth.org>
Date:   Tue Aug 17 22:17:09 2010 -0700

glcpp: Don't include the newline when discarding single-line comments

Matching the newline here meant having to do some redundant work here,
(incrementing line number, resetting column number, and returning a
NEWLINE token), that could otherwise simply be left to the existing rule
which matches a newline.

Worse, when the comment rule matches the newline as well, the parser
can lookahead and see a token for something that should actually be skipped.

For example, in a case like this:

	#if 0 // comment here
	fail
	#else
	win
	#endif

Both fail and win appear in the output, (not that the condition is being
evaluated incorrectly---merely that one token after the comment's newline
was being lexed/parse regardless of the condition).

This commit fixes the above test case, (which is also remarkably similar
to 087-if-comments which now passes).

---

 src/glsl/glcpp/glcpp-lex.l |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 9187926..a14e580 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -70,10 +70,7 @@ HEXADECIMAL_INTEGER	0[xX][0-9a-fA-F]+[uU]?
 %%
 
 	/* Single-line comments */
-"//"[^\n]*\n {
-	yylineno++;
-	yycolumn = 0;
-	return NEWLINE;
+"//"[^\n]* {
 }
 
 	/* Multi-line comments */




More information about the mesa-commit mailing list