3
3
-export ([tokenize /3 ]).
4
4
-import (elixir_interpolation , [unescape_tokens /1 ]).
5
5
6
- -define (container (T1 , T2 ),
7
- T1 == ${ , T2 == $} ;
8
- T1 == $[ , T2 == $]
9
- ).
10
-
11
6
-define (at_op (T ),
12
7
T == $@ ).
13
8
@@ -160,47 +155,58 @@ tokenize([$~,S,H|T] = Original, Line, Scope, Tokens) when ?is_sigil(H), ?is_upca
160
155
161
156
% Char tokens
162
157
163
- tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,E ,F ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ), ? is_hex (E ), ? is_hex (F ) ->
158
+ tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,E ,F ,$} |T ], Line , Scope , Tokens )
159
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ), ? is_hex (E ), ? is_hex (F ) ->
164
160
Char = escape_char ([$\\ ,P ,${ ,A ,B ,C ,D ,E ,F ,$} ]),
165
161
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
166
162
167
- tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,E ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ), ? is_hex (E ) ->
163
+ tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,E ,$} |T ], Line , Scope , Tokens )
164
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ), ? is_hex (E ) ->
168
165
Char = escape_char ([$\\ ,P ,${ ,A ,B ,C ,D ,E ,$} ]),
169
166
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
170
167
171
- tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ) ->
168
+ tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,D ,$} |T ], Line , Scope , Tokens )
169
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ), ? is_hex (D ) ->
172
170
Char = escape_char ([$\\ ,P ,${ ,A ,B ,C ,D ,$} ]),
173
171
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
174
172
175
- tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ) ->
173
+ tokenize ([$? ,$\\ ,P ,${ ,A ,B ,C ,$} |T ], Line , Scope , Tokens )
174
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ), ? is_hex (C ) ->
176
175
Char = escape_char ([$\\ ,P ,${ ,A ,B ,C ,$} ]),
177
176
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
178
177
179
- tokenize ([$? ,$\\ ,P ,${ ,A ,B ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ) ->
178
+ tokenize ([$? ,$\\ ,P ,${ ,A ,B ,$} |T ], Line , Scope , Tokens )
179
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ) ->
180
180
Char = escape_char ([$\\ ,P ,${ ,A ,B ,$} ]),
181
181
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
182
182
183
- tokenize ([$? ,$\\ ,P ,${ ,A ,$} |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ) ->
183
+ tokenize ([$? ,$\\ ,P ,${ ,A ,$} |T ], Line , Scope , Tokens )
184
+ when (P == $x orelse P == $X ), ? is_hex (A ) ->
184
185
Char = escape_char ([$\\ ,P ,${ ,A ,$} ]),
185
186
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
186
187
187
- tokenize ([$? ,$\\ ,P ,A ,B |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ) ->
188
+ tokenize ([$? ,$\\ ,P ,A ,B |T ], Line , Scope , Tokens )
189
+ when (P == $x orelse P == $X ), ? is_hex (A ), ? is_hex (B ) ->
188
190
Char = escape_char ([$\\ ,P ,A ,B ]),
189
191
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
190
192
191
- tokenize ([$? ,$\\ ,P ,A |T ], Line , Scope , Tokens ) when (P == $x orelse P == $X ), ? is_hex (A ) ->
193
+ tokenize ([$? ,$\\ ,P ,A |T ], Line , Scope , Tokens )
194
+ when (P == $x orelse P == $X ), ? is_hex (A ) ->
192
195
Char = escape_char ([$\\ ,P ,A ]),
193
196
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
194
197
195
- tokenize ([$? ,$\\ ,A ,B ,C |T ], Line , Scope , Tokens ) when ? is_octal (A ), A =< $3 ,? is_octal (B ), ? is_octal (C ) ->
198
+ tokenize ([$? ,$\\ ,A ,B ,C |T ], Line , Scope , Tokens )
199
+ when ? is_octal (A ), A =< $3 ,? is_octal (B ), ? is_octal (C ) ->
196
200
Char = escape_char ([$\\ ,A ,B ,C ]),
197
201
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
198
202
199
- tokenize ([$? ,$\\ ,A ,B |T ], Line , Scope , Tokens ) when ? is_octal (A ), ? is_octal (B ) ->
203
+ tokenize ([$? ,$\\ ,A ,B |T ], Line , Scope , Tokens )
204
+ when ? is_octal (A ), ? is_octal (B ) ->
200
205
Char = escape_char ([$\\ ,A ,B ]),
201
206
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
202
207
203
- tokenize ([$? ,$\\ ,A |T ], Line , Scope , Tokens ) when ? is_octal (A ) ->
208
+ tokenize ([$? ,$\\ ,A |T ], Line , Scope , Tokens )
209
+ when ? is_octal (A ) ->
204
210
Char = escape_char ([$\\ ,A ]),
205
211
tokenize (T , Line , Scope , [{number , Line , Char }|Tokens ]);
206
212
@@ -257,8 +263,8 @@ tokenize(":%{}" ++ Rest, Line, Scope, Tokens) ->
257
263
tokenize (Rest , Line , Scope , [{atom , Line , '%{}' }|Tokens ]);
258
264
tokenize (" :%" ++ Rest , Line , Scope , Tokens ) ->
259
265
tokenize (Rest , Line , Scope , [{atom , Line , '%' }|Tokens ]);
260
- tokenize ([ $: , T1 , T2 | Rest ] , Line , Scope , Tokens ) when ? container ( T1 , T2 ) ->
261
- tokenize (Rest , Line , Scope , [{atom , Line , list_to_atom ([ T1 , T2 ]) }|Tokens ]);
266
+ tokenize (" :{} " ++ Rest , Line , Scope , Tokens ) ->
267
+ tokenize (Rest , Line , Scope , [{atom , Line , '{}' }|Tokens ]);
262
268
263
269
tokenize (" ...:" ++ Rest , Line , Scope , Tokens ) when ? is_space (hd (Rest )) ->
264
270
tokenize (Rest , Line , Scope , [{kw_identifier , Line , '...' }|Tokens ]);
@@ -268,8 +274,8 @@ tokenize("%{}:" ++ Rest, Line, Scope, Tokens) when ?is_space(hd(Rest)) ->
268
274
tokenize (Rest , Line , Scope , [{kw_identifier , Line , '%{}' }|Tokens ]);
269
275
tokenize (" %:" ++ Rest , Line , Scope , Tokens ) when ? is_space (hd (Rest )) ->
270
276
tokenize (Rest , Line , Scope , [{kw_identifier , Line , '%' }|Tokens ]);
271
- tokenize ([ T1 , T2 , $: | Rest ] , Line , Scope , Tokens ) when ? container ( T1 , T2 ), ? is_space (hd (Rest )) ->
272
- tokenize (Rest , Line , Scope , [{kw_identifier , Line , list_to_atom ([ T1 , T2 ]) }|Tokens ]);
277
+ tokenize (" {}: " ++ Rest , Line , Scope , Tokens ) when ? is_space (hd (Rest )) ->
278
+ tokenize (Rest , Line , Scope , [{kw_identifier , Line , '{}' }|Tokens ]);
273
279
274
280
% ## Three Token Operators
275
281
tokenize ([$: ,T1 ,T2 ,T3 |Rest ], Line , Scope , Tokens ) when
@@ -315,6 +321,9 @@ tokenize("..." ++ Rest, Line, Scope, Tokens) ->
315
321
Token = check_call_identifier (identifier , Line , '...' , Rest ),
316
322
tokenize (Rest , Line , Scope , [Token |Tokens ]);
317
323
324
+ tokenize (" =>" ++ Rest , Line , Scope , Tokens ) ->
325
+ tokenize (Rest , Line , Scope , add_token_with_nl ({assoc_op , Line , '=>' }, Tokens ));
326
+
318
327
% ## Three token operators
319
328
tokenize ([T1 ,T2 ,T3 |Rest ], Line , Scope , Tokens ) when ? unary_op3 (T1 , T2 , T3 ) ->
320
329
handle_unary_op (Rest , Line , unary_op , list_to_atom ([T1 ,T2 ,T3 ]), Scope , Tokens );
@@ -344,9 +353,6 @@ tokenize([T|Rest], Line, Scope, Tokens) when T == $(;
344
353
Token = {list_to_atom ([T ]), Line },
345
354
handle_terminator (Rest , Line , Scope , Token , Tokens );
346
355
347
- tokenize (" =>" ++ Rest , Line , Scope , Tokens ) ->
348
- tokenize (Rest , Line , Scope , add_token_with_nl ({assoc_op , Line , '=>' }, Tokens ));
349
-
350
356
% ## Two Token Operators
351
357
tokenize ([T1 ,T2 |Rest ], Line , Scope , Tokens ) when ? two_op (T1 , T2 ) ->
352
358
handle_op (Rest , Line , two_op , list_to_atom ([T1 , T2 ]), Scope , Tokens );
@@ -537,7 +543,7 @@ handle_dot([$.,T1,T2|Rest], Line, Scope, Tokens) when
537
543
% ## Single Token Operators
538
544
handle_dot ([$. ,T |Rest ], Line , Scope , Tokens ) when
539
545
? at_op (T ); ? unary_op (T ); ? dual_op (T ); ? mult_op (T ); ? comp_op (T );
540
- ? match_op (T ); ? pipe_op (T ) ->
546
+ ? match_op (T ); ? pipe_op (T ); T == $% ->
541
547
handle_call_identifier (Rest , Line , list_to_atom ([T ]), Scope , Tokens );
542
548
543
549
% ## Exception for .( as it needs to be treated specially in the parser
0 commit comments