discover/grub2: Implement 'else' blocks
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Sep 2013 08:58:30 +0000 (16:58 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 24 Sep 2013 05:14:59 +0000 (13:14 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/grub2/lexer.l
discover/grub2/parser.y

index 5a4447b500452694efff642649c19b888b4e84f2..3e1f9fa148c62174acb30258328c578c231f954e 100644 (file)
@@ -37,6 +37,7 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 "do"         return TOKEN_DO;
 "done"       return TOKEN_DONE;
 "elif"       return TOKEN_ELIF;
 "do"         return TOKEN_DO;
 "done"       return TOKEN_DONE;
 "elif"       return TOKEN_ELIF;
+"else"       return TOKEN_ELSE;
 "esac"       return TOKEN_ESAC;
 "fi"         return TOKEN_FI;
 "for"        return TOKEN_FOR;
 "esac"       return TOKEN_ESAC;
 "fi"         return TOKEN_FI;
 "for"        return TOKEN_FOR;
index 2b229b80598ae63488bd17b0810f0d7f89e26198..e13cd72a8f72e6358e7dfa7ab7387000b384efc4 100644 (file)
@@ -29,6 +29,7 @@ static void yyerror(struct grub2_parser *, char const *s);
 %token TOKEN_DO                "do"
 %token TOKEN_DONE              "done"
 %token TOKEN_ELIF              "elif"
 %token TOKEN_DO                "do"
 %token TOKEN_DONE              "done"
 %token TOKEN_ELIF              "elif"
+%token TOKEN_ELSE              "else"
 %token TOKEN_ESAC              "esac"
 %token TOKEN_FI                "fi"
 %token TOKEN_FOR               "for"
 %token TOKEN_ESAC              "esac"
 %token TOKEN_FI                "fi"
 %token TOKEN_FOR               "for"
@@ -85,6 +86,14 @@ statement: TOKEN_EOL {
                "fi" TOKEN_EOL {
                $$ = create_statement_if(parser, $3, $6, NULL);
        }
                "fi" TOKEN_EOL {
                $$ = create_statement_if(parser, $3, $6, NULL);
        }
+       | "if" TOKEN_DELIM statement
+               "then" TOKEN_EOL
+               statements
+               "else" TOKEN_EOL
+               statements
+               "fi" TOKEN_EOL {
+               $$ = create_statement_if(parser, $3, $6, $9);
+       }
        | "menuentry" TOKEN_DELIM words TOKEN_DELIM
                '{' statements '}'
                TOKEN_EOL {
        | "menuentry" TOKEN_DELIM words TOKEN_DELIM
                '{' statements '}'
                TOKEN_EOL {