Skip to content

Commit

Permalink
Merge pull request #75 from belltoy/fix/maybe-else-optional
Browse files Browse the repository at this point in the history
Fix the optional else block parse in maybe syntax.
  • Loading branch information
elbrujohalcon authored Nov 17, 2022
2 parents a1bebae + 3d38e35 commit b6b6e77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/ktn_code.erl
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ to_map({try_after, Attrs, AfterBody}) ->
#{type => try_after,
attrs => #{location => get_location(Attrs), text => get_text(Attrs)},
content => to_map(AfterBody)};
%% maybe..end
to_map({'maybe', Attrs, Body}) ->
MaybeBody = to_map(Body),
#{type => 'maybe',
attrs => #{location => get_location(Attrs), text => get_text(Attrs)},
content => MaybeBody};
%% maybe..else..end
to_map({'maybe', Attrs, Body, Else}) ->
MaybeBody = to_map(Body),
Expand Down
12 changes: 11 additions & 1 deletion test/ktn_code_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

-if(?OTP_RELEASE >= 25).

-export([parse_maybe/1]).
-export([parse_maybe/1, parse_maybe_else/1]).

-endif.

Expand Down Expand Up @@ -116,6 +116,16 @@ to_string(_Config) ->

-spec parse_maybe(config()) -> ok.
parse_maybe(_Config) ->
%% Note that to pass this test case, the 'maybe_expr' feature must be enabled.
#{type := root,
content :=
[#{type := function, content := [#{type := clause, content := [#{type := 'maybe'}]}]}]} =
ktn_code:parse_tree(<<"foo() -> maybe ok ?= ok end.">>),

ok.

-spec parse_maybe_else(config()) -> ok.
parse_maybe_else(_Config) ->
%% Note that to pass this test case, the 'maybe_expr' feature must be enabled.
#{type := root,
content :=
Expand Down

0 comments on commit b6b6e77

Please sign in to comment.