harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 273bc207f596c169d875dc95b3007983daae8932
parent 0a1edbd41cf5c026c6e25ec0ab812b0c6c81031b
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri,  6 May 2022 22:46:08 -0400

lex: fix base prefix lexing

Only lex a base prefix that starts with a 0 (e.g. 0x) rather than any
digit.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/lex.c | 40+++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/lex.c b/src/lex.c @@ -287,25 +287,27 @@ lex_literal(struct lexer *lexer, struct token *out) int base = 10; const char *basechrs = "0123456789"; - switch ((c = next(lexer, NULL, true))) { - case 'b': - base = 2; - basechrs = "01"; - consume(lexer, 2); - break; - case 'o': - base = 8; - basechrs = "01234567"; - consume(lexer, 2); - break; - case 'x': - base = 16; - basechrs = "0123456789ABCDEFabcdef"; - consume(lexer, 2); - break; - default: - push(lexer, c, true); - break; + if (c == '0') { + switch ((c = next(lexer, NULL, true))) { + case 'b': + base = 2; + basechrs = "01"; + consume(lexer, 2); + break; + case 'o': + base = 8; + basechrs = "01234567"; + consume(lexer, 2); + break; + case 'x': + base = 16; + basechrs = "0123456789ABCDEFabcdef"; + consume(lexer, 2); + break; + default: + push(lexer, c, true); + break; + } } char *suff = NULL;