Skip to content

Commit c78c8dd

Browse files
author
José Valim
committed
Improve some docs
1 parent 8f34d58 commit c78c8dd

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

lib/elixir/lib/code.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ defmodule Code do
140140
end
141141

142142
@doc """
143-
Converts the given string to AST. It returns { :ok, ast }
144-
if it succeeds, { :error, { line, error, token } } otherwise.
143+
Converts the given string to AST. It returns `{ :ok, ast }`
144+
if it succeeds, `{ :error, { line, error, token } }` otherwise.
145145
146146
## Options
147147
@@ -270,6 +270,15 @@ defmodule Code do
270270
:elixir_compiler.string :unicode.characters_to_list(string), file
271271
end
272272

273+
@doc """
274+
Compiles the quoted expression and returns a list of tuples where
275+
the first element is the module name and the second one is its
276+
binary.
277+
"""
278+
def compile_quoted(quoted, file // "nofile") when is_binary(file) do
279+
:elixir_compiler.quoted [quoted], file
280+
end
281+
273282
@doc """
274283
Ensures the given module is loaded. If the module is already
275284
loaded, it works as no-op. If the module was not loaded yet,

lib/elixir/lib/macro.ex

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ defmodule Macro do
164164

165165
@doc %B"""
166166
Unescape the given chars according to the map given.
167-
Check `unescape/1` if you want to use the same map as
168-
Elixir single- and double-quoted strings.
167+
Check `unescape_binary/1` if you want to use the same map
168+
as Elixir single- and double-quoted strings.
169169
170170
## Map
171171
@@ -211,19 +211,21 @@ defmodule Macro do
211211

212212
@doc """
213213
Unescape the given tokens according to the default map.
214-
Check `unescape/1` and `unescape/2` for more information
215-
about unescaping. Only tokens that are binaries are
216-
unescaped, all others are ignored. This function is useful
217-
when implementing your own sigils. Check the implementation
218-
of `Kernel.__b__` for examples.
214+
Check `unescape_binary/1` and `unescape_binary/2` for more
215+
information about unescaping.
216+
217+
Only tokens that are binaries are unescaped, all others are
218+
ignored. This function is useful when implementing your own
219+
sigils. Check the implementation of `Kernel.__b__`
220+
for examples.
219221
"""
220222
def unescape_tokens(tokens) do
221223
:elixir_interpolation.unescape_tokens(tokens)
222224
end
223225

224226
@doc """
225227
Unescape the given tokens according to the given map.
226-
Check `unescape_tokens/1` and `unescaped/2` for more information.
228+
Check `unescape_tokens/1` and `unescape_binary/2` for more information.
227229
"""
228230
def unescape_tokens(tokens, map) do
229231
:elixir_interpolation.unescape_tokens(tokens, map)
@@ -597,16 +599,16 @@ defmodule Macro do
597599
do_safe_term(terms) || :ok
598600
end
599601

600-
def do_safe_term({ local, _, terms }) when local in [:{}, :[], :__aliases__] do
602+
defp do_safe_term({ local, _, terms }) when local in [:{}, :[], :__aliases__] do
601603
do_safe_term(terms)
602604
end
603605

604-
def do_safe_term({ unary, _, [term] }) when unary in [:+, :-] do
606+
defp do_safe_term({ unary, _, [term] }) when unary in [:+, :-] do
605607
do_safe_term(term)
606608
end
607609

608-
def do_safe_term({ left, right }), do: do_safe_term(left) || do_safe_term(right)
609-
def do_safe_term(terms) when is_list(terms), do: Enum.find_value(terms, do_safe_term(&1))
610-
def do_safe_term(terms) when is_tuple(terms), do: { :unsafe, terms }
611-
def do_safe_term(_), do: nil
610+
defp do_safe_term({ left, right }), do: do_safe_term(left) || do_safe_term(right)
611+
defp do_safe_term(terms) when is_list(terms), do: Enum.find_value(terms, do_safe_term(&1))
612+
defp do_safe_term(terms) when is_tuple(terms), do: { :unsafe, terms }
613+
defp do_safe_term(_), do: nil
612614
end

lib/elixir/src/elixir_compiler.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ get_opts() ->
2222
%% Compiles the given string.
2323

2424
string(Contents, File) when is_list(Contents), is_binary(File) ->
25+
Forms = elixir_translator:'forms!'(Contents, 1, File, []),
26+
quoted(Forms, File).
27+
28+
quoted(Forms, File) when is_binary(File) ->
2529
Previous = get(elixir_compiled),
2630

2731
try
2832
put(elixir_compiled, []),
29-
Forms = elixir_translator:'forms!'(Contents, 1, File, []),
3033
eval_forms(Forms, 1, [], elixir:scope_for_eval([{file,File}])),
3134
lists:reverse(get(elixir_compiled))
3235
after

0 commit comments

Comments
 (0)