From a196ab1f8aacf657e591a0a15c80c3f37b9496b0 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 1 Jul 2014 17:40:28 -0700 Subject: glsl/glcpp: Add explicit error for "#define without macro name" Previously, glcpp would emit an error like this if happened to occur immediately after the "#define", but in general would just get confused, (leading to un-helpful error messages). To fix things to generate a clean error message, we do a few things: 1. Don't require horizontal whitespace immediately after #define 2. Add a production for the error case, (DEFINE_TOKEN followed immediately by a NEWLINE token). 3. Make the lexer reset to the state after every NEWLINE. This 3rd point prevents the lexer from getting so confused and generating further spurious errors in the file because it was stuck in the start condition. We also drop the similar error message from the rule since the newly-added rule will have already printed the error message. Reviewed-by: Ian Romanick --- src/glsl/glcpp/glcpp-parse.y | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/glsl/glcpp/glcpp-parse.y') diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index e2e8aca58a8..25da2a515b2 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -424,6 +424,9 @@ control_line_error: HASH_TOKEN ERROR_TOKEN NEWLINE { glcpp_error(& @1, parser, "#%s", $2); } +| HASH_TOKEN DEFINE_TOKEN NEWLINE { + glcpp_error (& @1, parser, "#define without macro name"); + } | HASH_TOKEN GARBAGE pp_tokens NEWLINE { glcpp_error (& @1, parser, "Illegal non-directive after #"); } -- cgit v1.2.3