@@ -9,72 +9,78 @@ unescape_tokens/1, unescape_map/1]).
9
9
10
10
% % Extract string interpolations
11
11
12
- extract (Line , Column , Raw , Interpol , String , Last ) ->
13
- % % Ignore whatever is in the scope and enable terminator checking.
14
- Scope = Raw # elixir_tokenizer {terminators = []},
15
- extract (Line , Column , Scope , Interpol , String , [], [], Last ).
12
+ extract (Line , Column , Scope , Interpol , String , Last ) ->
13
+ extract (String , [], [], Line , Column , Scope , Interpol , Last ).
16
14
17
15
% % Terminators
18
16
19
- extract (Line , Column , _Scope , _Interpol , [], _Buffer , _Output , Last ) ->
17
+ extract ([], _Buffer , _Output , Line , Column , # elixir_tokenizer { cursor_completion = false }, _Interpol , Last ) ->
20
18
{error , {string , Line , Column , io_lib :format (" missing terminator: ~ts " , [[Last ]]), []}};
21
19
22
- extract (Line , Column , _Scope , _Interpol , [Last | Rest ], Buffer , Output , Last ) ->
23
- finish_extraction (Line , Column + 1 , Buffer , Output , Rest );
20
+ extract ([], Buffer , Output , Line , Column , Scope , _Interpol , _Last ) ->
21
+ finish_extraction ([], Buffer , Output , Line , Column , Scope );
22
+
23
+ extract ([Last | Rest ], Buffer , Output , Line , Column , Scope , _Interpol , Last ) ->
24
+ finish_extraction (Rest , Buffer , Output , Line , Column + 1 , Scope );
24
25
25
26
% % Going through the string
26
27
27
- extract (Line , _Column , Scope , Interpol , [$\\ , $\r , $\n | Rest ], Buffer , Output , Last ) ->
28
- extract_nl (Line , Scope , Interpol , Rest , [$\n , $\r , $\\ | Buffer ], Output , Last );
28
+ extract ([$\\ , $\r , $\n | Rest ], Buffer , Output , Line , _Column , Scope , Interpol , Last ) ->
29
+ extract_nl (Rest , [$\n , $\r , $\\ | Buffer ], Output , Line , Scope , Interpol , Last );
29
30
30
- extract (Line , _Column , Scope , Interpol , [$\\ , $\n | Rest ], Buffer , Output , Last ) ->
31
- extract_nl (Line , Scope , Interpol , Rest , [$\n , $\\ | Buffer ], Output , Last );
31
+ extract ([$\\ , $\n | Rest ], Buffer , Output , Line , _Column , Scope , Interpol , Last ) ->
32
+ extract_nl (Rest , [$\n , $\\ | Buffer ], Output , Line , Scope , Interpol , Last );
32
33
33
- extract (Line , _Column , Scope , Interpol , [$\n | Rest ], Buffer , Output , Last ) ->
34
- extract_nl (Line , Scope , Interpol , Rest , [$\n | Buffer ], Output , Last );
34
+ extract ([$\n | Rest ], Buffer , Output , Line , _Column , Scope , Interpol , Last ) ->
35
+ extract_nl (Rest , [$\n | Buffer ], Output , Line , Scope , Interpol , Last );
35
36
36
- extract (Line , Column , Scope , Interpol , [$\\ , Last | Rest ], Buffer , Output , Last ) ->
37
- extract (Line , Column + 2 , Scope , Interpol , Rest , [Last | Buffer ], Output , Last );
37
+ extract ([$\\ , Last | Rest ], Buffer , Output , Line , Column , Scope , Interpol , Last ) ->
38
+ extract (Rest , [Last | Buffer ], Output , Line , Column + 2 , Scope , Interpol , Last );
38
39
39
- extract (Line , Column , Scope , true , [$\\ , $# , ${ | Rest ], Buffer , Output , Last ) ->
40
- extract (Line , Column + 1 , Scope , true , Rest , [${ , $# , $\\ | Buffer ], Output , Last );
40
+ extract ([$\\ , $# , ${ | Rest ], Buffer , Output , Line , Column , Scope , true , Last ) ->
41
+ extract (Rest , [${ , $# , $\\ | Buffer ], Output , Line , Column + 1 , Scope , true , Last );
41
42
42
- extract (Line , Column , Scope , true , [$# , ${ | Rest ], Buffer , Output , Last ) ->
43
- Output1 = build_string (Line , Buffer , Output ),
44
- case elixir_tokenizer :tokenize (Rest , Line , Column + 2 , Scope ) of
45
- {error , {EndLine , EndColumn , _ , " }" }, [$} | NewRest ], Tokens } ->
46
- Output2 = build_interpol (Line , Column , EndLine , EndColumn , Tokens , Output1 ),
47
- extract (EndLine , EndColumn + 1 , Scope , true , NewRest , [], Output2 , Last );
48
- {error , Reason , _ , _ } ->
43
+ extract ([$# , ${ | Rest ], Buffer , Output , Line , Column , Scope , true , Last ) ->
44
+ Output1 = build_string (Buffer , Output ),
45
+ case elixir_tokenizer :tokenize (Rest , Line , Column + 2 , Scope # elixir_tokenizer {terminators = []}) of
46
+ {error , {EndLine , EndColumn , _ , " }" }, [$} | NewRest ], Warnings , Tokens } ->
47
+ NewScope = Scope # elixir_tokenizer {warnings = Warnings },
48
+ Output2 = build_interpol (Line , Column , EndLine , EndColumn , lists :reverse (Tokens ), Output1 ),
49
+ extract (NewRest , [], Output2 , EndLine , EndColumn + 1 , NewScope , true , Last );
50
+ {error , Reason , _ , _ , _ } ->
49
51
{error , Reason };
50
- {ok , _ , _ } ->
52
+ {ok , EndLine , EndColumn , Warnings , Tokens } when Scope # elixir_tokenizer .cursor_completion /= false ->
53
+ NewScope = Scope # elixir_tokenizer {warnings = Warnings , cursor_completion = terminators },
54
+ Output2 = build_interpol (Line , Column , EndLine , EndColumn , Tokens , Output1 ),
55
+ extract ([], [], Output2 , EndLine , EndColumn , NewScope , true , Last );
56
+ {ok , _ , _ , _ , _ } ->
51
57
{error , {string , Line , Column , " missing interpolation terminator: \" }\" " , []}}
52
58
end ;
53
59
54
- extract (Line , Column , Scope , Interpol , [$\\ , Char | Rest ], Buffer , Output , Last ) ->
55
- extract (Line , Column + 2 , Scope , Interpol , Rest , [Char , $\\ | Buffer ], Output , Last );
60
+ extract ([$\\ , Char | Rest ], Buffer , Output , Line , Column , Scope , Interpol , Last ) ->
61
+ extract (Rest , [Char , $\\ | Buffer ], Output , Line , Column + 2 , Scope , Interpol , Last );
56
62
57
63
% % Catch all clause
58
64
59
- extract (Line , Column , Scope , Interpol , [Char1 , Char2 | Rest ], Buffer , Output , Last )
65
+ extract ([Char1 , Char2 | Rest ], Buffer , Output , Line , Column , Scope , Interpol , Last )
60
66
when Char1 =< 255 , Char2 =< 255 ->
61
- extract (Line , Column + 1 , Scope , Interpol , [Char2 | Rest ], [Char1 | Buffer ], Output , Last );
67
+ extract ([Char2 | Rest ], [Char1 | Buffer ], Output , Line , Column + 1 , Scope , Interpol , Last );
62
68
63
- extract (Line , Column , Scope , Interpol , Rest , Buffer , Output , Last ) ->
69
+ extract (Rest , Buffer , Output , Line , Column , Scope , Interpol , Last ) ->
64
70
[Char | NewRest ] = unicode_util :gc (Rest ),
65
- extract (Line , Column + 1 , Scope , Interpol , NewRest , [ Char | Buffer ], Output , Last ).
71
+ extract (NewRest , [ Char | Buffer ], Output , Line , Column + 1 , Scope , Interpol , Last ).
66
72
67
73
% % Handle newlines. Heredocs require special attention
68
74
69
- extract_nl (Line , Scope , Interpol , Rest , Buffer , Output , [H ,H ,H ] = Last ) ->
75
+ extract_nl (Rest , Buffer , Output , Line , Scope , Interpol , [H ,H ,H ] = Last ) ->
70
76
case strip_horizontal_space (Rest , Buffer , 1 ) of
71
77
{[H ,H ,H |NewRest ], _NewBuffer , Column } ->
72
- finish_extraction (Line + 1 , Column + 3 , Buffer , Output , NewRest );
78
+ finish_extraction (NewRest , Buffer , Output , Line + 1 , Column + 3 , Scope );
73
79
{NewRest , NewBuffer , Column } ->
74
- extract (Line + 1 , Column , Scope , Interpol , NewRest , NewBuffer , Output , Last )
80
+ extract (NewRest , NewBuffer , Output , Line + 1 , Column , Scope , Interpol , Last )
75
81
end ;
76
- extract_nl (Line , Scope , Interpol , Rest , Buffer , Output , Last ) ->
77
- extract (Line + 1 , 1 , Scope , Interpol , Rest , Buffer , Output , Last ).
82
+ extract_nl (Rest , Buffer , Output , Line , Scope , Interpol , Last ) ->
83
+ extract (Rest , Buffer , Output , Line + 1 , 1 , Scope , Interpol , Last ).
78
84
79
85
strip_horizontal_space ([H | T ], Buffer , Counter ) when H =:= $\s ; H =:= $\t ->
80
86
strip_horizontal_space (T , [H | Buffer ], Counter + 1 );
@@ -243,16 +249,16 @@ unescape_map(E) -> E.
243
249
244
250
% Extract Helpers
245
251
246
- finish_extraction (Line , Column , Buffer , Output , Remaining ) ->
247
- Final = case build_string (Line , Buffer , Output ) of
252
+ finish_extraction (Remaining , Buffer , Output , Line , Column , Scope ) ->
253
+ Final = case build_string (Buffer , Output ) of
248
254
[] -> [[]];
249
255
F -> F
250
256
end ,
251
257
252
- {Line , Column , lists :reverse (Final ), Remaining }.
258
+ {Line , Column , lists :reverse (Final ), Remaining , Scope }.
253
259
254
- build_string (_Line , [], Output ) -> Output ;
255
- build_string (_Line , Buffer , Output ) -> [lists :reverse (Buffer ) | Output ].
260
+ build_string ([], Output ) -> Output ;
261
+ build_string (Buffer , Output ) -> [lists :reverse (Buffer ) | Output ].
256
262
257
263
build_interpol (Line , Column , EndLine , EndColumn , Buffer , Output ) ->
258
- [{{Line , Column , nil }, {EndLine , EndColumn , nil }, lists : reverse ( Buffer ) } | Output ].
264
+ [{{Line , Column , nil }, {EndLine , EndColumn , nil }, Buffer } | Output ].
0 commit comments