Support exponential notation in lexer
This commit is contained in:
parent
34a6e30769
commit
191515bbc3
@ -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
|
||||
|
@ -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
5
src/vendor/rline.c
vendored
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user