Преглед изворни кода

ncd: NCDValueParser_parse: simplify grammar

ambrop7 пре 14 година
родитељ
комит
9f6c7d227a
4 измењених фајлова са 161 додато и 172 уклоњено
  1. 76 78
      generated/NCDValueParser_parse.c
  2. 39 52
      generated/NCDValueParser_parse.out
  3. 23 21
      generated/NCDValueParser_parse.y
  4. 23 21
      ncd/NCDValueParser_parse.y

+ 76 - 78
generated/NCDValueParser_parse.c

@@ -76,7 +76,7 @@ struct parser_out {
 **                       defined, then do no error processing.
 **                       defined, then do no error processing.
 */
 */
 #define YYCODETYPE unsigned char
 #define YYCODETYPE unsigned char
-#define YYNOCODE 10
+#define YYNOCODE 11
 #define YYACTIONTYPE unsigned char
 #define YYACTIONTYPE unsigned char
 #define ParseTOKENTYPE void *
 #define ParseTOKENTYPE void *
 typedef union {
 typedef union {
@@ -91,7 +91,7 @@ typedef union {
 #define ParseARG_PDECL ,struct parser_out *parser_out
 #define ParseARG_PDECL ,struct parser_out *parser_out
 #define ParseARG_FETCH struct parser_out *parser_out = yypParser->parser_out
 #define ParseARG_FETCH struct parser_out *parser_out = yypParser->parser_out
 #define ParseARG_STORE yypParser->parser_out = parser_out
 #define ParseARG_STORE yypParser->parser_out = parser_out
-#define YYNSTATE 13
+#define YYNSTATE 12
 #define YYNRULE 8
 #define YYNRULE 8
 #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
 #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
 #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
 #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
@@ -162,28 +162,26 @@ static const YYMINORTYPE yyzerominor = { 0 };
 **  yy_default[]       Default action for each state.
 **  yy_default[]       Default action for each state.
 */
 */
 static const YYACTIONTYPE yy_action[] = {
 static const YYACTIONTYPE yy_action[] = {
- /*     0 */     6,   13,    1,   11,    4,   14,    1,    5,   22,    2,
- /*    10 */     8,    7,    6,   23,    1,   10,    7,    3,    9,    7,
- /*    20 */    12,
+ /*     0 */     8,   11,    1,   10,    6,    9,    5,    7,    9,    5,
+ /*    10 */     3,    4,    1,   21,    8,   12,    1,   13,    2,
 };
 };
 static const YYCODETYPE yy_lookahead[] = {
 static const YYCODETYPE yy_lookahead[] = {
- /*     0 */     1,    0,    3,    4,    1,    0,    3,    7,    8,    2,
- /*    10 */     6,    7,    1,    9,    3,    6,    7,    2,    6,    7,
- /*    20 */     4,
+ /*     0 */     1,    4,    3,    4,    6,    7,    8,    6,    7,    8,
+ /*    10 */     1,    7,    3,    9,    1,    0,    3,    0,    2,
 };
 };
-#define YY_SHIFT_USE_DFLT (-2)
-#define YY_SHIFT_MAX 8
+#define YY_SHIFT_USE_DFLT (-4)
+#define YY_SHIFT_MAX 6
 static const signed char yy_shift_ofst[] = {
 static const signed char yy_shift_ofst[] = {
- /*     0 */     3,   -1,   11,   11,    1,    5,    7,   15,   16,
+ /*     0 */     9,   -1,   13,   15,   17,   16,   -3,
 };
 };
-#define YY_REDUCE_USE_DFLT (-1)
-#define YY_REDUCE_MAX 3
+#define YY_REDUCE_USE_DFLT (-3)
+#define YY_REDUCE_MAX 2
 static const signed char yy_reduce_ofst[] = {
 static const signed char yy_reduce_ofst[] = {
- /*     0 */     0,    4,    9,   12,
+ /*     0 */     4,   -2,    1,
 };
 };
 static const YYACTIONTYPE yy_default[] = {
 static const YYACTIONTYPE yy_default[] = {
- /*     0 */    21,   21,   21,   21,   21,   21,   15,   16,   21,   18,
- /*    10 */    17,   19,   20,
+ /*     0 */    20,   20,   20,   20,   20,   14,   20,   15,   18,   19,
+ /*    10 */    16,   17,
 };
 };
 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
 
 
@@ -279,7 +277,7 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
 static const char *const yyTokenName[] = { 
 static const char *const yyTokenName[] = { 
   "$",             "STRING",        "COMMA",         "CURLY_OPEN",  
   "$",             "STRING",        "COMMA",         "CURLY_OPEN",  
   "CURLY_CLOSE",   "error",         "list_contents",  "list",        
   "CURLY_CLOSE",   "error",         "list_contents",  "list",        
-  "input",       
+  "value",         "input",       
 };
 };
 #endif /* NDEBUG */
 #endif /* NDEBUG */
 
 
@@ -289,12 +287,12 @@ static const char *const yyTokenName[] = {
 static const char *const yyRuleName[] = {
 static const char *const yyRuleName[] = {
  /*   0 */ "input ::= STRING",
  /*   0 */ "input ::= STRING",
  /*   1 */ "input ::= list",
  /*   1 */ "input ::= list",
- /*   2 */ "list_contents ::= STRING",
- /*   3 */ "list_contents ::= list",
- /*   4 */ "list_contents ::= STRING COMMA list_contents",
- /*   5 */ "list_contents ::= list COMMA list_contents",
- /*   6 */ "list ::= CURLY_OPEN CURLY_CLOSE",
- /*   7 */ "list ::= CURLY_OPEN list_contents CURLY_CLOSE",
+ /*   2 */ "list_contents ::= value",
+ /*   3 */ "list_contents ::= value COMMA list_contents",
+ /*   4 */ "list ::= CURLY_OPEN CURLY_CLOSE",
+ /*   5 */ "list ::= CURLY_OPEN list_contents CURLY_CLOSE",
+ /*   6 */ "value ::= STRING",
+ /*   7 */ "value ::= list",
 };
 };
 #endif /* NDEBUG */
 #endif /* NDEBUG */
 
 
@@ -381,15 +379,16 @@ static void yy_destructor(
 {
 {
 #line 56 "NCDValueParser_parse.y"
 #line 56 "NCDValueParser_parse.y"
  free((yypminor->yy0)); 
  free((yypminor->yy0)); 
-#line 385 "NCDValueParser_parse.c"
+#line 383 "NCDValueParser_parse.c"
 }
 }
       break;
       break;
     case 6: /* list_contents */
     case 6: /* list_contents */
     case 7: /* list */
     case 7: /* list */
+    case 8: /* value */
 {
 {
-#line 61 "NCDValueParser_parse.y"
+#line 62 "NCDValueParser_parse.y"
  NCDConfig_free_list((yypminor->yy14)); 
  NCDConfig_free_list((yypminor->yy14)); 
-#line 393 "NCDValueParser_parse.c"
+#line 392 "NCDValueParser_parse.c"
 }
 }
       break;
       break;
     default:  break;   /* If no destructor action specified: do nothing */
     default:  break;   /* If no destructor action specified: do nothing */
@@ -562,12 +561,12 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
    while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
    while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
    /* Here code is inserted which will execute if the parser
    /* Here code is inserted which will execute if the parser
    ** stack every overflows */
    ** stack every overflows */
-#line 71 "NCDValueParser_parse.y"
+#line 73 "NCDValueParser_parse.y"
 
 
     if (yypMinor) {
     if (yypMinor) {
         free(yypMinor->yy0);
         free(yypMinor->yy0);
     }
     }
-#line 571 "NCDValueParser_parse.c"
+#line 570 "NCDValueParser_parse.c"
    ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
    ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
 }
 }
 
 
@@ -624,14 +623,14 @@ static const struct {
   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
 } yyRuleInfo[] = {
 } yyRuleInfo[] = {
-  { 8, 1 },
-  { 8, 1 },
-  { 6, 1 },
+  { 9, 1 },
+  { 9, 1 },
   { 6, 1 },
   { 6, 1 },
   { 6, 3 },
   { 6, 3 },
-  { 6, 3 },
   { 7, 2 },
   { 7, 2 },
   { 7, 3 },
   { 7, 3 },
+  { 8, 1 },
+  { 8, 1 },
 };
 };
 
 
 static void yy_accept(yyParser*);  /* Forward Declaration */
 static void yy_accept(yyParser*);  /* Forward Declaration */
@@ -687,84 +686,83 @@ static void yy_reduce(
   **     break;
   **     break;
   */
   */
       case 0: /* input ::= STRING */
       case 0: /* input ::= STRING */
-#line 77 "NCDValueParser_parse.y"
+#line 79 "NCDValueParser_parse.y"
 {
 {
     ASSERT(parser_out->ast_type == AST_TYPE_NONE)
     ASSERT(parser_out->ast_type == AST_TYPE_NONE)
 
 
     parser_out->ast_string = yymsp[0].minor.yy0;
     parser_out->ast_string = yymsp[0].minor.yy0;
     parser_out->ast_type = AST_TYPE_STRING;
     parser_out->ast_type = AST_TYPE_STRING;
 }
 }
-#line 698 "NCDValueParser_parse.c"
+#line 697 "NCDValueParser_parse.c"
         break;
         break;
       case 1: /* input ::= list */
       case 1: /* input ::= list */
-#line 84 "NCDValueParser_parse.y"
+#line 86 "NCDValueParser_parse.y"
 {
 {
     ASSERT(parser_out->ast_type == AST_TYPE_NONE)
     ASSERT(parser_out->ast_type == AST_TYPE_NONE)
 
 
     parser_out->ast_list = yymsp[0].minor.yy14;
     parser_out->ast_list = yymsp[0].minor.yy14;
     parser_out->ast_type = AST_TYPE_LIST;
     parser_out->ast_type = AST_TYPE_LIST;
 }
 }
-#line 708 "NCDValueParser_parse.c"
-        break;
-      case 2: /* list_contents ::= STRING */
-#line 91 "NCDValueParser_parse.y"
-{
-    yygotominor.yy14 = NCDConfig_make_list_string(yymsp[0].minor.yy0, NULL);
-    if (!yygotominor.yy14) {
-        parser_out->out_of_memory = 1;
-    }
-}
-#line 718 "NCDValueParser_parse.c"
-        break;
-      case 3: /* list_contents ::= list */
-#line 98 "NCDValueParser_parse.y"
-{
-    yygotominor.yy14 = NCDConfig_make_list_list(yymsp[0].minor.yy14, NULL);
-    if (!yygotominor.yy14) {
-        parser_out->out_of_memory = 1;
-    }
-}
-#line 728 "NCDValueParser_parse.c"
+#line 707 "NCDValueParser_parse.c"
         break;
         break;
-      case 4: /* list_contents ::= STRING COMMA list_contents */
-#line 105 "NCDValueParser_parse.y"
+      case 2: /* list_contents ::= value */
+#line 93 "NCDValueParser_parse.y"
 {
 {
-    yygotominor.yy14 = NCDConfig_make_list_string(yymsp[-2].minor.yy0, yymsp[0].minor.yy14);
-    if (!yygotominor.yy14) {
-        parser_out->out_of_memory = 1;
-    }
-  yy_destructor(yypParser,2,&yymsp[-1].minor);
+    yygotominor.yy14 = yymsp[0].minor.yy14;
 }
 }
-#line 739 "NCDValueParser_parse.c"
+#line 714 "NCDValueParser_parse.c"
         break;
         break;
-      case 5: /* list_contents ::= list COMMA list_contents */
-#line 112 "NCDValueParser_parse.y"
+      case 3: /* list_contents ::= value COMMA list_contents */
+#line 97 "NCDValueParser_parse.y"
 {
 {
-    yygotominor.yy14 = NCDConfig_make_list_list(yymsp[-2].minor.yy14, yymsp[0].minor.yy14);
-    if (!yygotominor.yy14) {
-        parser_out->out_of_memory = 1;
+    if (!yymsp[-2].minor.yy14) {
+        NCDConfig_free_list(yymsp[0].minor.yy14);
+    } else {
+        ASSERT(!yymsp[-2].minor.yy14->next)
+        yymsp[-2].minor.yy14->next = yymsp[0].minor.yy14;
     }
     }
+    yygotominor.yy14 = yymsp[-2].minor.yy14;
   yy_destructor(yypParser,2,&yymsp[-1].minor);
   yy_destructor(yypParser,2,&yymsp[-1].minor);
 }
 }
-#line 750 "NCDValueParser_parse.c"
+#line 728 "NCDValueParser_parse.c"
         break;
         break;
-      case 6: /* list ::= CURLY_OPEN CURLY_CLOSE */
-#line 119 "NCDValueParser_parse.y"
+      case 4: /* list ::= CURLY_OPEN CURLY_CLOSE */
+#line 107 "NCDValueParser_parse.y"
 {
 {
     yygotominor.yy14 = NULL;
     yygotominor.yy14 = NULL;
   yy_destructor(yypParser,3,&yymsp[-1].minor);
   yy_destructor(yypParser,3,&yymsp[-1].minor);
   yy_destructor(yypParser,4,&yymsp[0].minor);
   yy_destructor(yypParser,4,&yymsp[0].minor);
 }
 }
-#line 759 "NCDValueParser_parse.c"
+#line 737 "NCDValueParser_parse.c"
         break;
         break;
-      case 7: /* list ::= CURLY_OPEN list_contents CURLY_CLOSE */
-#line 123 "NCDValueParser_parse.y"
+      case 5: /* list ::= CURLY_OPEN list_contents CURLY_CLOSE */
+#line 111 "NCDValueParser_parse.y"
 {
 {
     yygotominor.yy14 = yymsp[-1].minor.yy14;
     yygotominor.yy14 = yymsp[-1].minor.yy14;
   yy_destructor(yypParser,3,&yymsp[-2].minor);
   yy_destructor(yypParser,3,&yymsp[-2].minor);
   yy_destructor(yypParser,4,&yymsp[0].minor);
   yy_destructor(yypParser,4,&yymsp[0].minor);
 }
 }
-#line 768 "NCDValueParser_parse.c"
+#line 746 "NCDValueParser_parse.c"
+        break;
+      case 6: /* value ::= STRING */
+#line 115 "NCDValueParser_parse.y"
+{
+    yygotominor.yy14 = NCDConfig_make_list_string(yymsp[0].minor.yy0, NULL);
+    if (!yygotominor.yy14) {
+        parser_out->out_of_memory = 1;
+    }
+}
+#line 756 "NCDValueParser_parse.c"
+        break;
+      case 7: /* value ::= list */
+#line 122 "NCDValueParser_parse.y"
+{
+    yygotominor.yy14 = NCDConfig_make_list_list(yymsp[0].minor.yy14, NULL);
+    if (!yygotominor.yy14) {
+        parser_out->out_of_memory = 1;
+    }
+}
+#line 766 "NCDValueParser_parse.c"
         break;
         break;
       default:
       default:
         break;
         break;
@@ -826,10 +824,10 @@ static void yy_syntax_error(
 ){
 ){
   ParseARG_FETCH;
   ParseARG_FETCH;
 #define TOKEN (yyminor.yy0)
 #define TOKEN (yyminor.yy0)
-#line 66 "NCDValueParser_parse.y"
+#line 68 "NCDValueParser_parse.y"
 
 
     parser_out->syntax_error = 1;
     parser_out->syntax_error = 1;
-#line 833 "NCDValueParser_parse.c"
+#line 831 "NCDValueParser_parse.c"
   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
 }
 }
 
 

+ 39 - 52
generated/NCDValueParser_parse.out

@@ -4,103 +4,89 @@ State 0:
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
 
 
-                        STRING shift  4
+                        STRING shift  3
                     CURLY_OPEN shift  1
                     CURLY_OPEN shift  1
-                          list shift  5
+                          list shift  4
                          input accept
                          input accept
 
 
 State 1:
 State 1:
-          list_contents ::= * STRING
-          list_contents ::= * list
-          list_contents ::= * STRING COMMA list_contents
-          list_contents ::= * list COMMA list_contents
+          list_contents ::= * value
+          list_contents ::= * value COMMA list_contents
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= CURLY_OPEN * CURLY_CLOSE
           list ::= CURLY_OPEN * CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
           list ::= CURLY_OPEN * list_contents CURLY_CLOSE
           list ::= CURLY_OPEN * list_contents CURLY_CLOSE
+          value ::= * STRING
+          value ::= * list
 
 
-                        STRING shift  6
+                        STRING shift  8
                     CURLY_OPEN shift  1
                     CURLY_OPEN shift  1
-                   CURLY_CLOSE shift  11
-                 list_contents shift  8
-                          list shift  7
+                   CURLY_CLOSE shift  10
+                 list_contents shift  6
+                          list shift  9
+                         value shift  5
 
 
 State 2:
 State 2:
-          list_contents ::= * STRING
-          list_contents ::= * list
-          list_contents ::= * STRING COMMA list_contents
-          list_contents ::= STRING COMMA * list_contents
-          list_contents ::= * list COMMA list_contents
+          list_contents ::= * value
+          list_contents ::= * value COMMA list_contents
+          list_contents ::= value COMMA * list_contents
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= * CURLY_OPEN CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
           list ::= * CURLY_OPEN list_contents CURLY_CLOSE
+          value ::= * STRING
+          value ::= * list
 
 
-                        STRING shift  6
+                        STRING shift  8
                     CURLY_OPEN shift  1
                     CURLY_OPEN shift  1
-                 list_contents shift  10
-                          list shift  7
+                 list_contents shift  7
+                          list shift  9
+                         value shift  5
 
 
 State 3:
 State 3:
-          list_contents ::= * STRING
-          list_contents ::= * list
-          list_contents ::= * STRING COMMA list_contents
-          list_contents ::= * list COMMA list_contents
-          list_contents ::= list COMMA * list_contents
-          list ::= * CURLY_OPEN CURLY_CLOSE
-          list ::= * CURLY_OPEN list_contents CURLY_CLOSE
-
-                        STRING shift  6
-                    CURLY_OPEN shift  1
-                 list_contents shift  9
-                          list shift  7
-
-State 4:
       (0) input ::= STRING *
       (0) input ::= STRING *
 
 
                              $ reduce 0
                              $ reduce 0
 
 
-State 5:
+State 4:
       (1) input ::= list *
       (1) input ::= list *
 
 
                              $ reduce 1
                              $ reduce 1
 
 
-State 6:
-      (2) list_contents ::= STRING *
-          list_contents ::= STRING * COMMA list_contents
+State 5:
+      (2) list_contents ::= value *
+          list_contents ::= value * COMMA list_contents
 
 
                          COMMA shift  2
                          COMMA shift  2
                      {default} reduce 2
                      {default} reduce 2
 
 
+State 6:
+          list ::= CURLY_OPEN list_contents * CURLY_CLOSE
+
+                   CURLY_CLOSE shift  11
+
 State 7:
 State 7:
-      (3) list_contents ::= list *
-          list_contents ::= list * COMMA list_contents
+      (3) list_contents ::= value COMMA list_contents *
 
 
-                         COMMA shift  3
                      {default} reduce 3
                      {default} reduce 3
 
 
 State 8:
 State 8:
-          list ::= CURLY_OPEN list_contents * CURLY_CLOSE
+      (6) value ::= STRING *
 
 
-                   CURLY_CLOSE shift  12
+                     {default} reduce 6
 
 
 State 9:
 State 9:
-      (5) list_contents ::= list COMMA list_contents *
+      (7) value ::= list *
 
 
-                     {default} reduce 5
+                     {default} reduce 7
 
 
 State 10:
 State 10:
-      (4) list_contents ::= STRING COMMA list_contents *
+      (4) list ::= CURLY_OPEN CURLY_CLOSE *
 
 
                      {default} reduce 4
                      {default} reduce 4
 
 
 State 11:
 State 11:
-      (6) list ::= CURLY_OPEN CURLY_CLOSE *
-
-                     {default} reduce 6
+      (5) list ::= CURLY_OPEN list_contents CURLY_CLOSE *
 
 
-State 12:
-      (7) list ::= CURLY_OPEN list_contents CURLY_CLOSE *
-
-                     {default} reduce 7
+                     {default} reduce 5
 
 
 ----------------------------------------------------
 ----------------------------------------------------
 Symbols:
 Symbols:
@@ -112,4 +98,5 @@ Symbols:
     5: error:
     5: error:
     6: list_contents: STRING CURLY_OPEN
     6: list_contents: STRING CURLY_OPEN
     7: list: CURLY_OPEN
     7: list: CURLY_OPEN
-    8: input: STRING CURLY_OPEN
+    8: value: STRING CURLY_OPEN
+    9: input: STRING CURLY_OPEN

+ 23 - 21
generated/NCDValueParser_parse.y

@@ -57,9 +57,11 @@ struct parser_out {
 
 
 %type list_contents {struct NCDConfig_list *}
 %type list_contents {struct NCDConfig_list *}
 %type list {struct NCDConfig_list *}
 %type list {struct NCDConfig_list *}
+%type value {struct NCDConfig_list *}
 
 
 %destructor list_contents { NCDConfig_free_list($$); }
 %destructor list_contents { NCDConfig_free_list($$); }
 %destructor list { NCDConfig_free_list($$); }
 %destructor list { NCDConfig_free_list($$); }
+%destructor value { NCDConfig_free_list($$); }
 
 
 %stack_size 0
 %stack_size 0
 
 
@@ -88,38 +90,38 @@ input ::= list(A). {
     parser_out->ast_type = AST_TYPE_LIST;
     parser_out->ast_type = AST_TYPE_LIST;
 }
 }
 
 
-list_contents(R) ::= STRING(A). {
-    R = NCDConfig_make_list_string(A, NULL);
-    if (!R) {
-        parser_out->out_of_memory = 1;
-    }
+list_contents(R) ::= value(A). {
+    R = A;
 }
 }
 
 
-list_contents(R) ::= list(A). {
-    R = NCDConfig_make_list_list(A, NULL);
-    if (!R) {
-        parser_out->out_of_memory = 1;
+list_contents(R) ::= value(A) COMMA list_contents(N). {
+    if (!A) {
+        NCDConfig_free_list(N);
+    } else {
+        ASSERT(!A->next)
+        A->next = N;
     }
     }
+    R = A;
 }
 }
 
 
-list_contents(R) ::= STRING(A) COMMA list_contents(N). {
-    R = NCDConfig_make_list_string(A, N);
+list(R) ::= CURLY_OPEN CURLY_CLOSE. {
+    R = NULL;
+}
+
+list(R) ::= CURLY_OPEN list_contents(A) CURLY_CLOSE. {
+    R = A;
+}
+
+value(R) ::= STRING(A). {
+    R = NCDConfig_make_list_string(A, NULL);
     if (!R) {
     if (!R) {
         parser_out->out_of_memory = 1;
         parser_out->out_of_memory = 1;
     }
     }
 }
 }
 
 
-list_contents(R) ::= list(A) COMMA list_contents(N). {
-    R = NCDConfig_make_list_list(A, N);
+value(R) ::= list(A). {
+    R = NCDConfig_make_list_list(A, NULL);
     if (!R) {
     if (!R) {
         parser_out->out_of_memory = 1;
         parser_out->out_of_memory = 1;
     }
     }
 }
 }
-
-list(R) ::= CURLY_OPEN CURLY_CLOSE. {
-    R = NULL;
-}
-
-list(R) ::= CURLY_OPEN list_contents(A) CURLY_CLOSE. {
-    R = A;
-}

+ 23 - 21
ncd/NCDValueParser_parse.y

@@ -57,9 +57,11 @@ struct parser_out {
 
 
 %type list_contents {struct NCDConfig_list *}
 %type list_contents {struct NCDConfig_list *}
 %type list {struct NCDConfig_list *}
 %type list {struct NCDConfig_list *}
+%type value {struct NCDConfig_list *}
 
 
 %destructor list_contents { NCDConfig_free_list($$); }
 %destructor list_contents { NCDConfig_free_list($$); }
 %destructor list { NCDConfig_free_list($$); }
 %destructor list { NCDConfig_free_list($$); }
+%destructor value { NCDConfig_free_list($$); }
 
 
 %stack_size 0
 %stack_size 0
 
 
@@ -88,38 +90,38 @@ input ::= list(A). {
     parser_out->ast_type = AST_TYPE_LIST;
     parser_out->ast_type = AST_TYPE_LIST;
 }
 }
 
 
-list_contents(R) ::= STRING(A). {
-    R = NCDConfig_make_list_string(A, NULL);
-    if (!R) {
-        parser_out->out_of_memory = 1;
-    }
+list_contents(R) ::= value(A). {
+    R = A;
 }
 }
 
 
-list_contents(R) ::= list(A). {
-    R = NCDConfig_make_list_list(A, NULL);
-    if (!R) {
-        parser_out->out_of_memory = 1;
+list_contents(R) ::= value(A) COMMA list_contents(N). {
+    if (!A) {
+        NCDConfig_free_list(N);
+    } else {
+        ASSERT(!A->next)
+        A->next = N;
     }
     }
+    R = A;
 }
 }
 
 
-list_contents(R) ::= STRING(A) COMMA list_contents(N). {
-    R = NCDConfig_make_list_string(A, N);
+list(R) ::= CURLY_OPEN CURLY_CLOSE. {
+    R = NULL;
+}
+
+list(R) ::= CURLY_OPEN list_contents(A) CURLY_CLOSE. {
+    R = A;
+}
+
+value(R) ::= STRING(A). {
+    R = NCDConfig_make_list_string(A, NULL);
     if (!R) {
     if (!R) {
         parser_out->out_of_memory = 1;
         parser_out->out_of_memory = 1;
     }
     }
 }
 }
 
 
-list_contents(R) ::= list(A) COMMA list_contents(N). {
-    R = NCDConfig_make_list_list(A, N);
+value(R) ::= list(A). {
+    R = NCDConfig_make_list_list(A, NULL);
     if (!R) {
     if (!R) {
         parser_out->out_of_memory = 1;
         parser_out->out_of_memory = 1;
     }
     }
 }
 }
-
-list(R) ::= CURLY_OPEN CURLY_CLOSE. {
-    R = NULL;
-}
-
-list(R) ::= CURLY_OPEN list_contents(A) CURLY_CLOSE. {
-    R = A;
-}