@@ -1550,7 +1550,7 @@ tokenize_sigil_name([S | T], NameAcc, Line, Column, Scope, Tokens) when ?is_upca
15501550 tokenize_sigil_name (T , [S | NameAcc ], Line , Column + 1 , Scope , Tokens );
15511551% With a lowercase letter and a non-empty NameAcc we return an error.
15521552tokenize_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" ++
15541554 " sequence of uppercase letters only, got: " ,
15551555 {error , Message , [$~ ] ++ lists :reverse (NameAcc ) ++ Original };
15561556% 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
15611561 when ? is_quote (H ) ->
15621562 case extract_heredoc_with_interpolation (Line , Column , Scope , ? is_downcase (S ), T , H ) of
15631563 {ok , NewLine , NewColumn , Parts , Rest , NewScope } ->
1564- {Final , Modifiers } = collect_modifiers (Rest , []),
15651564 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 >>);
15701566
15711567 {error , Reason } ->
15721568 error (Reason , [$~ ] ++ SigilName ++ Original , Scope , Tokens )
@@ -1576,12 +1572,8 @@ tokenize_sigil_contents([H | T] = Original, [S | _] = SigilName, Line, Column, S
15761572 when ? is_sigil (H ) ->
15771573 case elixir_interpolation :extract (Line , Column + 1 , Scope , ? is_downcase (S ), T , sigil_terminator (H )) of
15781574 {NewLine , NewColumn , Parts , Rest , NewScope } ->
1579- {Final , Modifiers } = collect_modifiers (Rest , []),
15801575 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 >>);
15851577
15861578 {error , Reason } ->
15871579 Sigil = [$~ , S , H ],
@@ -1601,6 +1593,24 @@ tokenize_sigil_contents([H | _] = Original, SigilName, Line, Column, Scope, Toke
16011593tokenize_sigil_contents ([], _SigilName , Line , Column , Scope , Tokens ) ->
16021594 tokenize ([], Line , Column , Scope , Tokens ).
16031595
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+
16041614% % Fail early on invalid do syntax. For example, after
16051615% % most keywords, after comma and so on.
16061616tokenize_keyword_terminator (DoLine , DoColumn , do , [{identifier , {Line , Column , Meta }, Atom } | T ]) ->
0 commit comments