summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glcpp-lex.l7
-rw-r--r--glcpp-parse.y9
-rw-r--r--glcpp.h1
3 files changed, 11 insertions, 6 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index 13e4d6f0ef..114b59f045 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -173,12 +173,7 @@ TOKEN [^[:space:](),]+
}
\n {
- /* XXX: Printing here (rather than in a parser production)
- * *and* frobbing a bit of the parser state here are both ugly
- * things. But all my attempts to avoid this by returning a
- * NEWLINE token here have led to even more ugly things. */
- printf ("\n");
- yyextra->just_printed_separator = 1;
+ yyextra->need_newline = 1;
}
{HSPACE}+
diff --git a/glcpp-parse.y b/glcpp-parse.y
index 93713a3f0c..ddc2a258cd 100644
--- a/glcpp-parse.y
+++ b/glcpp-parse.y
@@ -171,6 +171,12 @@ input:
if ($2)
talloc_free ($2);
+
+ if (parser->need_newline) {
+ printf ("\n");
+ parser->just_printed_separator = 1;
+ parser->need_newline = 0;
+ }
}
;
@@ -564,6 +570,7 @@ glcpp_parser_create (void)
parser->expansions = NULL;
parser->just_printed_separator = 1;
+ parser->need_newline = 0;
return parser;
}
@@ -577,6 +584,8 @@ glcpp_parser_parse (glcpp_parser_t *parser)
void
glcpp_parser_destroy (glcpp_parser_t *parser)
{
+ if (parser->need_newline)
+ printf ("\n");
glcpp_lex_destroy (parser->scanner);
hash_table_dtor (parser->defines);
talloc_free (parser);
diff --git a/glcpp.h b/glcpp.h
index c25e29c688..2e93cb981d 100644
--- a/glcpp.h
+++ b/glcpp.h
@@ -102,6 +102,7 @@ struct glcpp_parser {
struct hash_table *defines;
expansion_node_t *expansions;
int just_printed_separator;
+ int need_newline;
};
void