%%
-{HASH}define{HSPACE}+/{IDENTIFIER}"(" {
+{HASH}if/.*\n {
+ yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
- return HASH_DEFINE_FUNC;
+ return HASH_IF;
}
-{HASH}define {
+{HASH}elif/.*\n {
+ yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
- return HASH_DEFINE_OBJ;
+ return HASH_ELIF;
}
-{HASH}undef {
+{HASH}else/.*\n {
yyextra->space_tokens = 0;
- return HASH_UNDEF;
+ return HASH_ELSE;
}
-{HASH}if {
+{HASH}endif/.*\n {
yyextra->space_tokens = 0;
- return HASH_IF;
+ return HASH_ENDIF;
}
-{HASH}elif {
+ /* When skipping (due to an #if 0 or similar) consume anything
+ * up to a newline. We do this less priroty than any
+ * #if-related directive (#if, #elif, #else, #endif), but with
+ * more priority than any other directive or token to avoid
+ * any side-effects from skipped content.
+ *
+ * We use the lexing_if flag to avoid skipping any part of an
+ * if conditional expression. */
+[^\n]+/\n {
+ if (yyextra->lexing_if ||
+ yyextra->skip_stack == NULL ||
+ yyextra->skip_stack->type == SKIP_NO_SKIP)
+ {
+ REJECT;
+ }
+}
+
+{HASH}define{HSPACE}+/{IDENTIFIER}"(" {
yyextra->space_tokens = 0;
- return HASH_ELIF;
+ return HASH_DEFINE_FUNC;
}
-{HASH}else {
+{HASH}define {
yyextra->space_tokens = 0;
- return HASH_ELSE;
+ return HASH_DEFINE_OBJ;
}
-{HASH}endif {
+{HASH}undef {
yyextra->space_tokens = 0;
- return HASH_ENDIF;
+ return HASH_UNDEF;
}
{HASH} {
}
\n {
+ yyextra->lexing_if = 0;
return NEWLINE;
}
line:
control_line {
- if (parser->skip_stack == NULL ||
- parser->skip_stack->type == SKIP_NO_SKIP)
- {
- printf ("\n");
- }
+ printf ("\n");
}
| text_line {
- if (parser->skip_stack == NULL ||
- parser->skip_stack->type == SKIP_NO_SKIP)
- {
- _glcpp_parser_print_expanded_token_list (parser, $1);
- printf ("\n");
- }
+ _glcpp_parser_print_expanded_token_list (parser, $1);
+ printf ("\n");
talloc_free ($1);
}
| expanded_line
parser->defines = hash_table_ctor (32, hash_table_string_hash,
hash_table_string_compare);
parser->active = _string_list_create (parser);
+ parser->lexing_if = 0;
parser->space_tokens = 1;
parser->newline_as_space = 0;
parser->in_control_line = 0;