@@ -1550,7 +1550,7 @@ tokenize_sigil_name([S | T], NameAcc, Line, Column, Scope, Tokens) when ?is_upca
1550
1550
tokenize_sigil_name (T , [S | NameAcc ], Line , Column + 1 , Scope , Tokens );
1551
1551
% With a lowercase letter and a non-empty NameAcc we return an error.
1552
1552
tokenize_sigil_name ([S | _T ] = Original , [_ | _ ] = NameAcc , _Line , _Column , _Scope , _Tokens ) when ? is_downcase (S ) ->
1553
- Message = " invalid sigil name, it should be either a one-letter lowercase letter or a" ++
1553
+ Message = " invalid sigil name, it should be either a one-letter lowercase letter or a" ++
1554
1554
" sequence of uppercase letters only, got: " ,
1555
1555
{error , Message , [$~ ] ++ lists :reverse (NameAcc ) ++ Original };
1556
1556
% We finished the letters, so the name is over.
@@ -1561,12 +1561,8 @@ tokenize_sigil_contents([H, H, H | T] = Original, [S | _] = SigilName, Line, Col
1561
1561
when ? is_quote (H ) ->
1562
1562
case extract_heredoc_with_interpolation (Line , Column , Scope , ? is_downcase (S ), T , H ) of
1563
1563
{ok , NewLine , NewColumn , Parts , Rest , NewScope } ->
1564
- {Final , Modifiers } = collect_modifiers (Rest , []),
1565
1564
Indentation = NewColumn - 4 ,
1566
- TokenColumn = Column - 1 - length (SigilName ),
1567
- Token = {sigil , {Line , TokenColumn , nil }, SigilName , Parts , Modifiers , Indentation , <<H , H , H >>},
1568
- NewColumnWithModifiers = NewColumn + length (Modifiers ),
1569
- tokenize (Final , NewLine , NewColumnWithModifiers , NewScope , [Token | Tokens ]);
1565
+ add_sigil_token (SigilName , Line , Column , NewLine , NewColumn , Parts , Rest , NewScope , Tokens , Indentation , <<H , H , H >>);
1570
1566
1571
1567
{error , Reason } ->
1572
1568
error (Reason , [$~ ] ++ SigilName ++ Original , Scope , Tokens )
@@ -1576,12 +1572,8 @@ tokenize_sigil_contents([H | T] = Original, [S | _] = SigilName, Line, Column, S
1576
1572
when ? is_sigil (H ) ->
1577
1573
case elixir_interpolation :extract (Line , Column + 1 , Scope , ? is_downcase (S ), T , sigil_terminator (H )) of
1578
1574
{NewLine , NewColumn , Parts , Rest , NewScope } ->
1579
- {Final , Modifiers } = collect_modifiers (Rest , []),
1580
1575
Indentation = nil ,
1581
- TokenColumn = Column - 1 - length (SigilName ),
1582
- Token = {sigil , {Line , TokenColumn , nil }, SigilName , tokens_to_binary (Parts ), Modifiers , Indentation , <<H >>},
1583
- NewColumnWithModifiers = NewColumn + length (Modifiers ),
1584
- tokenize (Final , NewLine , NewColumnWithModifiers , NewScope , [Token | Tokens ]);
1576
+ add_sigil_token (SigilName , Line , Column , NewLine , NewColumn , tokens_to_binary (Parts ), Rest , NewScope , Tokens , Indentation , <<H >>);
1585
1577
1586
1578
{error , Reason } ->
1587
1579
Sigil = [$~ , S , H ],
@@ -1601,6 +1593,24 @@ tokenize_sigil_contents([H | _] = Original, SigilName, Line, Column, Scope, Toke
1601
1593
tokenize_sigil_contents ([], _SigilName , Line , Column , Scope , Tokens ) ->
1602
1594
tokenize ([], Line , Column , Scope , Tokens ).
1603
1595
1596
+ add_sigil_token (SigilName , Line , Column , NewLine , NewColumn , Parts , Rest , Scope , Tokens , Indentation , Delimiter ) ->
1597
+ TokenColumn = Column - 1 - length (SigilName ),
1598
+ MaybeEncoded = case SigilName of
1599
+ % Single-letter sigils present no risk of atom exhaustion (limited possibilities)
1600
+ [_Char ] -> {ok , list_to_atom (" sigil_" ++ SigilName )};
1601
+ _ -> unsafe_to_atom (" sigil_" ++ SigilName , Line , TokenColumn , Scope )
1602
+ end ,
1603
+ case MaybeEncoded of
1604
+ {ok , Atom } ->
1605
+ {Final , Modifiers } = collect_modifiers (Rest , []),
1606
+ Token = {sigil , {Line , TokenColumn , nil }, Atom , Parts , Modifiers , Indentation , Delimiter },
1607
+ NewColumnWithModifiers = NewColumn + length (Modifiers ),
1608
+ tokenize (Final , NewLine , NewColumnWithModifiers , Scope , [Token | Tokens ]);
1609
+
1610
+ {error , Reason } ->
1611
+ error (Reason , Rest , Scope , Tokens )
1612
+ end .
1613
+
1604
1614
% % Fail early on invalid do syntax. For example, after
1605
1615
% % most keywords, after comma and so on.
1606
1616
tokenize_keyword_terminator (DoLine , DoColumn , do , [{identifier , {Line , Column , Meta }, Atom } | T ]) ->
0 commit comments