discover/grub2: Add support for for-loops
[petitboot] / discover / grub2 / parser.y
index 0beddd6fc3e28252af96acb74cd12a34a0186ebd..23bf4276818932613b3df07e14a9392861a1e2eb 100644 (file)
@@ -130,6 +130,12 @@ statement:
                /* we just flatten everything */
                $$ = create_statement_block(parser, $6);
        }
+       | "for" TOKEN_DELIM word TOKEN_DELIM "in" TOKEN_DELIM words TOKEN_EOL
+               "do" sep
+               statements
+               "done" {
+               $$ = create_statement_for(parser, $3, $7, $11);
+       }
 
 words: word {
                $$ = create_argv(parser);
@@ -243,6 +249,19 @@ struct grub2_statement *create_statement_function(struct grub2_parser *parser,
        return &stmt->st;
 }
 
+struct grub2_statement *create_statement_for(struct grub2_parser *parser,
+               struct grub2_word *var, struct grub2_argv *list,
+               struct grub2_statements *body)
+{
+       struct grub2_statement_for *stmt =
+               talloc(parser, struct grub2_statement_for);
+       stmt->st.exec = statement_for_execute;
+       stmt->var = var;
+       stmt->list = list;
+       stmt->body = body;
+       return &stmt->st;
+}
+
 void statement_append(struct grub2_statements *stmts,
                struct grub2_statement *stmt)
 {