summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0ac0cc8)
Add our simple parser to handle a grub2 script. Since we're not building
a parse tree at the moment (we have no reduce rules), we just have a
simple word-based %union for our tokens.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
%parse-param { struct grub2_parser *parser }
%{
%parse-param { struct grub2_parser *parser }
%{
+#include "grub2.h"
+#include "parser.h"
+
+#define YYLEX_PARAM parser->scanner
+
+static void yyerror(struct grub2_parser *, char const *s);
%token TOKEN_WORD
%start script
%token TOKEN_WORD
%start script
+script: statements
+ ;
+
+statements: statement
+ | statements statement
+ ;
+
+statement: TOKEN_EOL
+ | words TOKEN_EOL
+ | '{' statements '}'
+ | "if" TOKEN_DELIM statement
+ "then" TOKEN_EOL
+ statements
+ "fi" TOKEN_EOL
+ | "menuentry" TOKEN_DELIM words TOKEN_DELIM
+ '{' statements '}'
+ TOKEN_EOL
+ ;
+
+words: | word
+ | words TOKEN_DELIM word
+ ;
+
+word: TOKEN_WORD
+ | word TOKEN_WORD
+ ;
+void yyerror(struct grub2_parser *parser, char const *s)
+{
+ fprintf(stderr, "%d: error: %s '%s'\n",
+ yyget_lineno(parser->scanner),
+ s, yyget_text(parser->scanner));
+}