mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
Move character literal processing to the lexer
To match the processing of integer literals, character literals are passed as a string from lexer to parser then interpreted there. This is just as awkward as it was for integer literals, without the excuse that we used to need the information about the dts version to process them correctly. So, move character literal processing back to the lexer as well, cleaning things up. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
b82b977614
commit
cfc6523619
2 changed files with 18 additions and 36 deletions
20
dtc-lexer.l
20
dtc-lexer.l
|
@ -167,9 +167,23 @@ static void lexical_error(const char *fmt, ...);
|
|||
}
|
||||
|
||||
<*>{CHAR_LITERAL} {
|
||||
yytext[yyleng-1] = '\0';
|
||||
yylval.literal = xstrdup(yytext+1);
|
||||
DPRINT("Character literal: %s\n", yylval.literal);
|
||||
struct data d;
|
||||
DPRINT("Character literal: %s\n", yytext);
|
||||
|
||||
d = data_copy_escape_string(yytext+1, yyleng-2);
|
||||
if (d.len == 1) {
|
||||
lexical_error("Empty character literal");
|
||||
yylval.integer = 0;
|
||||
return DT_CHAR_LITERAL;
|
||||
}
|
||||
|
||||
yylval.integer = (unsigned char)d.val[0];
|
||||
|
||||
if (d.len > 2)
|
||||
lexical_error("Character literal has %d"
|
||||
" characters instead of 1",
|
||||
d.len - 1);
|
||||
|
||||
return DT_CHAR_LITERAL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue