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:
Hans Svensson 2024-02-16 09:57:23 +01:00 committed by GitHub
parent 944ed49f0b
commit de426a210b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 9 deletions

View File

@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Support for OTP-27 - no changes in behavior.
### Changed
### Removed
### Fixed

View File

@ -282,9 +282,9 @@ namespace List =
private function
asc : (('a, 'a) => bool, 'a, list('a), list('a)) => list(list('a))
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)
asc(_, x, acc, []) = [List.reverse(x::acc)]
asc(_, x, acc, []) = [reverse(x::acc)]
/** Merges list of sorted lists
*/

View File

@ -302,7 +302,7 @@ stmt() ->
, {switch, keyword(switch), parens(expr()), maybe_block(branch())}
, {'if', keyword('if'), parens(expr()), body()}
, {elif, keyword(elif), parens(expr()), body()}
, {else, keyword(else), body()}
, {'else', keyword('else'), body()}
])).
branch() ->
@ -326,7 +326,7 @@ expr100() ->
Expr150 = ?LAZY_P(expr150()),
choice(
[ ?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())),
case _2 of
none -> _1;
@ -612,7 +612,7 @@ group_ifs([], Acc) ->
group_ifs([{'if', Ann, Cond, Then} | Stmts], Acc) ->
{Elses, Rest} = else_branches(Stmts, []),
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'"});
group_ifs([{elif, Ann, _, _} | _], _) ->
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]) ->
{'if', Ann, Cond, Then,
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};
build_if(Ann, Cond, Then, []) ->
{'if', Ann, Cond, Then, {tuple, [{origin, system}], []}}.
else_branches([Elif = {elif, _, _, _} | Stmts], Acc) ->
else_branches(Stmts, [Elif | Acc]);
else_branches([Else = {else, _, _} | Stmts], Acc) ->
else_branches([Else = {'else', _, _} | Stmts], Acc) ->
{lists:reverse([Else | Acc]), Stmts};
else_branches(Stmts, Acc) ->
{lists:reverse(Acc), Stmts}.

View File

@ -418,7 +418,7 @@ stmt_p({'if', _, Cond, Then}) ->
block_expr(200, beside(text("if"), paren(expr(Cond))), Then);
stmt_p({elif, _, Cond, Then}) ->
block_expr(200, beside(text("elif"), paren(expr(Cond))), Then);
stmt_p({else, Else}) ->
stmt_p({'else', Else}) ->
HideGenerated = not show_generated(),
case aeso_syntax:get_ann(origin, Else) of
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]);
_ -> {lists:reverse(Elifs), If}
end;
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}.
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {'else', Else}}.