Created
November 6, 2025 23:03
-
-
Save xeioex/9968232b463f9b019581bb22b33469ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit 252eb831250f8c8d5afe9d5b5736093e3421e887 | |
| Author: Dmitry Volyntsev <[email protected]> | |
| Date: Wed Nov 5 14:40:54 2025 -0800 | |
| wip | |
| diff --git a/src/njs_lexer.c b/src/njs_lexer.c | |
| index 4131301d..852a424d 100644 | |
| --- a/src/njs_lexer.c | |
| +++ b/src/njs_lexer.c | |
| @@ -813,96 +813,30 @@ njs_lexer_string(njs_lexer_t *lexer, njs_lexer_token_t *token, u_char quote) | |
| static void | |
| njs_lexer_number(njs_lexer_t *lexer, njs_lexer_token_t *token) | |
| { | |
| - u_char c; | |
| - const u_char *p; | |
| + const char *p; | |
| - c = lexer->start[-1]; | |
| - p = lexer->start; | |
| - | |
| - token->text.start = lexer->start - 1; | |
| - | |
| - if (c == '0' && p != lexer->end) { | |
| - | |
| - /* Hexadecimal literal values. */ | |
| - | |
| - if (*p == 'x' || *p == 'X') { | |
| - p++; | |
| - | |
| - if (p == lexer->end || njs_char_to_hex(*p) < 0) { | |
| - goto illegal_token; | |
| - } | |
| - | |
| - token->number = njs_number_hex_parse(&p, lexer->end, 1); | |
| - | |
| - goto done; | |
| - } | |
| - | |
| - /* Octal literal values. */ | |
| - | |
| - if (*p == 'o' || *p == 'O') { | |
| - p++; | |
| - | |
| - if (p == lexer->end || (u_char)(*p - '0') > 7) { | |
| - goto illegal_token; | |
| - } | |
| - | |
| - token->number = njs_number_oct_parse(&p, lexer->end, 1); | |
| - | |
| - if (p < lexer->end && (*p == '8' || *p == '9')) { | |
| - goto illegal_trailer; | |
| - } | |
| - | |
| - goto done; | |
| - } | |
| - | |
| - /* Binary literal values. */ | |
| - | |
| - if (*p == 'b' || *p == 'B') { | |
| - p++; | |
| - | |
| - if (p == lexer->end || (u_char)(*p - '0') > 1) { | |
| - goto illegal_token; | |
| - } | |
| - | |
| - token->number = njs_number_bin_parse(&p, lexer->end, 1); | |
| - | |
| - if (p < lexer->end && (*p >= '2' && *p <= '9')) { | |
| - goto illegal_trailer; | |
| - } | |
| - | |
| - goto done; | |
| - } | |
| + p = (const char *) lexer->start - 1; | |
| + token->text.start = (u_char *) p; | |
| - /* Legacy Octal literals are deprecated. */ | |
| + token->number = njs_atod((const char *) p, &p, 0, | |
| + JS_ATOD_ACCEPT_BIN_OCT | |
| + | JS_ATOD_ACCEPT_LEGACY_OCTAL | |
| + | JS_ATOD_ACCEPT_UNDERSCORES); | |
| - if ((*p >= '0' && *p <= '9') || *p == '_') { | |
| - goto illegal_trailer; | |
| - } | |
| - } | |
| - | |
| - p--; | |
| - token->number = njs_number_dec_parse(&p, lexer->end, 1); | |
| - | |
| -done: | |
| - | |
| - if (p[-1] == '_') { | |
| - p--; | |
| + if (p == (const char *) token->text.start) { | |
| + goto illegal_token; | |
| } | |
| lexer->start = (u_char *) p; | |
| - token->text.length = p - token->text.start; | |
| + token->text.length = (u_char *) p - token->text.start; | |
| token->type = NJS_TOKEN_NUMBER; | |
| return; | |
| -illegal_trailer: | |
| - | |
| - p++; | |
| - | |
| illegal_token: | |
| - token->text.length = p - token->text.start; | |
| + token->text.length = (u_char *) p - token->text.start; | |
| token->type = NJS_TOKEN_ILLEGAL; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment