Browse Source

ncd: ncd/NCDConfigTokenizer: add If, elif, else tokens.

ambrop7 13 năm trước cách đây
mục cha
commit
49e65392c9

+ 9 - 0
examples/ncd_tokenizer_test.c

@@ -96,6 +96,15 @@ static int tokenizer_output (void *user, int token, char *value, size_t value_le
         case NCD_TOKEN_BRACKET_CLOSE:
         case NCD_TOKEN_BRACKET_CLOSE:
             printf("bracket close\n");
             printf("bracket close\n");
             break;
             break;
+        case NCD_TOKEN_IF:
+            printf("if\n");
+            break;
+        case NCD_TOKEN_ELIF:
+            printf("elif\n");
+            break;
+        case NCD_TOKEN_ELSE:
+            printf("else\n");
+            break;
         default:
         default:
             ASSERT(0);
             ASSERT(0);
     }
     }

+ 9 - 0
ncd/NCDConfigTokenizer.c

@@ -114,6 +114,15 @@ void NCDConfigTokenizer_Tokenize (char *str, size_t left, NCDConfigTokenizer_out
         else if (l = data_begins_with(str, left, "->")) {
         else if (l = data_begins_with(str, left, "->")) {
             token = NCD_TOKEN_ARROW;
             token = NCD_TOKEN_ARROW;
         }
         }
+        else if (l = data_begins_with(str, left, "If")) {
+            token = NCD_TOKEN_IF;
+        }
+        else if (l = data_begins_with(str, left, "elif")) {
+            token = NCD_TOKEN_ELIF;
+        }
+        else if (l = data_begins_with(str, left, "else")) {
+            token = NCD_TOKEN_ELSE;
+        }
         else if (is_name_first_char(*str)) {
         else if (is_name_first_char(*str)) {
             l = 1;
             l = 1;
             while (l < left && is_name_char(str[l])) {
             while (l < left && is_name_char(str[l])) {

+ 3 - 0
ncd/NCDConfigTokenizer.h

@@ -49,6 +49,9 @@
 #define NCD_TOKEN_COLON 13
 #define NCD_TOKEN_COLON 13
 #define NCD_TOKEN_BRACKET_OPEN 14
 #define NCD_TOKEN_BRACKET_OPEN 14
 #define NCD_TOKEN_BRACKET_CLOSE 15
 #define NCD_TOKEN_BRACKET_CLOSE 15
+#define NCD_TOKEN_IF 16
+#define NCD_TOKEN_ELIF 17
+#define NCD_TOKEN_ELSE 18
 
 
 typedef int (*NCDConfigTokenizer_output) (void *user, int token, char *value, size_t value_len, size_t line, size_t line_char);
 typedef int (*NCDConfigTokenizer_output) (void *user, int token, char *value, size_t value_len, size_t line, size_t line_char);