From de426a210b1943638e21da88846a8bec9ebe81c6 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 16 Feb 2024 09:57:23 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + priv/stdlib/List.aes | 4 ++-- src/aeso_parser.erl | 10 +++++----- src/aeso_pretty.erl | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7c046e..2eda1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/priv/stdlib/List.aes b/priv/stdlib/List.aes index e0201d0..59bbdf1 100644 --- a/priv/stdlib/List.aes +++ b/priv/stdlib/List.aes @@ -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 */ diff --git a/src/aeso_parser.erl b/src/aeso_parser.erl index 1591078..85bcf95 100644 --- a/src/aeso_parser.erl +++ b/src/aeso_parser.erl @@ -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}. diff --git a/src/aeso_pretty.erl b/src/aeso_pretty.erl index 2697288..cb0c05d 100644 --- a/src/aeso_pretty.erl +++ b/src/aeso_pretty.erl @@ -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}}.