[njs] Improved njs_parser_property_token().

Dmitry Volyntsev xeioex at nginx.com
Mon Feb 11 15:16:22 UTC 2019


details:   https://hg.nginx.org/njs/rev/08285ce7dd7c
branches:  
changeset: 772:08285ce7dd7c
user:      hongzhidao <hongzhidao at gmail.com>
date:      Sat Feb 09 16:26:08 2019 +0800
description:
Improved njs_parser_property_token().

diffstat:

 njs/njs_parser.c            |  27 ++++++++++++++++++++++-----
 njs/njs_parser.h            |   4 +---
 njs/njs_parser_expression.c |  26 ++------------------------
 3 files changed, 25 insertions(+), 32 deletions(-)

diffs (138 lines):

diff -r 4e8940c1bef1 -r 08285ce7dd7c njs/njs_parser.c
--- a/njs/njs_parser.c	Fri Feb 08 20:22:28 2019 +0300
+++ b/njs/njs_parser.c	Sat Feb 09 16:26:08 2019 +0800
@@ -60,6 +60,7 @@ static njs_token_t njs_parser_object(njs
     njs_parser_node_t *obj);
 static njs_token_t njs_parser_array(njs_vm_t *vm, njs_parser_t *parser,
     njs_parser_node_t *obj);
+static nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value);
 static njs_token_t njs_parser_escape_string_create(njs_vm_t *vm,
     njs_parser_t *parser, njs_value_t *value);
 static njs_token_t njs_parser_unexpected_token(njs_vm_t *vm,
@@ -1756,9 +1757,11 @@ njs_parser_grouping_expression(njs_vm_t 
 
 
 njs_token_t
-njs_parser_property_token(njs_parser_t *parser)
+njs_parser_property_token(njs_vm_t *vm, njs_parser_t *parser)
 {
-    njs_token_t  token;
+    nxt_int_t          ret;
+    njs_token_t        token;
+    njs_parser_node_t  *node;
 
     parser->lexer->property = 1;
 
@@ -1766,6 +1769,20 @@ njs_parser_property_token(njs_parser_t *
 
     parser->lexer->property = 0;
 
+    if (token == NJS_TOKEN_NAME) {
+        node = njs_parser_node_new(vm, parser, NJS_TOKEN_STRING);
+        if (nxt_slow_path(node == NULL)) {
+            return NJS_TOKEN_ERROR;
+        }
+
+        ret = njs_parser_string_create(vm, &node->u.value);
+        if (nxt_slow_path(ret != NXT_OK)) {
+            return NJS_TOKEN_ERROR;
+        }
+
+        parser->node = node;
+    }
+
     return token;
 }
 
@@ -2183,7 +2200,7 @@ njs_parser_object(njs_vm_t *vm, njs_pars
     object->u.object = obj;
 
     for ( ;; ) {
-        token = njs_parser_property_token(parser);
+        token = njs_parser_property_token(vm, parser);
 
         switch (token) {
 
@@ -2191,7 +2208,7 @@ njs_parser_object(njs_vm_t *vm, njs_pars
             return njs_parser_token(parser);
 
         case NJS_TOKEN_NAME:
-            token = njs_parser_property_name(vm, parser);
+            token = njs_parser_token(parser);
             break;
 
         case NJS_TOKEN_NUMBER:
@@ -2351,7 +2368,7 @@ njs_parser_array(njs_vm_t *vm, njs_parse
 }
 
 
-nxt_int_t
+static nxt_int_t
 njs_parser_string_create(njs_vm_t *vm, njs_value_t *value)
 {
     u_char     *p;
diff -r 4e8940c1bef1 -r 08285ce7dd7c njs/njs_parser.h
--- a/njs/njs_parser.h	Fri Feb 08 20:22:28 2019 +0300
+++ b/njs/njs_parser.h	Sat Feb 09 16:26:08 2019 +0800
@@ -320,10 +320,8 @@ njs_token_t njs_parser_assignment_expres
     njs_parser_t *parser, njs_token_t token);
 njs_token_t njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser,
     njs_token_t token);
-njs_token_t njs_parser_property_name(njs_vm_t *vm, njs_parser_t *parser);
-njs_token_t njs_parser_property_token(njs_parser_t *parser);
+njs_token_t njs_parser_property_token(njs_vm_t *vm, njs_parser_t *parser);
 njs_token_t njs_parser_token(njs_parser_t *parser);
-nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value);
 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);
diff -r 4e8940c1bef1 -r 08285ce7dd7c njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c	Fri Feb 08 20:22:28 2019 +0300
+++ b/njs/njs_parser_expression.c	Sat Feb 09 16:26:08 2019 +0800
@@ -984,7 +984,7 @@ njs_parser_property_expression(njs_vm_t 
 
         if (token == NJS_TOKEN_DOT) {
 
-            token = njs_parser_property_token(parser);
+            token = njs_parser_property_token(vm, parser);
             if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
                 return token;
             }
@@ -993,7 +993,7 @@ njs_parser_property_expression(njs_vm_t 
                 return NJS_TOKEN_ILLEGAL;
             }
 
-            token = njs_parser_property_name(vm, parser);
+            token = njs_parser_token(parser);
 
         } else {
             token = njs_parser_token(parser);
@@ -1014,28 +1014,6 @@ njs_parser_property_expression(njs_vm_t 
 }
 
 
-njs_token_t
-njs_parser_property_name(njs_vm_t *vm, njs_parser_t *parser)
-{
-    nxt_int_t          ret;
-    njs_parser_node_t  *node;
-
-    node = njs_parser_node_new(vm, parser, NJS_TOKEN_STRING);
-    if (nxt_slow_path(node == NULL)) {
-        return NJS_TOKEN_ERROR;
-    }
-
-    ret = njs_parser_string_create(vm, &node->u.value);
-    if (nxt_slow_path(ret != NXT_OK)) {
-        return NJS_TOKEN_ERROR;
-    }
-
-    parser->node = node;
-
-    return njs_parser_token(parser);
-}
-
-
 static njs_token_t
 njs_parser_property_brackets(njs_vm_t *vm, njs_parser_t *parser,
     njs_token_t token)


More information about the nginx-devel mailing list