Skip to content

Commit 4b31a32

Browse files
committed
kconfig: update current_pos in the second lexer
To simplify the generated lexer, let the hand-made lexer update the file name and line number for the parser. I tested this with DEBUG_PARSE, and confirmed the same file names and line numbers were dumped. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 824fa3b commit 4b31a32

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎scripts/kconfig/zconf.l‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ n [A-Za-z0-9_-]
101101
<COMMAND>{
102102
{n}+ {
103103
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
104-
current_pos.file = current_file;
105-
current_pos.lineno = yylineno;
106104
if (id && id->flags & TF_COMMAND) {
107105
BEGIN(PARAM);
108106
return id->token;
@@ -285,9 +283,21 @@ int yylex(void)
285283
repeat:
286284
token = yylex1();
287285

288-
/* Do not pass unneeded T_EOL to the parser. */
289-
if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
290-
goto repeat;
286+
if (prev_token == T_EOL || prev_token == T_HELPTEXT) {
287+
if (token == T_EOL) {
288+
/* Do not pass unneeded T_EOL to the parser. */
289+
goto repeat;
290+
} else {
291+
/*
292+
* For the parser, update file/lineno at the first token
293+
* of each statement. Generally, \n is a statement
294+
* terminator in Kconfig, but it is not always true
295+
* because \n could be escaped by a backslash.
296+
*/
297+
current_pos.file = current_file;
298+
current_pos.lineno = yylineno;
299+
}
300+
}
291301

292302
if (prev_prev_token == T_EOL && prev_token == T_WORD &&
293303
(token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))

0 commit comments

Comments
 (0)