@@ -701,7 +701,7 @@ handle_literal(Literal, Token, ExtraMeta) ->
701
701
{ok , EncodedLiteral } ->
702
702
EncodedLiteral ;
703
703
{error , Reason } ->
704
- return_error (Meta , elixir_utils :characters_to_list (Reason ) ++ [" : " ], " literal" )
704
+ return_error (? location ( Token ) , elixir_utils :characters_to_list (Reason ) ++ [" : " ], " literal" )
705
705
end
706
706
end .
707
707
@@ -725,7 +725,7 @@ build_op(AST, {_Kind, Location, '//'}, Right) ->
725
725
{'..//' , Meta , [Left , Middle , Right ]};
726
726
727
727
_ ->
728
- return_error (meta_from_location ( Location ) , " the range step operator (//) must immediately follow the range definition operator (..), for example: 1..9//2. If you wanted to define a default argument, use (\\\\ ) instead. Syntax error before: " , " '//'" )
728
+ return_error (Location , " the range step operator (//) must immediately follow the range definition operator (..), for example: 1..9//2. If you wanted to define a default argument, use (\\\\ ) instead. Syntax error before: " , " '//'" )
729
729
end ;
730
730
731
731
build_op ({UOp , _ , [Left ]}, {_Kind , Location , 'in' }, Right ) when ? rearrange_uop (UOp ) ->
@@ -917,7 +917,7 @@ build_fn(Fn, Stab, End) ->
917
917
Meta = newlines_op (? location (Fn )) ++ meta_from_token_with_closing (Fn , End ),
918
918
{fn , Meta , collect_stab (Stab , [], [])};
919
919
block ->
920
- return_error (meta_from_token (Fn ), " expected anonymous functions to be defined with -> inside: " , " 'fn'" )
920
+ return_error (? location (Fn ), " expected anonymous functions to be defined with -> inside: " , " 'fn'" )
921
921
end .
922
922
923
923
% % Access
@@ -1090,23 +1090,28 @@ unwrap_when(Args) ->
1090
1090
1091
1091
% % Warnings and errors
1092
1092
1093
- return_error (Meta , Error , Token ) ->
1094
- return_error (Meta , [Error , Token ]).
1093
+ return_error ({Line , Column , _ }, ErrorMessage , ErrorToken ) ->
1094
+ return_error ([{line , Line }, {column , Column }], [ErrorMessage , ErrorToken ]).
1095
+
1096
+ % % We should prefer to use return_error as it includes
1097
+ % % Line and Column but that's not always possible.
1098
+ return_error_with_meta (Meta , ErrorMessage , ErrorToken ) ->
1099
+ return_error (Meta , [ErrorMessage , ErrorToken ]).
1095
1100
1096
1101
error_invalid_stab (MetaStab ) ->
1097
- return_error (MetaStab ,
1102
+ return_error_with_meta (MetaStab ,
1098
1103
" unexpected operator ->. If you want to define multiple clauses, the first expression must use ->. "
1099
1104
" Syntax error before: " , " '->'" ).
1100
1105
1101
1106
error_bad_atom (Token ) ->
1102
- return_error (meta_from_token (Token ), " atom cannot be followed by an alias. "
1107
+ return_error (? location (Token ), " atom cannot be followed by an alias. "
1103
1108
" If the '.' was meant to be part of the atom's name, "
1104
1109
" the atom name must be quoted. Syntax error before: " , " '.'" ).
1105
1110
1106
1111
maybe_bad_keyword_call_follow_up (_Token , KW , {'__cursor__' , _ , []} = Expr ) ->
1107
1112
reverse ([Expr | KW ]);
1108
1113
maybe_bad_keyword_call_follow_up (Token , _KW , _Expr ) ->
1109
- return_error (meta_from_token (Token ),
1114
+ return_error (? location (Token ),
1110
1115
" unexpected expression after keyword list. Keyword lists must always come as the last argument. Therefore, this is not allowed:\n\n "
1111
1116
" function_call(1, some: :option, 2)\n\n "
1112
1117
" Instead, wrap the keyword in brackets:\n\n "
@@ -1116,7 +1121,7 @@ maybe_bad_keyword_call_follow_up(Token, _KW, _Expr) ->
1116
1121
maybe_bad_keyword_data_follow_up (_Token , KW , {'__cursor__' , _ , []} = Expr ) ->
1117
1122
reverse ([Expr | KW ]);
1118
1123
maybe_bad_keyword_data_follow_up (Token , _KW , _Expr ) ->
1119
- return_error (meta_from_token (Token ),
1124
+ return_error (? location (Token ),
1120
1125
" unexpected expression after keyword list. Keyword lists must always come last in lists and maps. Therefore, this is not allowed:\n\n "
1121
1126
" [some: :value, :another]\n "
1122
1127
" %{some: :value, another => value}\n\n "
@@ -1126,12 +1131,12 @@ maybe_bad_keyword_data_follow_up(Token, _KW, _Expr) ->
1126
1131
" Syntax error after: " , " ','" ).
1127
1132
1128
1133
error_no_parens_strict (Token ) ->
1129
- return_error (meta_from_token (Token ), " unexpected parentheses. If you are making a "
1134
+ return_error (? location (Token ), " unexpected parentheses. If you are making a "
1130
1135
" function call, do not insert spaces between the function name and the "
1131
1136
" opening parentheses. Syntax error before: " , " '('" ).
1132
1137
1133
1138
error_no_parens_many_strict (Node ) ->
1134
- return_error (? meta (Node ),
1139
+ return_error_with_meta (? meta (Node ),
1135
1140
" unexpected comma. Parentheses are required to solve ambiguity in nested calls.\n\n "
1136
1141
" This error happens when you have nested function calls without parentheses. "
1137
1142
" For example:\n\n "
@@ -1145,7 +1150,7 @@ error_no_parens_many_strict(Node) ->
1145
1150
" Elixir cannot compile otherwise. Syntax error before: " , " ','" ).
1146
1151
1147
1152
error_no_parens_container_strict (Node ) ->
1148
- return_error (? meta (Node ),
1153
+ return_error_with_meta (? meta (Node ),
1149
1154
" unexpected comma. Parentheses are required to solve ambiguity inside containers.\n\n "
1150
1155
" This error may happen when you forget a comma in a list or other container:\n\n "
1151
1156
" [a, b c, d]\n\n "
@@ -1157,10 +1162,10 @@ error_no_parens_container_strict(Node) ->
1157
1162
" [one, two(three, four), five]\n\n "
1158
1163
" Elixir cannot compile otherwise. Syntax error before: " , " ','" ).
1159
1164
1160
- error_invalid_kw_identifier ({_ , _ , do } = Token ) ->
1161
- return_error (meta_from_token ( Token ) , elixir_tokenizer :invalid_do_error (" unexpected keyword: " ), " do:" );
1162
- error_invalid_kw_identifier ({_ , _ , KW } = Token ) ->
1163
- return_error (meta_from_token ( Token ) , " syntax error before: " , " '" ++ atom_to_list (KW ) ++ " :'" ).
1165
+ error_invalid_kw_identifier ({_ , Location , do }) ->
1166
+ return_error (Location , elixir_tokenizer :invalid_do_error (" unexpected keyword: " ), " do:" );
1167
+ error_invalid_kw_identifier ({_ , Location , KW }) ->
1168
+ return_error (Location , " syntax error before: " , " '" ++ atom_to_list (KW ) ++ " :'" ).
1164
1169
1165
1170
% % TODO: Make this an error on v2.0
1166
1171
warn_empty_paren ({_ , {Line , _ , _ }}) ->
0 commit comments