[njs] Improved njs_lexer_rollback().
Dmitry Volyntsev
xeioex at nginx.com
Sat Apr 27 17:45:08 UTC 2019
details: https://hg.nginx.org/njs/rev/2f1f71863953
branches:
changeset: 936:2f1f71863953
user: hongzhidao <hongzhidao at gmail.com>
date: Sat Apr 27 09:04:24 2019 +0800
description:
Improved njs_lexer_rollback().
diffstat:
njs/njs_lexer.c | 14 ++++++++------
njs/njs_lexer.h | 1 -
njs/test/njs_unit_test.c | 6 ++++++
3 files changed, 14 insertions(+), 7 deletions(-)
diffs (58 lines):
diff -r 277845bea37a -r 2f1f71863953 njs/njs_lexer.c
--- a/njs/njs_lexer.c Sat Apr 27 20:28:37 2019 +0300
+++ b/njs/njs_lexer.c Sat Apr 27 09:04:24 2019 +0800
@@ -307,11 +307,6 @@ njs_lexer_token(njs_vm_t *vm, njs_lexer_
lexer->prev_start = lexer->start;
- if (lexer->lexer_token != NULL) {
- lexer->prev_token = lexer->lexer_token->token;
- nxt_mp_free(vm->mem_pool, lexer->lexer_token);
- }
-
if (nxt_queue_is_empty(&lexer->preread)) {
lt = njs_lexer_token_push(vm, lexer);
if (nxt_slow_path(lt == NULL)) {
@@ -319,7 +314,14 @@ njs_lexer_token(njs_vm_t *vm, njs_lexer_
}
}
- lexer->lexer_token = njs_lexer_token_pop(lexer);
+ lt = njs_lexer_token_pop(lexer);
+
+ if (lexer->lexer_token != NULL && lexer->lexer_token != lt) {
+ lexer->prev_token = lexer->lexer_token->token;
+ nxt_mp_free(vm->mem_pool, lexer->lexer_token);
+ }
+
+ lexer->lexer_token = lt;
return njs_lexer_token_name_resolve(lexer, lexer->lexer_token);
}
diff -r 277845bea37a -r 2f1f71863953 njs/njs_lexer.h
--- a/njs/njs_lexer.h Sat Apr 27 20:28:37 2019 +0300
+++ b/njs/njs_lexer.h Sat Apr 27 09:04:24 2019 +0800
@@ -264,7 +264,6 @@ void njs_lexer_keyword(njs_lexer_t *lexe
#define njs_lexer_rollback(lexer) \
do { \
nxt_queue_insert_head(&(lexer)->preread, &(lexer)->lexer_token->link); \
- (lexer)->lexer_token = NULL; \
} while (0)
diff -r 277845bea37a -r 2f1f71863953 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Sat Apr 27 20:28:37 2019 +0300
+++ b/njs/test/njs_unit_test.c Sat Apr 27 09:04:24 2019 +0800
@@ -2157,6 +2157,12 @@ static njs_unit_test_t njs_test[] =
/* automatic semicolon insertion. */
+ { nxt_string("(a\n--"),
+ nxt_string("SyntaxError: Unexpected token \"--\" in 2") },
+
+ { nxt_string("(a\n++"),
+ nxt_string("SyntaxError: Unexpected token \"++\" in 2") },
+
{ nxt_string("var x = 0, y = 2; x\n--\ny; [x,y]"),
nxt_string("0,1") },
More information about the nginx-devel
mailing list