Before printing a token using its kind, check whether it has a symbol and print this...
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 13 May 2012 21:30:43 +0000 (23:30 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Mon, 14 May 2012 14:23:37 +0000 (16:23 +0200)
This makes a difference when there are different spellings for the same token.

token.c

diff --git a/token.c b/token.c
index 1aadc6b..c9b0de8 100644 (file)
--- a/token.c
+++ b/token.c
@@ -157,10 +157,15 @@ void print_token(FILE *f, const token_t *token)
                print_stringrep(&token->string.string, f);
                fputs("'", f);
                break;
+
        default:
-               fputc('\'', f);
-               print_token_kind(f, (token_kind_t)token->kind);
-               fputc('\'', f);
+               if (token->base.symbol) {
+                       fprintf(f, "'%s'", token->base.symbol->string);
+               } else {
+                       fputc('\'', f);
+                       print_token_kind(f, (token_kind_t)token->kind);
+                       fputc('\'', f);
+               }
                break;
        }
 }