@@ -2,7 +2,7 @@ import Kernel, except: [to_string: 1]
2
2
3
3
defmodule Macro do
4
4
@ moduledoc """
5
- This module provides conveniences for working with macros.
5
+ Conveniences for working with macros.
6
6
"""
7
7
8
8
@ typedoc "Abstract Syntax Tree (AST) node"
@@ -49,8 +49,9 @@ defmodule Macro do
49
49
end
50
50
51
51
@ doc """
52
- Breaks a pipeline expression into a list. Raises if
53
- the pipeline is ill-formed.
52
+ Breaks a pipeline expression into a list.
53
+
54
+ Raises if the pipeline is ill-formed.
54
55
"""
55
56
@ spec unpipe ( Macro . t ) :: [ Macro . t ]
56
57
def unpipe ( { :|> , _ , [ left , right ] } ) do
@@ -62,7 +63,7 @@ defmodule Macro do
62
63
end
63
64
64
65
@ doc """
65
- Pipes the given `expr` in to the `call_expr` as the
66
+ Pipes `expr` into the `call_expr` as the
66
67
argument in the given `position`.
67
68
"""
68
69
@ spec pipe ( Macro . t , Macro . t , integer ) :: Macro . t | no_return
@@ -125,7 +126,7 @@ defmodule Macro do
125
126
into a syntax tree.
126
127
127
128
One may pass `unquote: true` to `escape/2`
128
- which leaves unquote statements unescaped, effectively
129
+ which leaves ` unquote` statements unescaped, effectively
129
130
unquoting the contents on escape.
130
131
131
132
## Examples
@@ -147,7 +148,9 @@ defmodule Macro do
147
148
end
148
149
149
150
@ doc % S """
150
- Unescape the given chars. This is the unescaping behavior
151
+ Unescape the given chars.
152
+
153
+ This is the unescaping behavior
151
154
used by default in Elixir single- and double-quoted strings.
152
155
Check `unescape_string/2` for information on how to customize
153
156
the escaping map.
@@ -157,7 +160,7 @@ defmodule Macro do
157
160
also escaped according to the latin1 set they represent.
158
161
159
162
This function is commonly used on sigil implementations
160
- (like `%r`, `%b ` and others) which receive a raw, unescaped
163
+ (like `%r`, `%s ` and others) which receive a raw, unescaped
161
164
string.
162
165
163
166
## Examples
@@ -166,7 +169,7 @@ defmodule Macro do
166
169
"example\n "
167
170
168
171
In the example above, we pass a string with `\n ` escaped
169
- and we return a version with it unescaped.
172
+ and return a version with it unescaped.
170
173
"""
171
174
@spec unescape_string( String. t ) :: String . t
172
175
def unescape_string ( chars ) do
@@ -175,13 +178,14 @@ defmodule Macro do
175
178
176
179
@ doc % S """
177
180
Unescape the given chars according to the map given.
181
+
178
182
Check `unescape_string/1` if you want to use the same map
179
183
as Elixir single- and double-quoted strings.
180
184
181
185
## Map
182
186
183
187
The map must be a function. The function receives an integer
184
- representing the number of the characters it wants to unescape.
188
+ representing the codepoint of the character it wants to unescape.
185
189
Here is the default mapping function implemented by Elixir:
186
190
187
191
def unescape_map(?a), do: ?\a
@@ -202,16 +206,16 @@ defmodule Macro do
202
206
## Octals
203
207
204
208
Octals will by default be escaped unless the map function
205
- returns false for ?0 .
209
+ returns ` false` for `?0` .
206
210
207
211
## Hex
208
212
209
213
Hexadecimals will by default be escaped unless the map function
210
- returns false for ?x .
214
+ returns ` false` for `?x` .
211
215
212
216
## Examples
213
217
214
- Using the unescape_map defined above is easy:
218
+ Using the ` unescape_map` function defined above is easy:
215
219
216
220
Macro.unescape_string "example\\ n", &unescape_map(&1)
217
221
@@ -223,12 +227,13 @@ defmodule Macro do
223
227
224
228
@ doc """
225
229
Unescape the given tokens according to the default map.
230
+
226
231
Check `unescape_string/1` and `unescape_string/2` for more
227
232
information about unescaping.
228
233
229
234
Only tokens that are binaries are unescaped, all others are
230
235
ignored. This function is useful when implementing your own
231
- sigils. Check the implementation of `Kernel.sigil_b `
236
+ sigils. Check the implementation of `Kernel.sigil_s/2 `
232
237
for examples.
233
238
"""
234
239
@spec unescape_tokens( [ Macro . t ] ) :: [ Macro . t ]
@@ -238,6 +243,7 @@ defmodule Macro do
238
243
239
244
@ doc """
240
245
Unescape the given tokens according to the given map.
246
+
241
247
Check `unescape_tokens/1` and `unescape_string/2` for more information.
242
248
"""
243
249
@spec unescape_tokens( [ Macro . t ] , ( non_neg_integer -> non_neg_integer | false ) ) :: [ Macro . t ]
@@ -473,18 +479,19 @@ defmodule Macro do
473
479
end
474
480
475
481
@ doc """
476
- Receives a AST node and expands it once. The following contents are expanded:
482
+ Receives an AST node and expands it once.
483
+
484
+ The following contents are expanded:
477
485
478
486
* Macros (local or remote);
479
487
* Aliases are expanded (if possible) and return atoms;
480
488
* All pseudo-variables (`__FILE__`, `__MODULE__`, etc);
481
489
* Module attributes reader (`@foo`);
482
490
483
- In case the expression cannot be expanded, it returns the expression
491
+ If the expression cannot be expanded, it returns the expression
484
492
itself. Notice that `expand_once/2` performs the expansion just
485
493
once and it is not recursive. Check `expand/2` for expansion
486
- until the node no longer represents a macro and `expand_all/2`
487
- for recursive expansion.
494
+ until the node no longer represents a macro.
488
495
489
496
## Examples
490
497
@@ -529,7 +536,7 @@ defmodule Macro do
529
536
end
530
537
531
538
The final module name will be `MyHelpers.Module` and not
532
- `My.Module`. With `Macro.expand`, such aliases are taken
539
+ `My.Module`. With `Macro.expand/2 `, such aliases are taken
533
540
into consideration. Local and remote macros are also
534
541
expanded. We could rewrite our macro above to use this
535
542
function as:
@@ -653,9 +660,11 @@ defmodule Macro do
653
660
end
654
661
655
662
@ doc """
656
- Receives a AST node and expands it until it no longer represents
657
- a macro. Check `expand_once/2` for more information on how
658
- expansion works and `expand_all/2` for recursive expansion.
663
+ Receives an AST node and expands it until it no longer represents
664
+ a macro.
665
+
666
+ Check `expand_once/2` for more information on how
667
+ expansion works.
659
668
"""
660
669
def expand ( tree , env ) do
661
670
elem ( expand ( tree , env , nil ) , 0 )
@@ -700,9 +709,11 @@ defmodule Macro do
700
709
end
701
710
702
711
@ doc """
703
- Recurs the quoted expression checking if all sub-terms are
704
- safe (i.e. they represent data structures and don't actually
705
- evaluate code) and returns `:ok` unless a given term is unsafe,
712
+ Recursively traverses the quoted expression checking if all sub-terms are
713
+ safe.
714
+
715
+ Terms are considered safe if they represent data structures and don't actually
716
+ evaluate code. Returns `:ok` unless a given term is unsafe,
706
717
which is returned as `{ :unsafe, term }`.
707
718
"""
708
719
def safe_term ( terms ) do
0 commit comments