]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/parser.y
discover/grub2: Add structures & API for parser
[petitboot] / discover / grub2 / parser.y
index 2af213218070a0be6cac707b5e51e8fd9a569785..45ad4e13127d4414d77db15412c4fe190d45dc80 100644 (file)
@@ -4,15 +4,17 @@
 %parse-param { struct grub2_parser *parser }
 
 %{
+#include "grub2.h"
+#include "parser.h"
 #include "lexer.h"
+
+#define YYLEX_PARAM parser->scanner
+
+static void yyerror(struct grub2_parser *, char const *s);
 %}
 
 %union {
-       struct {
-               char    *strval;
-               int     expand;
-               int     split;
-       };
+       struct grub2_word *word;
 }
 
 /* reserved words */
 %token TOKEN_WORD
 
 %start script
+%debug
 
 %%
 
-script: /* empty */
+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));
+}