ソースを参照

ncd: NCDConfigParser, NCDValueParser: do not assert on unknown tokens

ambrop7 13 年 前
コミット
03aac297ad
2 ファイル変更7 行追加16 行削除
  1. 4 1
      ncd/NCDConfigParser.c
  2. 3 15
      ncd/NCDValueParser.c

+ 4 - 1
ncd/NCDConfigParser.c

@@ -131,7 +131,10 @@ static int tokenizer_output (void *user, int token, char *value, size_t value_le
         } break;
         
         default:
-            ASSERT(0);
+            BLog(BLOG_ERROR, "line %zu, character %zu: invalid token", line, line_char);
+            free(minor.str);
+            state->error = 1;
+            return 0;
     }
     
     // if we got syntax error, stop parsing

+ 3 - 15
ncd/NCDValueParser.c

@@ -67,20 +67,6 @@ static int tokenizer_output (void *user, int token, char *value, size_t value_le
     ASSERT(!state->out.syntax_error)
     ASSERT(!state->error)
     
-    // some tokens are only valid in NCD scripts and not value strings
-    switch (token) {
-        case NCD_TOKEN_NAME:
-        case NCD_TOKEN_ROUND_OPEN:
-        case NCD_TOKEN_ROUND_CLOSE:
-        case NCD_TOKEN_SEMICOLON:
-        case NCD_TOKEN_DOT:
-        case NCD_TOKEN_ARROW:
-        case NCD_TOKEN_PROCESS:
-        case NCD_TOKEN_TEMPLATE:
-            token = NCD_ERROR;
-            free(value);
-    }
-    
     if (token == NCD_ERROR) {
         BLog(BLOG_ERROR, "line %zu, character %zu: tokenizer error", line, line_char);
         goto fail;
@@ -124,7 +110,9 @@ static int tokenizer_output (void *user, int token, char *value, size_t value_le
         } break;
         
         default:
-            ASSERT(0);
+            BLog(BLOG_ERROR, "line %zu, character %zu: invalid token", line, line_char);
+            free(minor.str);
+            goto fail;
     }
     
     if (state->out.syntax_error) {