@@ -551,8 +551,10 @@ tokenize([$: | String] = Original, Line, Column, Scope, Tokens) ->
551551 NewScope = maybe_warn_for_ambiguous_bang_before_equals (atom , Unencoded , Rest , Line , Column , Scope ),
552552 Token = {atom , {Line , Column , nil }, Atom },
553553 tokenize (Rest , Line , Column + 1 + Length , NewScope , [Token | Tokens ]);
554- empty ->
554+ empty when Scope # elixir_tokenizer . cursor_completion == false ->
555555 unexpected_token (Original , Line , Column , Scope , Tokens );
556+ empty ->
557+ tokenize ([], Line , Column , Scope , Tokens );
556558 {error , Reason } ->
557559 error (Reason , Original , Scope , Tokens )
558560 end ;
@@ -565,17 +567,24 @@ tokenize([H | T], Line, Column, Scope, Tokens) when ?is_digit(H) ->
565567 case tokenize_number (T , [H ], 1 , false ) of
566568 {error , Reason , Original } ->
567569 error ({Line , Column , Reason , Original }, T , Scope , Tokens );
568- {[I | _ ], _Number , Original , _Length } when ? is_upcase (I ); ? is_downcase (I ); I == $_ ->
569- Msg =
570- io_lib :format (
571- " invalid character ~ts after number ~ts . If you intended to write a number, "
572- " make sure to add the proper punctuation character after the number (space, comma, etc). "
573- " If you meant to write an identifier, note that identifiers in Elixir cannot start with numbers. "
574- " Unexpected token: " ,
575- [[I ], Original ]
576- ),
577-
578- error ({Line , Column , Msg , [I ]}, T , Scope , Tokens );
570+ {[I | Rest ], Number , Original , _Length } when ? is_upcase (I ); ? is_downcase (I ); I == $_ ->
571+ if
572+ Number == 0 , (I =:= $x ) orelse (I =:= $o ) orelse (I =:= $b ), Rest == [],
573+ Scope # elixir_tokenizer .cursor_completion /= false ->
574+ tokenize ([], Line , Column , Scope , Tokens );
575+
576+ true ->
577+ Msg =
578+ io_lib :format (
579+ " invalid character ~ts after number ~ts . If you intended to write a number, "
580+ " make sure to add the proper punctuation character after the number (space, comma, etc). "
581+ " If you meant to write an identifier, note that identifiers in Elixir cannot start with numbers. "
582+ " Unexpected token: " ,
583+ [[I ], Original ]
584+ ),
585+
586+ error ({Line , Column , Msg , [I ]}, T , Scope , Tokens )
587+ end ;
579588 {Rest , Number , Original , Length } when is_integer (Number ) ->
580589 Token = {int , {Line , Column , Number }, Original },
581590 tokenize (Rest , Line , Column + Length , Scope , [Token | Tokens ]);
@@ -679,9 +688,16 @@ tokenize(String, Line, Column, Scope, Tokens) ->
679688 {keyword , Atom , Type , Rest , Length } ->
680689 tokenize_keyword (Type , Rest , Line , Column , Atom , Length , Scope , Tokens );
681690
682- empty ->
691+ empty when Scope # elixir_tokenizer . cursor_completion == false ->
683692 unexpected_token (String , Line , Column , Scope , Tokens );
684693
694+ empty ->
695+ case String of
696+ [$~ , L ] when ? is_upcase (L ); ? is_downcase (L ) -> tokenize ([], Line , Column , Scope , Tokens );
697+ [$~ ] -> tokenize ([], Line , Column , Scope , Tokens );
698+ _ -> unexpected_token (String , Line , Column , Scope , Tokens )
699+ end ;
700+
685701 {error , Reason } ->
686702 error (Reason , String , Scope , Tokens )
687703 end .
0 commit comments