diff options
author | Carl Worth <cworth@cworth.org> | 2010-05-25 17:08:07 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-05-25 17:08:07 -0700 |
commit | e9397867ddce20a4263949f4b3a488fa99af3041 (patch) | |
tree | a73dde532681d25967a22bf29b11b5777449f3ac | |
parent | f8ec4e0be86eee05f5a661a01864247fcd1a6b30 (diff) |
Collapse multiple spaces in input down to a single space.
This is what gcc does, and it's actually less work to do
this. Previously we were having to save the contents of space tokens
as a string, but we don't need to do that now.
We extend test #0 to exercise this feature here.
-rw-r--r-- | glcpp-lex.l | 1 | ||||
-rw-r--r-- | glcpp-parse.y | 10 | ||||
-rw-r--r-- | tests/000-content-with-spaces.c | 2 |
3 files changed, 7 insertions, 6 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l index f6d0c8b..516f42d 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -119,7 +119,6 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? {HSPACE}+ { if (yyextra->space_tokens) { - yylval.str = xtalloc_strdup (yyextra, yytext); return SPACE; } } diff --git a/glcpp-parse.y b/glcpp-parse.y index a198199..0460f71 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -132,8 +132,8 @@ glcpp_parser_lex (glcpp_parser_t *parser); %token HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_UNDEF IDENTIFIER NEWLINE OTHER SPACE %token LEFT_SHIFT RIGHT_SHIFT LESS_OR_EQUAL GREATER_OR_EQUAL EQUAL NOT_EQUAL AND OR PASTE -%type <ival> punctuator -%type <str> IDENTIFIER OTHER SPACE +%type <ival> punctuator SPACE +%type <str> IDENTIFIER OTHER %type <string_list> identifier_list %type <token> preprocessing_token %type <token_list> pp_tokens replacement_list text_line @@ -235,7 +235,7 @@ preprocessing_token: $$ = _token_create_str (parser, OTHER, $1); } | SPACE { - $$ = _token_create_str (parser, SPACE, $1); + $$ = _token_create_ival (parser, SPACE, SPACE); } ; @@ -495,9 +495,11 @@ _token_print (token_t *token) switch (token->type) { case IDENTIFIER: case OTHER: - case SPACE: printf ("%s", token->value.str); break; + case SPACE: + printf (" "); + break; case LEFT_SHIFT: printf ("<<"); break; diff --git a/tests/000-content-with-spaces.c b/tests/000-content-with-spaces.c index a7fc918..696cb3a 100644 --- a/tests/000-content-with-spaces.c +++ b/tests/000-content-with-spaces.c @@ -1 +1 @@ -this is four tokens +this is four tokens |