summaryrefslogtreecommitdiff
path: root/glcpp-parse.y
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-20 14:29:43 -0700
committerCarl Worth <cworth@cworth.org>2010-05-20 14:29:43 -0700
commit5a6b9a27fdb2ac66aaadd90b15b1889fea8f08d0 (patch)
tree1a0b226c9abf5be1280eddf66af93b1f7e895c46 /glcpp-parse.y
parent005b32061f77008530a290ed991980a579095002 (diff)
Avoid printing a space at the beginning of lines in the output.
This fixes more differences compared to "gcc -E" so removes several cases of erroneously failing test cases. The implementation isn't very elegant, but it is functional.
Diffstat (limited to 'glcpp-parse.y')
-rw-r--r--glcpp-parse.y18
1 files changed, 11 insertions, 7 deletions
diff --git a/glcpp-parse.y b/glcpp-parse.y
index c6d64176b2..93713a3f0c 100644
--- a/glcpp-parse.y
+++ b/glcpp-parse.y
@@ -114,7 +114,7 @@ glcpp_parser_lex (glcpp_parser_t *parser);
%lex-param {glcpp_parser_t *parser}
%token DEFINE FUNC_MACRO IDENTIFIER IDENTIFIER_FINALIZED OBJ_MACRO NEWLINE SEPARATOR SPACE TOKEN UNDEF
-%type <ival> input punctuator
+%type <ival> punctuator
%type <str> content FUNC_MACRO IDENTIFIER IDENTIFIER_FINALIZED OBJ_MACRO
%type <argument_list> argument_list
%type <string_list> macro parameter_list
@@ -144,7 +144,7 @@ glcpp_parser_lex (glcpp_parser_t *parser);
* character between any two. */
input:
/* empty */ {
- $$ = SEPARATOR;
+ parser->just_printed_separator = 1;
}
| input content {
int is_token;
@@ -157,16 +157,18 @@ input:
(c >= '0' && c <= '9') ||
(c == '_'));
- if ($1 == TOKEN && is_not_separator)
+ if (! parser->just_printed_separator && is_not_separator)
+ {
printf (" ");
+ }
printf ("%s", $2);
+
if (is_not_separator)
- $$ = TOKEN;
+ parser->just_printed_separator = 0;
else
- $$ = SEPARATOR;
- } else {
- $$ = $1;
+ parser->just_printed_separator = 1;
}
+
if ($2)
talloc_free ($2);
}
@@ -561,6 +563,8 @@ glcpp_parser_create (void)
hash_table_string_compare);
parser->expansions = NULL;
+ parser->just_printed_separator = 1;
+
return parser;
}