Support exponential notation in lexer

This commit is contained in:
K. Lange 2024-02-29 00:29:59 +09:00
parent 34a6e30769
commit 191515bbc3
3 changed files with 13 additions and 1 deletions

View File

@ -800,7 +800,8 @@ static void number(struct GlobalState * state, int exprType, RewindState *rewind
invalidTarget(state, exprType, "literal");
for (size_t j = 0; j < state->parser.previous.length; ++j) {
if (state->parser.previous.start[j] == '.') {
if (start[j] == 'x' || start[j] == 'X') break;
if (start[j] == '.' || start[j] == 'e' || start[j] == 'E') {
#ifndef KRK_NO_FLOAT
emitConstant(krk_parse_float(start, state->parser.previous.length));
#else

View File

@ -180,6 +180,12 @@ static KrkToken number(KrkScanner * scanner, char c) {
while (isDigit(peek(scanner))) advance(scanner);
}
if (peek(scanner) == 'e' || peek(scanner) == 'E') {
advance(scanner);
if (peek(scanner) == '+' || peek(scanner) == '-') advance(scanner);
while (isDigit(peek(scanner))) advance(scanner);
}
return makeToken(scanner, TOKEN_NUMBER);
}

5
src/vendor/rline.c vendored
View File

@ -672,6 +672,11 @@ static int paint_krk_numeral(struct syntax_state * state) {
paint(1, FLAG_NUMERAL);
while (isdigit(charat())) paint(1, FLAG_NUMERAL);
}
if (charat() == 'e' || charat() == 'E') {
paint(1, FLAG_NUMERAL);
if (charat() == '-' || charat() == '+') paint(1, FLAG_NUMERAL);
while (isdigit(charat())) paint(1, FLAG_NUMERAL);
}
}
return 0;
}