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>
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;
--- /dev/null
+this file ends with no newline
\ No newline at end of file
--- /dev/null
+this file ends with no newline
--- /dev/null
+#define
\ No newline at end of file
--- /dev/null
+0:1(2): preprocessor error: #define without macro name
+0:1(2): preprocessor error: syntax error, unexpected NEWLINE, expecting FUNC_IDENTIFIER or OBJ_IDENTIFIER
--- /dev/null
+This file ends with no newline within a comment /*
\ No newline at end of file
--- /dev/null
+0:1(52): preprocessor error: Unterminated comment
+This file ends with no newline within a comment