kconfig: use distinct tokens for type and default properties
[carl9170fw.git] / config / zconf.y
index 4aa5ad8dc874049a3ad8130d23078df8090f67d7..de3b94e7f4b680fc0a6ca7e15c53836701147fc5 100644 (file)
@@ -31,7 +31,6 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
 static struct menu *current_menu, *current_entry;
 
 %}
-%expect 29
 
 %union
 {
@@ -41,6 +40,7 @@ static struct menu *current_menu, *current_entry;
        struct expr *expr;
        struct menu *menu;
        const struct kconf_id *id;
+       enum symbol_type type;
        enum variable_flavor flavor;
 }
 
@@ -60,8 +60,6 @@ static struct menu *current_menu, *current_entry;
 %token <id>T_DEPENDS
 %token <id>T_OPTIONAL
 %token <id>T_PROMPT
-%token <id>T_TYPE
-%token <id>T_DEFAULT
 %token <id>T_SELECT
 %token <id>T_IMPLY
 %token <id>T_RANGE
@@ -70,13 +68,16 @@ static struct menu *current_menu, *current_entry;
 %token <id>T_ON
 %token <string> T_WORD
 %token <string> T_WORD_QUOTE
-%token T_UNEQUAL
-%token T_LESS
-%token T_LESS_EQUAL
-%token T_GREATER
-%token T_GREATER_EQUAL
+%token T_BOOL
 %token T_CLOSE_PAREN
+%token T_DEFAULT
+%token T_DEF_BOOL
+%token T_DEF_TRISTATE
+%token T_HEX
+%token T_INT
 %token T_OPEN_PAREN
+%token T_STRING
+%token T_TRISTATE
 %token T_EOL
 %token <string> T_VARIABLE
 %token <flavor> T_ASSIGN
@@ -91,10 +92,10 @@ static struct menu *current_menu, *current_entry;
 %type <string> prompt
 %type <symbol> nonconst_symbol
 %type <symbol> symbol
+%type <type> type logic_type default
 %type <expr> expr
 %type <expr> if_expr
 %type <id> end
-%type <id> option_name
 %type <menu> if_entry menu_entry choice_entry
 %type <string> symbol_option_arg word_opt assign_val
 
@@ -111,9 +112,7 @@ static struct menu *current_menu, *current_entry;
 %}
 
 %%
-input: nl start | start;
-
-start: mainmenu_stmt stmt_list | stmt_list;
+input: mainmenu_stmt stmt_list | stmt_list;
 
 /* mainmenu entry */
 
@@ -127,22 +126,12 @@ stmt_list:
        | stmt_list common_stmt
        | stmt_list choice_stmt
        | stmt_list menu_stmt
-       | stmt_list end                 { zconf_error("unexpected end statement"); }
        | stmt_list T_WORD error T_EOL  { zconf_error("unknown statement \"%s\"", $2); }
-       | stmt_list option_name error T_EOL
-{
-       zconf_error("unexpected option \"%s\"", $2->name);
-}
        | stmt_list error T_EOL         { zconf_error("invalid statement"); }
 ;
 
-option_name:
-       T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
-;
-
 common_stmt:
-         T_EOL
-       | if_stmt
+         if_stmt
        | comment_stmt
        | config_stmt
        | menuconfig_stmt
@@ -150,12 +139,6 @@ common_stmt:
        | assignment_stmt
 ;
 
-option_error:
-         T_WORD error T_EOL            { zconf_error("unknown option \"%s\"", $1); }
-       | error T_EOL                   { zconf_error("invalid option"); }
-;
-
-
 /* config/menuconfig entry */
 
 config_entry_start: T_CONFIG nonconst_symbol T_EOL
@@ -192,16 +175,14 @@ config_option_list:
        | config_option_list symbol_option
        | config_option_list depends
        | config_option_list help
-       | config_option_list option_error
-       | config_option_list T_EOL
 ;
 
-config_option: T_TYPE prompt_stmt_opt T_EOL
+config_option: type prompt_stmt_opt T_EOL
 {
-       menu_set_type($1->stype);
+       menu_set_type($1);
        printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
                zconf_curname(), zconf_lineno(),
-               $1->stype);
+               $1);
 };
 
 config_option: T_PROMPT prompt if_expr T_EOL
@@ -210,14 +191,14 @@ config_option: T_PROMPT prompt if_expr T_EOL
        printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
 };
 
-config_option: T_DEFAULT expr if_expr T_EOL
+config_option: default expr if_expr T_EOL
 {
        menu_add_expr(P_DEFAULT, $2, $3);
-       if ($1->stype != S_UNKNOWN)
-               menu_set_type($1->stype);
+       if ($1 != S_UNKNOWN)
+               menu_set_type($1);
        printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
                zconf_curname(), zconf_lineno(),
-               $1->stype);
+               $1);
 };
 
 config_option: T_SELECT nonconst_symbol if_expr T_EOL
@@ -293,8 +274,6 @@ choice_option_list:
        | choice_option_list choice_option
        | choice_option_list depends
        | choice_option_list help
-       | choice_option_list T_EOL
-       | choice_option_list option_error
 ;
 
 choice_option: T_PROMPT prompt if_expr T_EOL
@@ -303,15 +282,11 @@ choice_option: T_PROMPT prompt if_expr T_EOL
        printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
 };
 
-choice_option: T_TYPE prompt_stmt_opt T_EOL
+choice_option: logic_type prompt_stmt_opt T_EOL
 {
-       if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
-               menu_set_type($1->stype);
-               printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
-                       zconf_curname(), zconf_lineno(),
-                       $1->stype);
-       } else
-               YYERROR;
+       menu_set_type($1);
+       printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
+              zconf_curname(), zconf_lineno(), $1);
 };
 
 choice_option: T_OPTIONAL T_EOL
@@ -322,14 +297,26 @@ choice_option: T_OPTIONAL T_EOL
 
 choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
 {
-       if ($1->stype == S_UNKNOWN) {
-               menu_add_symbol(P_DEFAULT, $2, $3);
-               printd(DEBUG_PARSE, "%s:%d:default\n",
-                       zconf_curname(), zconf_lineno());
-       } else
-               YYERROR;
+       menu_add_symbol(P_DEFAULT, $2, $3);
+       printd(DEBUG_PARSE, "%s:%d:default\n",
+              zconf_curname(), zconf_lineno());
 };
 
+type:
+         logic_type
+       | T_INT                 { $$ = S_INT; }
+       | T_HEX                 { $$ = S_HEX; }
+       | T_STRING              { $$ = S_STRING; }
+
+logic_type:
+         T_BOOL                { $$ = S_BOOLEAN; }
+       | T_TRISTATE            { $$ = S_TRISTATE; }
+
+default:
+         T_DEFAULT             { $$ = S_UNKNOWN; }
+       | T_DEF_BOOL            { $$ = S_BOOLEAN; }
+       | T_DEF_TRISTATE        { $$ = S_TRISTATE; }
+
 choice_block:
          /* empty */
        | choice_block common_stmt
@@ -353,14 +340,7 @@ if_end: end
        }
 };
 
-if_stmt: if_entry if_block if_end
-;
-
-if_block:
-         /* empty */
-       | if_block common_stmt
-       | if_block menu_stmt
-       | if_block choice_stmt
+if_stmt: if_entry stmt_list if_end
 ;
 
 /* menu entry */
@@ -372,7 +352,7 @@ menu: T_MENU prompt T_EOL
        printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
 };
 
-menu_entry: menu visibility_list depends_list
+menu_entry: menu menu_option_list
 {
        $$ = menu_add_menu();
 };
@@ -385,14 +365,13 @@ menu_end: end
        }
 };
 
-menu_stmt: menu_entry menu_block menu_end
+menu_stmt: menu_entry stmt_list menu_end
 ;
 
-menu_block:
+menu_option_list:
          /* empty */
-       | menu_block common_stmt
-       | menu_block menu_stmt
-       | menu_block choice_stmt
+       | menu_option_list visible
+       | menu_option_list depends
 ;
 
 source_stmt: T_SOURCE prompt T_EOL
@@ -411,7 +390,12 @@ comment: T_COMMENT prompt T_EOL
        printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
 };
 
-comment_stmt: comment depends_list
+comment_stmt: comment comment_option_list
+;
+
+comment_option_list:
+         /* empty */
+       | comment_option_list depends
 ;
 
 /* help option */
@@ -440,13 +424,6 @@ help: help_start T_HELPTEXT
 
 /* depends option */
 
-depends_list:
-         /* empty */
-       | depends_list depends
-       | depends_list T_EOL
-       | depends_list option_error
-;
-
 depends: T_DEPENDS T_ON expr T_EOL
 {
        menu_add_dep($3);
@@ -454,13 +431,6 @@ depends: T_DEPENDS T_ON expr T_EOL
 };
 
 /* visibility option */
-
-visibility_list:
-         /* empty */
-       | visibility_list visible
-       | visibility_list T_EOL
-;
-
 visible: T_VISIBLE if_expr T_EOL
 {
        menu_add_visibility($2);
@@ -484,11 +454,6 @@ end:         T_ENDMENU T_EOL       { $$ = $1; }
        | T_ENDIF T_EOL         { $$ = $1; }
 ;
 
-nl:
-         T_EOL
-       | nl T_EOL
-;
-
 if_expr:  /* empty */                  { $$ = NULL; }
        | T_IF expr                     { $$ = $2; }
 ;