lexer: add support for line continuations
This commit is contained in:
parent
c2c59495b3
commit
c12374f5fd
16
lexer.cpp
16
lexer.cpp
@ -188,8 +188,12 @@ std::optional<token_t> lexer_t::lex_token()
|
|||||||
case ';':
|
case ';':
|
||||||
while (!at_end_p() && peek() != '\n') advance();
|
while (!at_end_p() && peek() != '\n') advance();
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case '\\':
|
||||||
|
if (match('\n')) { continue; }
|
||||||
|
else if (match('\r')) { if (match('\n')) continue; }
|
||||||
|
break;
|
||||||
case '\r':
|
case '\r':
|
||||||
|
case ' ':
|
||||||
case '\t':
|
case '\t':
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
@ -218,12 +222,18 @@ std::optional<token_t> lexer_t::lex_token()
|
|||||||
if (hex_t::pred(peek())) {
|
if (hex_t::pred(peek())) {
|
||||||
start_ix += 2;
|
start_ix += 2;
|
||||||
return {_number<hex_t>()};
|
return {_number<hex_t>()};
|
||||||
}
|
} else {
|
||||||
|
error(pos.line, pos.col, "expected hexadecimal literal");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
} else if (match('b')) {
|
} else if (match('b')) {
|
||||||
if (bin_t::pred(peek())) {
|
if (bin_t::pred(peek())) {
|
||||||
start_ix += 2;
|
start_ix += 2;
|
||||||
return {_number<bin_t>()};
|
return {_number<bin_t>()};
|
||||||
}
|
} else {
|
||||||
|
error(pos.line, pos.col, "expected binary literal");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user