kconfig: refactor pattern matching in STRING state
[carl9170fw.git] / config / zconf.l
index 3c3f52a7537e1f51841bb92c82cbdfe8239c8607..323fb5524fe54f4c48839d7e238262b31a0a22b9 100644 (file)
@@ -1,12 +1,13 @@
 %option nostdinit noyywrap never-interactive full ecs
 %option 8bit nodefault yylineno
-%x COMMAND HELP STRING PARAM
+%x COMMAND HELP STRING PARAM ASSIGN_VAL
 %{
 /*
  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  * Released under the terms of the GNU GPL v2.0.
  */
 
+#include <assert.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -72,7 +73,7 @@ static void warn_ignored_character(char chr)
 {
        fprintf(stderr,
                "%s:%d:warning: ignoring unsupported character '%c'\n",
-               zconf_curname(), zconf_lineno(), chr);
+               current_file->name, yylineno, chr);
 }
 %}
 
@@ -87,12 +88,6 @@ n    [A-Za-z0-9_-]
        return T_EOL;
 }
 [ \t]*#.*
-
-
-[ \t]+ {
-       BEGIN(COMMAND);
-}
-
 .      {
        unput(yytext[0]);
        BEGIN(COMMAND);
@@ -102,17 +97,28 @@ n  [A-Za-z0-9_-]
 <COMMAND>{
        {n}+    {
                const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
-               BEGIN(PARAM);
                current_pos.file = current_file;
                current_pos.lineno = yylineno;
                if (id && id->flags & TF_COMMAND) {
+                       BEGIN(PARAM);
                        yylval.id = id;
                        return id->token;
                }
                alloc_string(yytext, yyleng);
                yylval.string = text;
-               return T_WORD;
+               return T_VARIABLE;
+       }
+       ({n}|$)+        {
+               /* this token includes at least one '$' */
+               yylval.string = expand_token(yytext, yyleng);
+               if (strlen(yylval.string))
+                       return T_VARIABLE;
+               free(yylval.string);
        }
+       "="     { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; }
+       ":="    { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; }
+       "+="    { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; }
+       [[:blank:]]+
        .       warn_ignored_character(*yytext);
        \n      {
                BEGIN(INITIAL);
@@ -120,6 +126,16 @@ n  [A-Za-z0-9_-]
        }
 }
 
+<ASSIGN_VAL>{
+       [^[:blank:]\n]+.*       {
+               alloc_string(yytext, yyleng);
+               yylval.string = text;
+               return T_ASSIGN_VAL;
+       }
+       \n      { BEGIN(INITIAL); return T_EOL; }
+       .
+}
+
 <PARAM>{
        "&&"    return T_AND;
        "||"    return T_OR;
@@ -166,19 +182,9 @@ n  [A-Za-z0-9_-]
 
 <STRING>{
        "$".*   append_expanded_string(yytext);
-       [^$'"\\\n]+/\n  {
-               append_string(yytext, yyleng);
-               yylval.string = text;
-               return T_WORD_QUOTE;
-       }
        [^$'"\\\n]+     {
                append_string(yytext, yyleng);
        }
-       \\.?/\n {
-               append_string(yytext + 1, yyleng - 1);
-               yylval.string = text;
-               return T_WORD_QUOTE;
-       }
        \\.?    {
                append_string(yytext + 1, yyleng - 1);
        }
@@ -194,11 +200,15 @@ n [A-Za-z0-9_-]
                fprintf(stderr,
                        "%s:%d:warning: multi-line strings not supported\n",
                        zconf_curname(), zconf_lineno());
+               unput('\n');
                BEGIN(INITIAL);
-               return T_EOL;
+               yylval.string = text;
+               return T_WORD_QUOTE;
        }
        <<EOF>> {
                BEGIN(INITIAL);
+               yylval.string = text;
+               return T_WORD_QUOTE;
        }
 }