]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/lexer.l
discover/grub2: Clean up error-handling for grub2 parser & lexer
[petitboot] / discover / grub2 / lexer.l
index 6ed12ce8474a14787137c4a1b035342d6aefc29e..e1aad9931252f98be623a5fc87035a61f3de4ef2 100644 (file)
@@ -3,6 +3,8 @@
 #include "grub2.h"
 #include "parser.h"
 #include <talloc/talloc.h>
 #include "grub2.h"
 #include "parser.h"
 #include <talloc/talloc.h>
+
+void yyerror(struct grub2_parser *parser, const char *fmt, ...);
 %}
 
 %option nounput noinput
 %}
 
 %option nounput noinput
@@ -21,7 +23,7 @@
 %x sqstring
 %x dqstring
 
 %x sqstring
 %x dqstring
 
-WORD   [^{}|&$;<> \t\n'"]+
+WORD   [^{}|&$;<> \t\n'"#]+
 VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 
 %%
 VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 
 %%
@@ -29,7 +31,7 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
  /* discard leading & trailing whitespace, but keep inter-word delimeters */
 ^[ \t]+        ;
 [ \t]+$        ;
  /* discard leading & trailing whitespace, but keep inter-word delimeters */
 ^[ \t]+        ;
 [ \t]+$        ;
-[ \t]* return TOKEN_DELIM;
+[ \t]+ return TOKEN_DELIM;
 
  /* reserved words */
 "[["         return TOKEN_LDSQBRACKET;
 
  /* reserved words */
 "[["         return TOKEN_LDSQBRACKET;
@@ -116,10 +118,12 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 [ \t]*(;|\n)[ \t]*     return TOKEN_EOL;
 
  /* strip comments */
 [ \t]*(;|\n)[ \t]*     return TOKEN_EOL;
 
  /* strip comments */
-#.*$   ;
-
+#.*    ;
 
 
-.      printf("unknown token '%s'\n", yytext); exit(1);
+.      {
+               yyerror(yyget_extra(yyscanner), "unknown token '%s'\n", yytext);
+               yyterminate();
+       }
 
 %%
 
 
 %%