X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fgrub2%2Fparser.y;h=d57c732a8382152c690fbabad381b5b266c0f509;hp=dbdde51fe57fbc7377de1c7132f97d831aeee4e6;hb=42e3b424841bb6d8e52802924204f41bd1def070;hpb=2013dd8075a57e5399f080fa8094cc4b464f35cd diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y index dbdde51..d57c732 100644 --- a/discover/grub2/parser.y +++ b/discover/grub2/parser.y @@ -14,11 +14,10 @@ static void yyerror(struct grub2_parser *, char const *s); %} %union { - struct { - char *strval; - int expand; - int split; - }; + struct grub2_word *word; + struct grub2_argv *argv; + struct grub2_statement *statement; + struct grub2_statements *statements; } /* reserved words */ @@ -41,42 +40,68 @@ static void yyerror(struct grub2_parser *, char const *s); %token TOKEN_UTIL "until" %token TOKEN_WHILE "while" +%type statement +%type statements +%type words +%type word + /* syntax */ %token TOKEN_EOL %token TOKEN_DELIM -%token TOKEN_WORD +%token TOKEN_WORD %start script %debug %% -script: statements - ; +script: statements { + parser->statements = $1; + } -statements: statement - | statements statement - ; +statements: statement { + $$ = create_statements(parser); + statement_append($$, $1); + } + | statements statement { + statement_append($1, $2); + } -statement: TOKEN_EOL - | words TOKEN_EOL - | '{' statements '}' +statement: TOKEN_EOL { + $$ = NULL; + } + | words TOKEN_EOL { + $$ = create_statement_simple(parser, $1); + } + | '{' statements '}' { + $$ = create_statement_block(parser, $2); + } | "if" TOKEN_DELIM statement "then" TOKEN_EOL statements - "fi" TOKEN_EOL + "fi" TOKEN_EOL { + $$ = create_statement_if(parser, $3, $6, NULL); + } | "menuentry" TOKEN_DELIM words TOKEN_DELIM '{' statements '}' - TOKEN_EOL - ; + TOKEN_EOL { + $$ = create_statement_menuentry(parser, $3, $6); + } -words: | word - | words TOKEN_DELIM word - ; +words: word { + $$ = create_argv(parser); + argv_append($$, $1); + } + | words TOKEN_DELIM word { + argv_append($1, $3); + $$ = $1; + } word: TOKEN_WORD - | word TOKEN_WORD - ; + | word TOKEN_WORD { + word_append($1, $2); + $$ = $1; + } %% void yyerror(struct grub2_parser *parser, char const *s)