@@ -81,13 +81,17 @@ do_quote({ quote, _, Args } = Tuple, #elixir_quote{unquote=true} = Q, S) when le
81
81
do_quote ({ unquote , _Meta , [Expr ] }, # elixir_quote {unquote = true } = Q , _ ) ->
82
82
{ Expr , Q # elixir_quote {unquoted = true } };
83
83
84
- do_quote ({ function , Meta , [{ '/' , _ , [{F , _ , C }, A ]}] = Args },
85
- # elixir_quote {imports_hygiene = true } = Q , S ) when is_atom (F ), is_integer (A ), is_atom (C ) ->
86
- do_quote_fa (function , Meta , Args , F , A , Q , S );
84
+ % % Context mark
87
85
88
- do_quote ({ { '.' , _ , [_ , function ] } = Target , Meta , [{ '/' , _ , [{F , _ , C }, A ]}] = Args },
89
- # elixir_quote {imports_hygiene = true } = Q , S ) when is_atom (F ), is_integer (A ), is_atom (C ) ->
90
- do_quote_fa (Target , Meta , Args , F , A , Q , S );
86
+ do_quote ({ Def , Meta , Args }, # elixir_quote {mark = true } = Q , S ) when ? defs (Def ); Def == defmodule ; Def == alias ; Def == import ->
87
+ NewMeta = lists :keystore (context , 1 , Meta , { context , Q # elixir_quote .context }),
88
+ do_quote_tuple ({ Def , NewMeta , Args }, Q , S );
89
+
90
+ do_quote ({ { '.' , _ , [_ , Def ] } = Target , Meta , Args }, # elixir_quote {mark = true } = Q , S ) when ? defs (Def ); Def == defmodule ; Def == alias ; Def == import ->
91
+ NewMeta = lists :keystore (context , 1 , Meta , { context , Q # elixir_quote .context }),
92
+ do_quote_tuple ({ Target , NewMeta , Args }, Q , S );
93
+
94
+ % % Aliases
91
95
92
96
do_quote ({ 'alias!' , _Meta , [Expr ] }, # elixir_quote {aliases_hygiene = true } = Q , S ) ->
93
97
{ TExpr , TQ } = do_quote (Expr , Q # elixir_quote {aliases_hygiene = false }, S ),
@@ -98,21 +102,31 @@ do_quote({ '__aliases__', Meta, [H|T] } = Alias, #elixir_quote{aliases_hygiene=t
98
102
Atom when is_atom (Atom ) -> Atom ;
99
103
Aliases when is_list (Aliases ) -> false
100
104
end ,
101
- NewMeta = lists :keystore (alias , 1 , Meta , { alias , Annotation }),
102
- do_quote_tuple ({ '__aliases__' , NewMeta , [H |T ] }, Q , S );
105
+ AliasMeta = lists :keystore (alias , 1 , Meta , { alias , Annotation }),
106
+ do_quote_tuple ({ '__aliases__' , AliasMeta , [H |T ] }, Q , S );
107
+
108
+ % % Vars
109
+
110
+ do_quote ({ Left , Meta , nil }, # elixir_quote {vars_hygiene = true } = Q , S ) when is_atom (Left ) ->
111
+ do_quote_tuple ({ Left , Meta , Q # elixir_quote .context }, Q , S );
112
+
113
+ % % Unquote
103
114
104
115
do_quote ({ { { '.' , Meta , [Left , unquote ] }, _ , [Expr ] }, _ , Args }, # elixir_quote {unquote = true } = Q , S ) ->
105
116
do_quote_call (Left , Meta , Expr , Args , Q , S );
106
117
107
118
do_quote ({ { '.' , Meta , [Left , unquote ] }, _ , [Expr ] }, # elixir_quote {unquote = true } = Q , S ) ->
108
119
do_quote_call (Left , Meta , Expr , nil , Q , S );
109
120
110
- do_quote ({ Left , Meta , nil }, # elixir_quote {vars_hygiene = true } = Q , S ) when is_atom (Left ) ->
111
- do_quote_tuple ({ Left , Meta , Q # elixir_quote .context }, Q , S );
121
+ % % Imports
122
+
123
+ do_quote ({ function , Meta , [{ '/' , _ , [{F , _ , C }, A ]}] = Args },
124
+ # elixir_quote {imports_hygiene = true } = Q , S ) when is_atom (F ), is_integer (A ), is_atom (C ) ->
125
+ do_quote_fa (function , Meta , Args , F , A , Q , S );
112
126
113
- do_quote ({ import , Meta , Args }, # elixir_quote { imports_hygiene = true } = Q , S ) ->
114
- ImportMeta = lists : keystore ( import , 1 , Meta , { context , Q # elixir_quote . context }),
115
- do_quote_tuple ({ import , ImportMeta , Args } , Q , S );
127
+ do_quote ({ { '.' , _ , [ _ , function ] } = Target , Meta , [{ '/' , _ , [{ F , _ , C }, A ]}] = Args },
128
+ # elixir_quote { imports_hygiene = true } = Q , S ) when is_atom ( F ), is_integer ( A ), is_atom ( C ) ->
129
+ do_quote_fa ( Target , Meta , Args , F , A , Q , S );
116
130
117
131
do_quote ({ Name , Meta , ArgsOrAtom } = Tuple , # elixir_quote {imports_hygiene = true } = Q , S ) when is_atom (Name ) ->
118
132
Arity = case is_atom (ArgsOrAtom ) of
@@ -133,6 +147,8 @@ do_quote({ Name, Meta, ArgsOrAtom } = Tuple, #elixir_quote{imports_hygiene=true}
133
147
do_quote ({ _ , _ , _ } = Tuple , Q , S ) ->
134
148
do_quote_tuple (Tuple , Q , S );
135
149
150
+ % % Literals
151
+
136
152
do_quote ({ Left , Right }, # elixir_quote {unquote = true } = Q , S ) when
137
153
is_tuple (Left ) andalso (element (1 , Left ) == unquote_splicing );
138
154
is_tuple (Right ) andalso (element (1 , Right ) == unquote_splicing ) ->
@@ -174,18 +190,11 @@ do_quote_tuple({ Left, Meta, Right }, Q, S) ->
174
190
{ TRight , RQ } = do_quote (Right , LQ , S ),
175
191
{ { '{}' , [], [TLeft , meta (Meta , Q ), TRight ] }, RQ }.
176
192
177
- meta (Meta , Q ) -> mark_meta (line_meta (Meta , Q ), Q ).
178
-
179
- mark_meta (Meta , # elixir_quote {mark = true }) ->
180
- lists :keystore (quoted , 1 , Meta , { quoted , true });
181
- mark_meta (Meta , # elixir_quote {mark = false }) ->
182
- Meta .
183
-
184
- line_meta (Meta , # elixir_quote {line = keep }) ->
193
+ meta (Meta , # elixir_quote {line = keep }) ->
185
194
Meta ;
186
- line_meta (Meta , # elixir_quote {line = nil }) ->
195
+ meta (Meta , # elixir_quote {line = nil }) ->
187
196
lists :keydelete (line , 1 , Meta );
188
- line_meta (Meta , # elixir_quote {line = Line }) ->
197
+ meta (Meta , # elixir_quote {line = Line }) ->
189
198
lists :keystore (line , 1 , Meta , { line , Line }).
190
199
191
200
% % Quote splicing
0 commit comments