Fix parser/pretty printer for OTP-27 (#502)
* In OTP-27 else is made a keyword, so needs quouting * Fix List.aes - remove unnecessary self-qualification * Changelog
This commit is contained in:
parent
944ed49f0b
commit
de426a210b
@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
|
- Support for OTP-27 - no changes in behavior.
|
||||||
### Changed
|
### Changed
|
||||||
### Removed
|
### Removed
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -282,9 +282,9 @@ namespace List =
|
|||||||
private function
|
private function
|
||||||
asc : (('a, 'a) => bool, 'a, list('a), list('a)) => list(list('a))
|
asc : (('a, 'a) => bool, 'a, list('a), list('a)) => list(list('a))
|
||||||
asc(lt, x, acc, h::t) =
|
asc(lt, x, acc, h::t) =
|
||||||
if(lt(h, x)) List.reverse(x::acc) :: monotonic_subs(lt, h::t)
|
if(lt(h, x)) reverse(x::acc) :: monotonic_subs(lt, h::t)
|
||||||
else asc(lt, h, x::acc, t)
|
else asc(lt, h, x::acc, t)
|
||||||
asc(_, x, acc, []) = [List.reverse(x::acc)]
|
asc(_, x, acc, []) = [reverse(x::acc)]
|
||||||
|
|
||||||
/** Merges list of sorted lists
|
/** Merges list of sorted lists
|
||||||
*/
|
*/
|
||||||
|
@ -302,7 +302,7 @@ stmt() ->
|
|||||||
, {switch, keyword(switch), parens(expr()), maybe_block(branch())}
|
, {switch, keyword(switch), parens(expr()), maybe_block(branch())}
|
||||||
, {'if', keyword('if'), parens(expr()), body()}
|
, {'if', keyword('if'), parens(expr()), body()}
|
||||||
, {elif, keyword(elif), parens(expr()), body()}
|
, {elif, keyword(elif), parens(expr()), body()}
|
||||||
, {else, keyword(else), body()}
|
, {'else', keyword('else'), body()}
|
||||||
])).
|
])).
|
||||||
|
|
||||||
branch() ->
|
branch() ->
|
||||||
@ -326,7 +326,7 @@ expr100() ->
|
|||||||
Expr150 = ?LAZY_P(expr150()),
|
Expr150 = ?LAZY_P(expr150()),
|
||||||
choice(
|
choice(
|
||||||
[ ?RULE(lam_args(), keyword('=>'), body(), {lam, _2, _1, _3}) %% TODO: better location
|
[ ?RULE(lam_args(), keyword('=>'), body(), {lam, _2, _1, _3}) %% TODO: better location
|
||||||
, {'if', keyword('if'), parens(Expr100), Expr150, right(tok(else), Expr100)}
|
, {'if', keyword('if'), parens(Expr100), Expr150, right(tok('else'), Expr100)}
|
||||||
, ?RULE(Expr150, optional(right(tok(':'), type())),
|
, ?RULE(Expr150, optional(right(tok(':'), type())),
|
||||||
case _2 of
|
case _2 of
|
||||||
none -> _1;
|
none -> _1;
|
||||||
@ -612,7 +612,7 @@ group_ifs([], Acc) ->
|
|||||||
group_ifs([{'if', Ann, Cond, Then} | Stmts], Acc) ->
|
group_ifs([{'if', Ann, Cond, Then} | Stmts], Acc) ->
|
||||||
{Elses, Rest} = else_branches(Stmts, []),
|
{Elses, Rest} = else_branches(Stmts, []),
|
||||||
group_ifs(Rest, [build_if(Ann, Cond, Then, Elses) | Acc]);
|
group_ifs(Rest, [build_if(Ann, Cond, Then, Elses) | Acc]);
|
||||||
group_ifs([{else, Ann, _} | _], _) ->
|
group_ifs([{'else', Ann, _} | _], _) ->
|
||||||
fail({Ann, "No matching 'if' for 'else'"});
|
fail({Ann, "No matching 'if' for 'else'"});
|
||||||
group_ifs([{elif, Ann, _, _} | _], _) ->
|
group_ifs([{elif, Ann, _, _} | _], _) ->
|
||||||
fail({Ann, "No matching 'if' for 'elif'"});
|
fail({Ann, "No matching 'if' for 'elif'"});
|
||||||
@ -622,14 +622,14 @@ group_ifs([Stmt | Stmts], Acc) ->
|
|||||||
build_if(Ann, Cond, Then, [{elif, Ann1, Cond1, Then1} | Elses]) ->
|
build_if(Ann, Cond, Then, [{elif, Ann1, Cond1, Then1} | Elses]) ->
|
||||||
{'if', Ann, Cond, Then,
|
{'if', Ann, Cond, Then,
|
||||||
set_ann(format, elif, build_if(Ann1, Cond1, Then1, Elses))};
|
set_ann(format, elif, build_if(Ann1, Cond1, Then1, Elses))};
|
||||||
build_if(Ann, Cond, Then, [{else, _Ann, Else}]) ->
|
build_if(Ann, Cond, Then, [{'else', _Ann, Else}]) ->
|
||||||
{'if', Ann, Cond, Then, Else};
|
{'if', Ann, Cond, Then, Else};
|
||||||
build_if(Ann, Cond, Then, []) ->
|
build_if(Ann, Cond, Then, []) ->
|
||||||
{'if', Ann, Cond, Then, {tuple, [{origin, system}], []}}.
|
{'if', Ann, Cond, Then, {tuple, [{origin, system}], []}}.
|
||||||
|
|
||||||
else_branches([Elif = {elif, _, _, _} | Stmts], Acc) ->
|
else_branches([Elif = {elif, _, _, _} | Stmts], Acc) ->
|
||||||
else_branches(Stmts, [Elif | Acc]);
|
else_branches(Stmts, [Elif | Acc]);
|
||||||
else_branches([Else = {else, _, _} | Stmts], Acc) ->
|
else_branches([Else = {'else', _, _} | Stmts], Acc) ->
|
||||||
{lists:reverse([Else | Acc]), Stmts};
|
{lists:reverse([Else | Acc]), Stmts};
|
||||||
else_branches(Stmts, Acc) ->
|
else_branches(Stmts, Acc) ->
|
||||||
{lists:reverse(Acc), Stmts}.
|
{lists:reverse(Acc), Stmts}.
|
||||||
|
@ -418,7 +418,7 @@ stmt_p({'if', _, Cond, Then}) ->
|
|||||||
block_expr(200, beside(text("if"), paren(expr(Cond))), Then);
|
block_expr(200, beside(text("if"), paren(expr(Cond))), Then);
|
||||||
stmt_p({elif, _, Cond, Then}) ->
|
stmt_p({elif, _, Cond, Then}) ->
|
||||||
block_expr(200, beside(text("elif"), paren(expr(Cond))), Then);
|
block_expr(200, beside(text("elif"), paren(expr(Cond))), Then);
|
||||||
stmt_p({else, Else}) ->
|
stmt_p({'else', Else}) ->
|
||||||
HideGenerated = not show_generated(),
|
HideGenerated = not show_generated(),
|
||||||
case aeso_syntax:get_ann(origin, Else) of
|
case aeso_syntax:get_ann(origin, Else) of
|
||||||
system when HideGenerated -> empty();
|
system when HideGenerated -> empty();
|
||||||
@ -533,5 +533,5 @@ get_elifs(If = {'if', Ann, Cond, Then, Else}, Elifs) ->
|
|||||||
elif -> get_elifs(Else, [{elif, Ann, Cond, Then} | Elifs]);
|
elif -> get_elifs(Else, [{elif, Ann, Cond, Then} | Elifs]);
|
||||||
_ -> {lists:reverse(Elifs), If}
|
_ -> {lists:reverse(Elifs), If}
|
||||||
end;
|
end;
|
||||||
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}.
|
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {'else', Else}}.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user