[njs] Improved parser syntax error.

Dmitry Volyntsev xeioex at nginx.com
Wed Feb 27 17:40:43 UTC 2019


details:   https://hg.nginx.org/njs/rev/d62d0d255b15
branches:  
changeset: 811:d62d0d255b15
user:      hongzhidao <hongzhidao at gmail.com>
date:      Tue Feb 26 10:11:53 2019 +0800
description:
Improved parser syntax error.

diffstat:

 njs/njs_parser.c |  46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)

diffs (65 lines):

diff -r fc69d402ec6d -r d62d0d255b15 njs/njs_parser.c
--- a/njs/njs_parser.c	Wed Feb 27 17:52:50 2019 +0800
+++ b/njs/njs_parser.c	Tue Feb 26 10:11:53 2019 +0800
@@ -278,30 +278,28 @@ njs_parser_statement_chain(njs_vm_t *vm,
 
     token = njs_parser_statement(vm, parser, token);
 
-    if (nxt_fast_path(token > NJS_TOKEN_ILLEGAL)) {
-
-        if (parser->node != NULL) {
-            /* The statement is not empty block or just semicolon. */
-
-            node = njs_parser_node_new(vm, parser, NJS_TOKEN_STATEMENT);
-            if (nxt_slow_path(node == NULL)) {
-                return NJS_TOKEN_ERROR;
-            }
-
-            node->left = last;
-            node->right = parser->node;
-            *dest = node;
-
-            while (token == NJS_TOKEN_SEMICOLON) {
-                token = njs_parser_token(parser);
-                if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
-                    break;
-                }
+    if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+        return njs_parser_unexpected_token(vm, parser, token);
+    }
+
+    if (parser->node != NULL) {
+        /* The statement is not empty block or just semicolon. */
+
+        node = njs_parser_node_new(vm, parser, NJS_TOKEN_STATEMENT);
+        if (nxt_slow_path(node == NULL)) {
+            return NJS_TOKEN_ERROR;
+        }
+
+        node->left = last;
+        node->right = parser->node;
+        *dest = node;
+
+        while (token == NJS_TOKEN_SEMICOLON) {
+            token = njs_parser_token(parser);
+            if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+                break;
             }
         }
-
-    } else if (!njs_is_error(&vm->retval)) {
-        (void) njs_parser_unexpected_token(vm, parser, token);
     }
 
     return token;
@@ -2830,6 +2828,10 @@ njs_parser_lexer_error(njs_vm_t *vm, njs
 {
     va_list  args;
 
+    if (njs_is_error(&vm->retval)) {
+        return;
+    }
+
     va_start(args, fmt);
     njs_parser_scope_error(vm, parser->scope, type, parser->lexer->line, fmt,
                            args);


More information about the nginx-devel mailing list