Skip to content

Commit

Permalink
[PATCH] kconfig: improve error handling in the parser
Browse files Browse the repository at this point in the history
Add a few error tokens to the parser to catch common errors and print more
descriptive error messages.

Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Roman Zippel authored and Linus Torvalds committed Nov 9, 2005
1 parent 3370f9f commit a02f057
Show file tree
Hide file tree
Showing 6 changed files with 515 additions and 421 deletions.
57 changes: 30 additions & 27 deletions scripts/kconfig/lex.zconf.c_shipped
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void zconffree (void * );

/* Begin user sect3 */

#define zconfwrap(n) 1
#define zconfwrap() 1
#define YY_SKIP_YYWRAP

typedef unsigned char YY_CHAR;
Expand Down Expand Up @@ -686,10 +686,10 @@ struct yy_trans_info
static yyconst flex_int16_t yy_accept[61] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34, 5, 4, 3, 2, 7, 8, 6, 32, 29,
34, 5, 4, 2, 3, 7, 8, 6, 32, 29,
31, 24, 28, 27, 26, 22, 17, 13, 16, 20,
22, 11, 12, 19, 19, 14, 22, 22, 4, 3,
2, 2, 1, 6, 32, 29, 31, 30, 24, 23,
22, 11, 12, 19, 19, 14, 22, 22, 4, 2,
3, 3, 1, 6, 32, 29, 31, 30, 24, 23,
26, 25, 15, 20, 9, 19, 19, 21, 10, 18
} ;

Expand Down Expand Up @@ -753,6 +753,11 @@ char *zconftext;

#define START_STRSIZE 16

static struct {
struct file *file;
int lineno;
} current_pos;

static char *text;
static int text_size, text_asize;

Expand All @@ -766,7 +771,7 @@ struct buffer *current_buf;
static int last_ts, first_ts;

static void zconf_endhelp(void);
static struct buffer *zconf_endfile(void);
static void zconf_endfile(void);

void new_string(void)
{
Expand Down Expand Up @@ -993,17 +998,17 @@ do_action: /* This label is used only to access EOF actions. */
{ /* beginning of action switch */
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
current_file->lineno++;
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP

{
current_file->lineno++;
return T_EOL;
}
YY_BREAK
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
current_file->lineno++; return T_EOL;

YY_BREAK
case 4:
YY_RULE_SETUP
Expand All @@ -1023,8 +1028,10 @@ case 6:
YY_RULE_SETUP
{
struct kconf_id *id = kconf_id_lookup(zconftext, zconfleng);
BEGIN(PARAM);
current_pos.file = current_file;
current_pos.lineno = current_file->lineno;
if (id && id->flags & TF_COMMAND) {
BEGIN(PARAM);
zconflval.id = id;
return id->token;
}
Expand All @@ -1040,7 +1047,11 @@ YY_RULE_SETUP
case 8:
/* rule 8 can match eol */
YY_RULE_SETUP
current_file->lineno++; BEGIN(INITIAL);
{
BEGIN(INITIAL);
current_file->lineno++;
return T_EOL;
}
YY_BREAK

case 9:
Expand Down Expand Up @@ -1246,9 +1257,9 @@ case YY_STATE_EOF(HELP):
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(COMMAND):
{
if (current_buf) {
if (current_file) {
zconf_endfile();
return T_EOF;
return T_EOL;
}
fclose(zconfin);
yyterminate();
Expand Down Expand Up @@ -1958,7 +1969,7 @@ YY_BUFFER_STATE zconf_scan_buffer (char * base, yy_size_t size )

/** Setup the input buffer state to scan a string. The next call to zconflex() will
* scan from a @e copy of @a str.
* @param str a NUL-terminated string to scan
* @param yy_str a NUL-terminated string to scan
*
* @return the newly allocated buffer state object.
* @note If you want to scan bytes that may contain NUL values, then use
Expand Down Expand Up @@ -2276,7 +2287,7 @@ void zconf_nextfile(const char *name)
current_file = file;
}

static struct buffer *zconf_endfile(void)
static void zconf_endfile(void)
{
struct buffer *parent;

Expand All @@ -2292,23 +2303,15 @@ static struct buffer *zconf_endfile(void)
}
free(current_buf);
current_buf = parent;

return parent;
}

int zconf_lineno(void)
{
if (current_buf)
return current_file->lineno - 1;
else
return 0;
return current_pos.lineno;
}

char *zconf_curname(void)
{
if (current_buf)
return current_file->name;
else
return "<none>";
return current_pos.file ? current_pos.file->name : "<none>";
}

2 changes: 1 addition & 1 deletion scripts/kconfig/lkc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void kconfig_load(void);

/* menu.c */
void menu_init(void);
void menu_add_menu(void);
struct menu *menu_add_menu(void);
void menu_end_menu(void);
void menu_add_entry(struct symbol *sym);
void menu_end_entry(void);
Expand Down
5 changes: 3 additions & 2 deletions scripts/kconfig/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ void menu_end_entry(void)
{
}

void menu_add_menu(void)
struct menu *menu_add_menu(void)
{
current_menu = current_entry;
menu_end_entry();
last_entry_ptr = &current_entry->list;
return current_menu = current_entry;
}

void menu_end_menu(void)
Expand Down
42 changes: 24 additions & 18 deletions scripts/kconfig/zconf.l
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

#define START_STRSIZE 16

static struct {
struct file *file;
int lineno;
} current_pos;

static char *text;
static int text_size, text_asize;

Expand All @@ -31,7 +36,7 @@ struct buffer *current_buf;
static int last_ts, first_ts;

static void zconf_endhelp(void);
static struct buffer *zconf_endfile(void);
static void zconf_endfile(void);

void new_string(void)
{
Expand Down Expand Up @@ -70,10 +75,13 @@ n [A-Za-z0-9_]
int str = 0;
int ts, i;

[ \t]*#.*\n current_file->lineno++;
[ \t]*#.*\n |
[ \t]*\n {
current_file->lineno++;
return T_EOL;
}
[ \t]*#.*

[ \t]*\n current_file->lineno++; return T_EOL;

[ \t]+ {
BEGIN(COMMAND);
Expand All @@ -88,8 +96,10 @@ n [A-Za-z0-9_]
<COMMAND>{
{n}+ {
struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
BEGIN(PARAM);
current_pos.file = current_file;
current_pos.lineno = current_file->lineno;
if (id && id->flags & TF_COMMAND) {
BEGIN(PARAM);
zconflval.id = id;
return id->token;
}
Expand All @@ -98,7 +108,11 @@ n [A-Za-z0-9_]
return T_WORD;
}
.
\n current_file->lineno++; BEGIN(INITIAL);
\n {
BEGIN(INITIAL);
current_file->lineno++;
return T_EOL;
}
}

<PARAM>{
Expand Down Expand Up @@ -214,9 +228,9 @@ n [A-Za-z0-9_]
}

<<EOF>> {
if (current_buf) {
if (current_file) {
zconf_endfile();
return T_EOF;
return T_EOL;
}
fclose(yyin);
yyterminate();
Expand Down Expand Up @@ -307,7 +321,7 @@ void zconf_nextfile(const char *name)
current_file = file;
}

static struct buffer *zconf_endfile(void)
static void zconf_endfile(void)
{
struct buffer *parent;

Expand All @@ -323,22 +337,14 @@ static struct buffer *zconf_endfile(void)
}
free(current_buf);
current_buf = parent;

return parent;
}

int zconf_lineno(void)
{
if (current_buf)
return current_file->lineno - 1;
else
return 0;
return current_pos.lineno;
}

char *zconf_curname(void)
{
if (current_buf)
return current_file->name;
else
return "<none>";
return current_pos.file ? current_pos.file->name : "<none>";
}
Loading

0 comments on commit a02f057

Please sign in to comment.