X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=discover%2Fgrub2%2Fparser.y;h=eb61f556491c23c503caea2958fa29a408cd866a;hb=561bedfedc9565764f71ac95957accabfdc677ab;hp=2af213218070a0be6cac707b5e51e8fd9a569785;hpb=0ac0cc8dbd8c3687880f3115ae41f9903e9f2333;p=petitboot diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y index 2af2132..eb61f55 100644 --- a/discover/grub2/parser.y +++ b/discover/grub2/parser.y @@ -4,15 +4,20 @@ %parse-param { struct grub2_parser *parser } %{ +#include "grub2.h" +#include "parser.h" #include "lexer.h" + +#define YYLEX_PARAM parser->scanner + +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 */ @@ -35,15 +40,74 @@ %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: /* empty */ +script: statements { + parser->script->statements = $1; + } + +statements: statement { + $$ = create_statements(parser); + statement_append($$, $1); + } + | statements statement { + statement_append($1, $2); + $$ = $1; + } + +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 { + $$ = create_statement_if(parser, $3, $6, NULL); + } + | "menuentry" TOKEN_DELIM words TOKEN_DELIM + '{' statements '}' + TOKEN_EOL { + $$ = create_statement_menuentry(parser, $3, $6); + } + +words: word { + $$ = create_argv(parser); + argv_append($$, $1); + } + | words TOKEN_DELIM word { + argv_append($1, $3); + $$ = $1; + } + +word: TOKEN_WORD + | word TOKEN_WORD { + word_append($1, $2); + $$ = $1; + } %% +void yyerror(struct grub2_parser *parser, char const *s) +{ + fprintf(stderr, "%d: error: %s '%s'\n", + yyget_lineno(parser->scanner), + s, yyget_text(parser->scanner)); +}