glsl/glcpp: Add testing for EOF sans newline (and fix for <DEFINE>, <COMMENT>)

The glcpp implementation has long had code to support a file that ends without
a final newline. But we didn't have a "make check" test for this.

Additionally, the <EOF> action was restricted only to the <INITIAL> state so
it would fail to get invoked if the EOF was encountered in the <COMMENT> or
the <DEFINE> case. Neither of these was a bug, per se, since EOF in either
of these cases is an error anyway, (either "unterminated comment" or
"missing macro name for #define").

But with the new explicit support for these cases, we not generate clean error
messages in these cases, (rather than "unexpected $end" from before).

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
Carl Worth 2014-06-20 14:28:20 -07:00
parent 21dda50549
commit 5dbdc341e8
7 changed files with 13 additions and 2 deletions

View file

@ -398,8 +398,11 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
return NEWLINE;
}
/* Handle missing newline at EOF. */
<INITIAL><<EOF>> {
<INITIAL,COMMENT,DEFINE><<EOF>> {
if (YY_START == COMMENT)
glcpp_error(yylloc, yyextra, "Unterminated comment");
if (YY_START == DEFINE)
glcpp_error(yylloc, yyextra, "#define without macro name");
BEGIN DONE; /* Don't keep matching this rule forever. */
yyextra->lexing_directive = 0;
return NEWLINE;

View file

@ -0,0 +1 @@
this file ends with no newline

View file

@ -0,0 +1 @@
this file ends with no newline

View file

@ -0,0 +1 @@
#define

View file

@ -0,0 +1,2 @@
0:1(2): preprocessor error: #define without macro name
0:1(2): preprocessor error: syntax error, unexpected NEWLINE, expecting FUNC_IDENTIFIER or OBJ_IDENTIFIER

View file

@ -0,0 +1 @@
This file ends with no newline within a comment /*

View file

@ -0,0 +1,2 @@
0:1(52): preprocessor error: Unterminated comment
This file ends with no newline within a comment