Skip to content

Commit

Permalink
Ensure parser always returns erl_anno:location() in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gomoripeti committed Nov 26, 2021
1 parent ae1c256 commit b86e6ee
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/erlfmt_parse.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ Erlang code.

%% XXX. To be refined.
-type error_description() :: term().
-type error_info() :: {erl_anno:line(), module(), error_description()}.
-type error_info() :: {erl_anno:location(), module(), error_description()}.
-type token() :: erlfmt_scan:token().

%% mkop(Op, Arg) -> {op,Anno,Op,Arg}.
Expand Down Expand Up @@ -1049,13 +1049,19 @@ parse_node(Tokens) ->
case parse(Tokens) of
{ok, _} = Res ->
Res;
Error ->
{error, {AnnoOrLoc, Mod, Description}} ->
case parse([{standalone_exprs, element(2, hd(Tokens))} | Tokens]) of
{ok, _} = Res -> Res;
_ -> Error
_ -> {error, {error_location(AnnoOrLoc), Mod, Description}}
end
end.

-spec error_location(erlfmt_scan:anno() | erl_anno:location()) -> erl_anno:location().
error_location(#{location := Loc}) ->
Loc;
error_location(Loc) ->
Loc.

%% unwrap single-expr definitions, wrapped in guards by the parser
build_macro_def(
{'-', Anno},
Expand Down

0 comments on commit b86e6ee

Please sign in to comment.