From 0fc7993eb196f50954b9ab4c7e57f3a2b8195019 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 11 Feb 2023 19:56:48 +0100 Subject: [PATCH] use superior skip_char --- lexer.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lexer.c b/lexer.c index 297c410..bc0bb0d 100644 --- a/lexer.c +++ b/lexer.c @@ -217,28 +217,24 @@ Token lexer_make_string(Lexer* lexer) void lexer_skip_literal_char(Lexer* lexer) { - if (lexer_current(lexer) == '\\') { + if (lexer_current(lexer) != '\\') { lexer_step(lexer); - if (!lexer_done(lexer) && lexer_current(lexer) == '0') { + return; + } + lexer_step(lexer); + if (lexer_done(lexer)) + return; + char previous = lexer_current(lexer); + lexer_step(lexer); + if (previous >= '1' && previous <= '9') { + while (!lexer_done(lexer) && isdigit(lexer_current(lexer))) lexer_step(lexer); - } else if (!lexer_done(lexer) && lexer_current(lexer) >= '1' - && lexer_current(lexer) <= '9') { + } else if (previous == 'x' || previous == 'X') { + while (!lexer_done(lexer) + && (isdigit(lexer_current(lexer)) + || (lexer_current(lexer) >= 'a' && lexer_current(lexer) <= 'f') + || (lexer_current(lexer) >= 'A' && lexer_current(lexer) <= 'F'))) lexer_step(lexer); - while (!lexer_done(lexer) && isdigit(lexer_current(lexer))) - lexer_step(lexer); - } else if (!lexer_done(lexer) - && (lexer_current(lexer) == 'x' || lexer_current(lexer) == 'X')) { - lexer_step(lexer); - while (!lexer_done(lexer) - && (isdigit(lexer_current(lexer)) - || (lexer_current(lexer) >= 'a' && lexer_current(lexer) <= 'f') - || (lexer_current(lexer) >= 'A' && lexer_current(lexer) <= 'F'))) - lexer_step(lexer); - } else if (!lexer_done(lexer)) { - lexer_step(lexer); - } - } else { - lexer_step(lexer); } }