4 #include "grub2-parser.h"
5 #include <talloc/talloc.h>
7 void yyerror(struct grub2_parser *parser, const char *fmt, ...);
10 %option nounput noinput
11 %option batch never-interactive
14 %option stack noyy_top_state
18 %option noyyalloc noyyfree noyyrealloc
19 %option extra-type="struct grub2_parser *"
24 WORD [^{}|&$;<> \t\n'"#]+
26 VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
30 /* discard whitespace, unless we're looking for inter-word delimiters */
31 {DELIM} { if (yyget_extra(yyscanner)->inter_word) return TOKEN_DELIM; }
34 "[[" return TOKEN_LDSQBRACKET;
35 "]]" return TOKEN_RDSQBRACKET;
36 "case" return TOKEN_CASE;
38 "done" return TOKEN_DONE;
39 "elif" return TOKEN_ELIF;
40 "else" return TOKEN_ELSE;
41 "esac" return TOKEN_ESAC;
43 "for" return TOKEN_FOR;
44 "function" return TOKEN_FUNCTION;
47 "menuentry" return TOKEN_MENUENTRY;
48 "select" return TOKEN_SELECT;
49 "submenu" return TOKEN_SUBMENU;
50 "then" return TOKEN_THEN;
51 "time" return TOKEN_TIME;
52 "until" return TOKEN_UTIL;
53 "while" return TOKEN_WHILE;
55 /* anything that's not a metachar: return as a plain word */
57 yylval->word = create_word_text(yyget_extra(yyscanner), yytext);
58 yyget_extra(yyscanner)->inter_word = true;
64 if (yytext[1] == '{') {
65 yytext[yyleng-1] = '\0';
69 yylval->word = create_word_var(yyget_extra(yyscanner), yytext,
71 yyget_extra(yyscanner)->inter_word = true;
75 /* single-quoted strings: return a single, non-expanded word token */
77 yy_push_state(sqstring, yyscanner);
80 yy_pop_state(yyscanner);
83 yylval->word = create_word_text(yyget_extra(yyscanner), yytext);
84 yyget_extra(yyscanner)->inter_word = true;
88 /* double-quoted strings: return a single, expanded word token */
90 yy_push_state(dqstring, yyscanner);
93 yy_pop_state(yyscanner);
95 <dqstring>([^"\$]|\\\")+ {
96 yylval->word = create_word_text(yyget_extra(yyscanner), yytext);
97 yyget_extra(yyscanner)->inter_word = true;
100 <dqstring>\${VARNAME} |
101 <dqstring>\$\{{VARNAME}\} {
102 if (yytext[1] == '{') {
103 yytext[yyleng-1] = '\0';
107 yylval->word = create_word_var(yyget_extra(yyscanner), yytext,
109 yyget_extra(yyscanner)->inter_word = true;
116 "{" { yyget_extra(yyscanner)->inter_word = false; return '{'; }
117 "}" { yyget_extra(yyscanner)->inter_word = false; return '}'; }
121 yyget_extra(yyscanner)->inter_word = false;
129 yyerror(yyget_extra(yyscanner), yyscanner,
130 "unknown token '%s'\n", yytext);
138 void *yyalloc(size_t bytes, void *yyscanner)
140 struct grub2_parser *parser = yyget_extra(yyscanner);
141 return talloc_size(parser, bytes);
144 void *yyrealloc(void *ptr, size_t bytes, void *yyscanner)
146 struct grub2_parser *parser = yyget_extra(yyscanner);
147 return talloc_realloc_size(parser, ptr, bytes);
150 void yyfree(void *ptr, void *yyscanner __attribute__((unused)))