[njs] Introduced njs_parser_peek_token().

Dmitry Volyntsev xeioex at nginx.com
Sun Mar 10 19:49:38 UTC 2019


details:   https://hg.nginx.org/njs/rev/0e8ab0dfd08b
branches:  
changeset: 824:0e8ab0dfd08b
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Sun Mar 10 22:26:25 2019 +0300
description:
Introduced njs_parser_peek_token().

diffstat:

 njs/njs_parser.c |  20 +-------------------
 njs/njs_parser.h |  40 ++++++++++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 29 deletions(-)

diffs (117 lines):

diff -r 5a27272949d8 -r 0e8ab0dfd08b njs/njs_parser.c
--- a/njs/njs_parser.c	Sun Mar 10 21:13:26 2019 +0300
+++ b/njs/njs_parser.c	Sun Mar 10 22:26:25 2019 +0300
@@ -375,7 +375,7 @@ njs_parser_statement(njs_vm_t *vm, njs_p
     default:
 
         if (token == NJS_TOKEN_NAME
-            && njs_lexer_peek_token(vm, parser->lexer, 0) == NJS_TOKEN_COLON)
+            && njs_parser_peek_token(vm, parser, 0) == NJS_TOKEN_COLON)
         {
             return njs_parser_labelled_statement(vm, parser);
         }
@@ -1929,24 +1929,6 @@ njs_parser_property_token(njs_vm_t *vm, 
 
 
 njs_token_t
-njs_parser_token(njs_vm_t *vm, njs_parser_t *parser)
-{
-    njs_token_t  token;
-
-    do {
-        token = njs_lexer_token(vm, parser->lexer);
-
-        if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
-            return token;
-        }
-
-    } while (nxt_slow_path(token == NJS_TOKEN_LINE_END));
-
-    return token;
-}
-
-
-njs_token_t
 njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
 {
     double             num;
diff -r 5a27272949d8 -r 0e8ab0dfd08b njs/njs_parser.h
--- a/njs/njs_parser.h	Sun Mar 10 21:13:26 2019 +0300
+++ b/njs/njs_parser.h	Sun Mar 10 22:26:25 2019 +0300
@@ -8,10 +8,6 @@
 #define _NJS_PARSER_H_INCLUDED_
 
 
-#define njs_parser_is_lvalue(node)                                            \
-    ((node)->token == NJS_TOKEN_NAME || (node)->token == NJS_TOKEN_PROPERTY)
-
-
 struct njs_parser_scope_s {
     njs_parser_node_t               *top;
 
@@ -89,10 +85,8 @@ njs_token_t njs_parser_assignment_expres
 njs_token_t njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser,
     njs_token_t token);
 njs_token_t njs_parser_property_token(njs_vm_t *vm, njs_parser_t *parser);
-njs_token_t njs_parser_token(njs_vm_t *vm, njs_parser_t *parser);
 njs_token_t njs_parser_lambda_statements(njs_vm_t *vm, njs_parser_t *parser,
     njs_token_t token);
-
 njs_variable_t *njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node);
 njs_index_t njs_variable_typeof(njs_vm_t *vm, njs_parser_node_t *node);
 njs_index_t njs_variable_index(njs_vm_t *vm, njs_parser_node_t *node);
@@ -105,6 +99,18 @@ void njs_parser_node_error(njs_vm_t *vm,
     njs_value_type_t type, const char *fmt, ...);
 
 
+#define njs_parser_peek_token(vm, parser, offset)                             \
+    njs_lexer_peek_token(vm, (parser)->lexer, offset)
+
+
+#define njs_parser_is_lvalue(node)                                            \
+    ((node)->token == NJS_TOKEN_NAME || (node)->token == NJS_TOKEN_PROPERTY)
+
+
+#define njs_scope_accumulative(vm, scope)                                     \
+    ((vm)->options.accumulative && (scope)->type == NJS_SCOPE_GLOBAL)
+
+
 #define njs_parser_syntax_error(vm, parser, fmt, ...)                         \
     njs_parser_lexer_error(vm, parser, NJS_OBJECT_SYNTAX_ERROR, fmt,          \
                            ##__VA_ARGS__)
@@ -114,6 +120,24 @@ void njs_parser_node_error(njs_vm_t *vm,
     njs_parser_lexer_error(vm, parser, NJS_OBJECT_REF_ERROR, fmt, ##__VA_ARGS__)
 
 
+nxt_inline njs_token_t
+njs_parser_token(njs_vm_t *vm, njs_parser_t *parser)
+{
+    njs_token_t  token;
+
+    do {
+        token = njs_lexer_token(vm, parser->lexer);
+
+        if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+            return token;
+        }
+
+    } while (nxt_slow_path(token == NJS_TOKEN_LINE_END));
+
+    return token;
+}
+
+
 nxt_inline njs_parser_node_t *
 njs_parser_node_new(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
 {
@@ -145,10 +169,6 @@ njs_parser_global_scope(njs_vm_t *vm)
 }
 
 
-#define njs_scope_accumulative(vm, scope)                                     \
-    ((vm)->options.accumulative && (scope)->type == NJS_SCOPE_GLOBAL)
-
-
 extern const nxt_lvlhsh_proto_t  njs_keyword_hash_proto;
 
 


More information about the nginx-devel mailing list