diff options
author | Hans Bolinder <[email protected]> | 2017-04-10 08:58:25 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2017-04-10 08:58:25 +0200 |
commit | 710abdb5d79554cde4e0ca051bfa16bdcfdccc57 (patch) | |
tree | 8e99daa1f998f49b0bd78a1937d70c9ca07f59eb /lib/syntax_tools/src | |
parent | 3a29920a05cedee8c1f7501ee7b1aa22e068efed (diff) | |
parent | 73657a28e74f8ad12ddb4fea49272a74f5b823c3 (diff) | |
download | otp-710abdb5d79554cde4e0ca051bfa16bdcfdccc57.tar.gz otp-710abdb5d79554cde4e0ca051bfa16bdcfdccc57.tar.bz2 otp-710abdb5d79554cde4e0ca051bfa16bdcfdccc57.zip |
Merge branch 'hasse/unicode_atoms/OTP-14285'
* hasse/unicode_atoms/OTP-14285:
syntax_tools: Fix Syntax Tools regarding Unicode atoms
debugger: Show Latin-1 code correctly
edoc: Fix EDoc regarding Unicode atoms
parsetools: Fix Yecc regarding Unicode atoms
parsetools: Fix Leex regarding Unicode atoms
stdlib: Fix Erlang shell regarding Unicode atoms
stdlib: Fix Erlang pretty printer regarding Unicode atoms
stdlib: Add function to io_lib to handle Unicode atoms
Diffstat (limited to 'lib/syntax_tools/src')
-rw-r--r-- | lib/syntax_tools/src/erl_prettypr.erl | 2 | ||||
-rw-r--r-- | lib/syntax_tools/src/erl_syntax.erl | 25 |
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/syntax_tools/src/erl_prettypr.erl b/lib/syntax_tools/src/erl_prettypr.erl index 378d69095d..40ddd2b22a 100644 --- a/lib/syntax_tools/src/erl_prettypr.erl +++ b/lib/syntax_tools/src/erl_prettypr.erl @@ -452,7 +452,7 @@ lay_2(Node, Ctxt) -> text(erl_syntax:variable_literal(Node)); atom -> - text(erl_syntax:atom_literal(Node)); + text(erl_syntax:atom_literal(Node, Ctxt#ctxt.encoding)); integer -> text(erl_syntax:integer_literal(Node)); diff --git a/lib/syntax_tools/src/erl_syntax.erl b/lib/syntax_tools/src/erl_syntax.erl index 4347cc46c1..9b2b503762 100644 --- a/lib/syntax_tools/src/erl_syntax.erl +++ b/lib/syntax_tools/src/erl_syntax.erl @@ -139,6 +139,7 @@ is_atom/2, atom_value/1, atom_literal/1, + atom_literal/2, atom_name/1, attribute/1, attribute/2, @@ -1841,7 +1842,7 @@ char_literal(Node) -> %% @doc Returns the literal string represented by a `char' %% node. This includes the leading "`$'" character. %% Depending on the encoding a character beyond 255 will be escaped -%% ('latin1') or copied as is ('utf8'). +%% (`latin1') or copied as is (`utf8'). %% %% @see char/1 @@ -1944,7 +1945,7 @@ string_literal(Node) -> %% @doc Returns the literal string represented by a `string' %% node. This includes surrounding double-quote characters. %% Depending on the encoding characters beyond 255 will be escaped -%% ('latin1') or copied as is ('utf8'). +%% (`latin1') or copied as is (`utf8'). %% %% @see string/1 @@ -1965,6 +1966,7 @@ string_literal(Node, latin1) -> %% @see atom_value/1 %% @see atom_name/1 %% @see atom_literal/1 +%% @see atom_literal/2 %% @see is_atom/2 %% type(Node) = atom @@ -2037,6 +2039,7 @@ atom_name(Node) -> %% ===================================================================== %% @doc Returns the literal string represented by an `atom' %% node. This includes surrounding single-quote characters if necessary. +%% Characters beyond 255 will be escaped. %% %% Note that e.g. the result of `atom("x\ny")' represents %% any and all of `'x\ny'', `'x\12y'', @@ -2048,8 +2051,24 @@ atom_name(Node) -> -spec atom_literal(syntaxTree()) -> string(). atom_literal(Node) -> - io_lib:write_atom(atom_value(Node)). + atom_literal(Node, latin1). + +%% ===================================================================== +%% @doc Returns the literal string represented by an `atom' +%% node. This includes surrounding single-quote characters if necessary. +%% Depending on the encoding a character beyond 255 will be escaped +%% (`latin1') or copied as is (`utf8'). +%% +%% @see atom/1 +%% @see atom_literal/1 +%% @see string/1 +atom_literal(Node, utf8) -> + io_lib:write_atom(atom_value(Node)); +atom_literal(Node, unicode) -> + io_lib:write_atom(atom_value(Node)); +atom_literal(Node, latin1) -> + io_lib:write_atom_as_latin1(atom_value(Node)). %% ===================================================================== %% @equiv map_expr(none, Fields) |