From c12374f5fda4724a4886eb4caf69f619f777c69b Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 23 Aug 2023 19:47:55 -0700 Subject: [PATCH] lexer: add support for line continuations --- lexer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lexer.cpp b/lexer.cpp index 7f44134..2a2ee49 100644 --- a/lexer.cpp +++ b/lexer.cpp @@ -188,8 +188,12 @@ std::optional lexer_t::lex_token() case ';': while (!at_end_p() && peek() != '\n') advance(); break; - case ' ': + case '\\': + if (match('\n')) { continue; } + else if (match('\r')) { if (match('\n')) continue; } + break; case '\r': + case ' ': case '\t': break; case '\n': @@ -218,12 +222,18 @@ std::optional lexer_t::lex_token() if (hex_t::pred(peek())) { start_ix += 2; return {_number()}; - } + } else { + error(pos.line, pos.col, "expected hexadecimal literal"); + return {}; + } } else if (match('b')) { if (bin_t::pred(peek())) { start_ix += 2; return {_number()}; - } + } else { + error(pos.line, pos.col, "expected binary literal"); + return {}; + } } [[fallthrough]]; default: