diff options
Diffstat (limited to 'discover/grub2')
-rw-r--r-- | discover/grub2/lexer.l | 24 | ||||
-rw-r--r-- | discover/grub2/parser.y | 63 |
2 files changed, 56 insertions, 31 deletions
diff --git a/discover/grub2/lexer.l b/discover/grub2/lexer.l index 18d1667..64eee27 100644 --- a/discover/grub2/lexer.l +++ b/discover/grub2/lexer.l @@ -1,5 +1,6 @@ %{ +#include "grub2.h" #include "parser.h" #include <talloc/talloc.h> %} @@ -50,16 +51,15 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#]) /* anything that's not a metachar: return as a plain word */ {WORD} { - yylval->strval = talloc_strdup(yyscanner, yytext); - yylval->expand = 0; + yylval->word = create_word(yyget_extra(yyscanner), yytext, + false, false); return TOKEN_WORD; } \${VARNAME} | \$\{{VARNAME}\} { - yylval->strval = talloc_strdup(yyscanner, yytext); - yylval->expand = 1; - yylval->split = 1; + yylval->word = create_word(yyget_extra(yyscanner), yytext, + true, true); return TOKEN_WORD; } @@ -69,12 +69,11 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#]) } <sqstring>\' { yy_pop_state(yyscanner); - return TOKEN_WORD; } <sqstring>[^']+ { - yylval->expand = 0; - yylval->split = 0; - yylval->strval = talloc_strdup(yyscanner, yytext); + yylval->word = create_word(yyget_extra(yyscanner), yytext, + false, false); + return TOKEN_WORD; } /* double-quoted strings: return a single, expanded word token */ @@ -83,12 +82,11 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#]) } <dqstring>\" { yy_pop_state(yyscanner); - return TOKEN_WORD; } <dqstring>([^"]|\\\")+ { - yylval->expand = 1; - yylval->split = 0; - yylval->strval = talloc_strdup(yyscanner, yytext); + yylval->word = create_word(yyget_extra(yyscanner), yytext, + true, false); + return TOKEN_WORD; } diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y index 45ad4e1..a8c02e2 100644 --- a/discover/grub2/parser.y +++ b/discover/grub2/parser.y @@ -14,7 +14,10 @@ static void yyerror(struct grub2_parser *, char const *s); %} %union { - struct grub2_word *word; + struct grub2_word *word; + struct grub2_argv *argv; + struct grub2_statement *statement; + struct grub2_statements *statements; } /* reserved words */ @@ -37,42 +40,66 @@ static void yyerror(struct grub2_parser *, char const *s); %token TOKEN_UTIL "until" %token TOKEN_WHILE "while" +%type <statement> statement +%type <statements> statements +%type <argv> words +%type <word> word + /* syntax */ %token TOKEN_EOL %token TOKEN_DELIM -%token TOKEN_WORD +%token <word> 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 '}' { $$ = NULL; } | "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) |