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>main
parent
9cabae6b03
commit
52f07dcca4
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;
|
||||
}
|
||||
|
||||
<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)? {
|
||||
char *e;
|
||||
DPRINT("Integer Literal: '%s'\n", yytext);
|
||||
|
|
Loading…
Reference in New Issue