mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
dtc: Add informative error for stray identifier
When a DTS is preprocessed, sometimes the user fails to include the correct header files, or make a spelling mistake on a macro name. This leads to a stray identifier in the DTS, like: property = <1 2 FOO BAR(3, 4)>; Give a more helpful error message than "syntax error" by recognizing and reporting the identifier, like this: Lexical error: <stdin>:2.21-24 Unexpected 'FOO' Also, treat that identifier as literal, which often helps the parser go further and may generate more helpful error messages. Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9cabae6b03
commit
52f07dcca4
1 changed files with 15 additions and 0 deletions
15
dtc-lexer.l
15
dtc-lexer.l
|
@ -151,6 +151,21 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
|
||||||
return DT_LABEL;
|
return DT_LABEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<V1>{LABEL} {
|
||||||
|
/* Missed includes or macro definitions while
|
||||||
|
* preprocessing can lead to unexpected identifiers in
|
||||||
|
* the input. Report a slightly more informative error
|
||||||
|
* in this case */
|
||||||
|
|
||||||
|
lexical_error("Unexpected '%s'", yytext);
|
||||||
|
|
||||||
|
/* Treat it as a literal which often generates further
|
||||||
|
* useful error messages */
|
||||||
|
|
||||||
|
yylval.integer = 0;
|
||||||
|
return DT_LITERAL;
|
||||||
|
}
|
||||||
|
|
||||||
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
|
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
|
||||||
char *e;
|
char *e;
|
||||||
DPRINT("Integer Literal: '%s'\n", yytext);
|
DPRINT("Integer Literal: '%s'\n", yytext);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue