@@ -394,13 +394,15 @@ tokenize([H|_] = String, Line, Scope, Tokens) when ?is_upcase(H) ->
394
394
tokenize ([H |_ ] = String , Line , Scope , Tokens ) when ? is_downcase (H ); H == $_ ->
395
395
{ Rest , { Kind , _ , Identifier } } = tokenize_any_identifier (String , Line , [], Scope ),
396
396
case handle_keyword (Line , Kind , Identifier , Tokens ) of
397
- false ->
397
+ nomatch ->
398
398
tokenize (Rest , Line , Scope , [{ Kind , Line , Identifier }|Tokens ]);
399
- [Check |T ] ->
399
+ { ok , [Check |T ] } ->
400
400
case handle_terminator (Check , Scope ) of
401
401
{ error , _ } = Error -> Error ;
402
402
New -> tokenize (Rest , Line , New , [Check |T ])
403
- end
403
+ end ;
404
+ { error , Token } ->
405
+ { error , { Line , " syntax error before: " , Token } }
404
406
end ;
405
407
406
408
% Ambiguous unary/binary operators tokens
@@ -807,29 +809,40 @@ terminator('<<') -> '>>'.
807
809
808
810
% Keywords check
809
811
handle_keyword (Line , Identifier , Atom , [{ '.' , _ }|_ ] = Tokens ) ->
810
- [{ Identifier , Line , Atom }|Tokens ];
812
+ { ok , [{ Identifier , Line , Atom }|Tokens ] } ;
811
813
812
814
handle_keyword (Line , Identifier , Atom , Tokens ) when
813
815
Identifier == identifier ; Identifier == do_identifier ;
814
816
Identifier == bracket_identifier ; Identifier == paren_identifier ->
815
817
case keyword (Atom ) of
816
- true -> [{ Atom , Line }|Tokens ];
817
- op -> add_token_with_nl ({ Atom , Line }, Tokens );
818
- block -> [{ block_identifier , Line , Atom }|Tokens ];
819
- false -> false
818
+ true -> { ok , [{ Atom , Line }|Tokens ] };
819
+ op -> { ok , add_token_with_nl ({ Atom , Line }, Tokens ) };
820
+ block -> { ok , [{ block_identifier , Line , Atom }|Tokens ] };
821
+ do ->
822
+ case do_keyword_valid (Tokens ) of
823
+ true -> { ok , [{ Atom , Line }|Tokens ] };
824
+ false -> { error , " do" }
825
+ end ;
826
+ false -> nomatch
820
827
end ;
821
828
822
- handle_keyword (_ , _ , _ , _ ) -> false .
829
+ handle_keyword (_ , _ , _ , _ ) -> nomatch .
830
+
831
+ do_keyword_valid ([{ Atom , _ }|_ ]) ->
832
+ is_boolean (keyword (Atom ));
833
+ do_keyword_valid (_ ) -> true .
823
834
824
835
% Keywords
825
836
keyword ('fn' ) -> true ;
826
- keyword ('do' ) -> true ;
827
837
keyword ('end' ) -> true ;
828
838
keyword ('true' ) -> true ;
829
839
keyword ('false' ) -> true ;
830
840
keyword ('nil' ) -> true ;
831
841
keyword ('not' ) -> true ;
832
842
843
+ % Special handling for do
844
+ keyword ('do' ) -> do ;
845
+
833
846
% Bin operator keywords
834
847
keyword ('and' ) -> op ;
835
848
keyword ('or' ) -> op ;
0 commit comments