summaryrefslogtreecommitdiff
path: root/dtc-lexer.l
diff options
context:
space:
mode:
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r--dtc-lexer.l20
1 files changed, 17 insertions, 3 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l
index ba5d150..0821bde 100644
--- a/dtc-lexer.l
+++ b/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;
}