%token <string> T_WORD
%type <string> define;
-%type <string> keyword;
%type <string> line;
%type <string> text;
%type <string> variable;
$$ = NULL;
};
- // XXX T_DEFINE is sort of missing here, but adding it
- // generates a highly ambiguous grammar
-keyword : T_IF;
-
// IF can show up in values and therefore this
// hack is needed to parse those properly
-word : T_WORD
- | keyword;
+word : T_WORD;
words : word
| words word
define : T_DEFINE variable T_EOL
{
$$ = $2;
- }
- | variable T_EOL
- {
- $$ = $1;
};
%%
# #
#############################################################################*/
-%option nounput noinput noyywrap yylineno
+%option noinput noyywrap yylineno
%{
#define YY_DECL int yylex()
quoted_string \"([^\"])*\"
word ({quoted_string}|({digit}|{letter}|{special})+)
+/*
+ Compatibility for the old python parser.
+
+ We automatically prepend "define" in front of some keywords, because
+ generally the language requires it.
+*/
+keywords (description|{whitespace}(build(_cmds)?|install(_cmds)?|prepare_cmds|requires))
+
+%s DEFINE
+
%%
#.*$ { /* ignore comments */ }
{whitespace} {}
\n { num_lines++; return T_EOL; }
-"==" { return T_EQUALS; }
-"=" { return T_ASSIGN; }
-"+=" { return T_APPEND; }
+<INITIAL>^{keywords}$ {
+ // Determine the length of the string
+ size_t length = strlen("define ") + yyleng;
+
+ // Make a copy because unput touches yytext
+ char* buffer = pakfire_malloc(length + 1);
+ snprintf(buffer, length + 1, "define %s", yytext);
+
+ // Put the whole string back onto the stack (backwards)
+ for (int i = length - 1; i >= 0; i--) {
+ unput(buffer[i]);
+ }
+
+ pakfire_free(buffer);
+ }
-"if" { return T_IF; }
-"define" { return T_DEFINE; }
-"def" { return T_DEFINE; }
-"end" { return T_END; }
+<INITIAL>"==" { return T_EQUALS; }
+<INITIAL>"=" { return T_ASSIGN; }
+<INITIAL>"+=" { return T_APPEND; }
+
+<INITIAL>"if" { return T_IF; }
+<INITIAL>"define" {
+ BEGIN(DEFINE);
+ return T_DEFINE;
+ }
+<INITIAL>"def" {
+ BEGIN(DEFINE);
+ return T_DEFINE;
+ }
+<INITIAL>"end" {
+ return T_END;
+ }
+
+<DEFINE>"end" {
+ BEGIN(0);
+ return T_END;
+ }
{quoted_string} {
// Remove quotes