Handle UTF-8 in character literals

Also handle `\x{hhh..}` in strings... Character literals has to be a single character, not composite.

+ tests (and the corresponding fix to the char literal pretty printer)
This commit is contained in:
Hans Svensson
2020-02-24 15:35:54 +01:00
parent 2bad76314f
commit e98edd4eef
4 changed files with 63 additions and 30 deletions
+7 -2
View File
@@ -369,8 +369,13 @@ expr_p(_, {char, _, C}) ->
case C of
$' -> text("'\\''");
$" -> text("'\"'");
_ -> S = lists:flatten(io_lib:format("~p", [[C]])),
text("'" ++ tl(lists:droplast(S)) ++ "'")
_ when C < 16#80 ->
S = lists:flatten(io_lib:format("~p", [[C]])),
text("'" ++ tl(lists:droplast(S)) ++ "'");
_ ->
S = lists:flatten(
io_lib:format("'~ts'", [list_to_binary(aeso_scan:utf8_encode([C]))])),
text(S)
end;
%% -- Names
expr_p(_, E = {id, _, _}) -> name(E);