discover/grub2: Add structures & API for parser
[petitboot] / discover / grub2 / grub2.h
1 #ifndef GRUB2_H
2 #define GRUB2_H
3
4 #include <stdbool.h>
5 #include <list/list.h>
6
7 struct grub2_parser;
8
9 struct grub2_word {
10         const char              *text;
11         bool                    expand;
12         bool                    split;
13         struct grub2_word       *next;
14         struct list_item        argv_list;
15 };
16
17 struct grub2_argv {
18         struct list             words;
19 };
20
21 struct grub2_statement_simple {
22         struct grub2_argv       *argv;
23 };
24
25 struct grub2_statement_menuentry {
26         struct grub2_argv       *argv;
27         struct grub2_statements *statements;
28 };
29
30 struct grub2_statement_if {
31         struct grub2_statement  *condition;
32         struct grub2_statements *true_case;
33         struct grub2_statements *false_case;
34 };
35
36 struct grub2_statement {
37         struct list_item        list;
38         enum {
39                 STMT_TYPE_SIMPLE,
40                 STMT_TYPE_MENUENTRY,
41                 STMT_TYPE_IF,
42         } type;
43         union {
44                 struct grub2_statement_simple           simple;
45                 struct grub2_statement_menuentry        menuentry;
46                 struct grub2_statement_if               ifstmt;
47         };
48 };
49
50 struct grub2_statements {
51         struct list             list;
52 };
53
54 struct grub2_parser {
55         void                    *scanner;
56         struct grub2_statements *statements;
57 };
58
59 struct grub2_statements *create_statements(struct grub2_parser *parser);
60
61 struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
62                 struct grub2_argv *argv);
63
64 struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
65                 struct grub2_argv *argv, struct grub2_statements *stmts);
66
67 struct grub2_statement *create_statement_if(struct grub2_parser *parser,
68                 struct grub2_statement *condition,
69                 struct grub2_statements *true_case,
70                 struct grub2_statements *false_case);
71
72 struct grub2_word *create_word(struct grub2_parser *parser, const char *text,
73                 bool expand, bool split);
74
75 struct grub2_argv *create_argv(struct grub2_parser *parser);
76
77 void statement_append(struct grub2_statements *stmts,
78                 struct grub2_statement *stmt);
79
80 void argv_append(struct grub2_argv *argv, struct grub2_word *word);
81
82 void word_append(struct grub2_word *w1, struct grub2_word *w2);
83
84 #endif /* GRUB2_H */
85