%option reentrant noyywrap
%option extra-type="glcpp_parser_t *"
+%x ST_DEFINE
+%x ST_DEFVAL
+
SPACE [[:space:]]
NONSPACE [^[:space:]]
NEWLINE [\n]
* "#define foo()" from "#define foo ()".
*/
{HASH}define{HSPACE}* {
+ BEGIN ST_DEFINE;
return DEFINE;
}
+<ST_DEFINE>{IDENTIFIER} {
+ BEGIN ST_DEFVAL;
+ yylval.str = xtalloc_strdup (yyextra, yytext);
+ return IDENTIFIER;
+}
+
+<ST_DEFVAL>\n {
+ BEGIN INITIAL;
+ return NEWLINE;
+}
+
+<ST_DEFVAL>{HSPACE}+ {
+ BEGIN INITIAL;
+ return SPACE;
+}
+
+<ST_DEFVAL>"(" {
+ BEGIN INITIAL;
+ return '(';
+}
+
{IDENTIFIER} {
yylval.str = xtalloc_strdup (yyextra, yytext);
switch (glcpp_parser_macro_type (yyextra, yylval.str))
return NEWLINE;
}
-{HSPACE}+ {
- return SPACE;
-}
+{SPACE}+
%%
| '(' { printf ("("); }
| ')' { printf (")"); }
| ',' { printf (","); }
-| SPACE { printf (" "); }
;
macro:
$$ = _argument_list_create (parser);
_argument_list_append ($$, $1);
}
-| argument_list ',' SPACE argument {
- _argument_list_append ($1, $4);
- $$ = $1;
- }
| argument_list ',' argument {
_argument_list_append ($1, $3);
$$ = $1;
talloc_free ($2);
$$ = $1;
}
-| argument SPACE word {
- _string_list_append_item ($1, " ");
- _string_list_append_item ($1, $3);
- talloc_free ($3);
- $$ = $1;
- }
| argument '(' argument ')' {
_string_list_append_item ($1, "(");
_string_list_append_list ($1, $3);
string_list_t *list = _string_list_create (parser);
_define_function_macro (parser, $2, $4, list);
}
-| DEFINE IDENTIFIER '(' parameter_list ')' SPACE replacement_list {
- _define_function_macro (parser, $2, $4, $7);
+| DEFINE IDENTIFIER '(' parameter_list ')' replacement_list {
+ _define_function_macro (parser, $2, $4, $6);
}
| UNDEF FUNC_MACRO {
string_list_t *replacement = hash_table_find (parser->defines, $2);
| '(' { $$ = xtalloc_strdup (parser, "("); }
| ')' { $$ = xtalloc_strdup (parser, ")"); }
| ',' { $$ = xtalloc_strdup (parser, ","); }
-| SPACE { $$ = xtalloc_strdup (parser, " "); }
;
parameter_list:
if (list == NULL)
return;
- for (node = list->head; node; node = node->next)
+ for (node = list->head; node; node = node->next) {
printf ("%s", node->str);
+ if (node->next)
+ printf (" ");
+ }
}
argument_list_t *
argument_list_t *arguments)
{
string_list_t *result;
+
macro_t *macro;
result = _string_list_create (parser);