Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add refutation clause #2765

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix outcome printing of optional arguments on OCaml 5.2 (@anmonteiro, [#2753](https://github.com/reasonml/reason/pull/2753))
- support parsing and printing of `external%extension` (@anmonteiro, [#2750](https://github.com/reasonml/reason/pull/2750))
- install `refmt` manpage (@anmonteiro, [#2760](https://github.com/reasonml/reason/pull/2760))
- add support for parsing / printing of refutation clause in `switch` (@anmonteiro, [#2765](https://github.com/reasonml/reason/pull/2765))

## 3.11.0

Expand Down
19 changes: 17 additions & 2 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -3463,13 +3463,28 @@ letop_bindings:
%inline match_cases(EXPR): lnonempty_list(match_case(EXPR)) { $1 };

match_case(EXPR):
as_loc(BAR) pattern preceded(WHEN,expr)? EQUALGREATER EXPR
| as_loc(BAR) pattern EQUALGREATER EXPR
{ let pat = {$2 with ppat_loc =
{ $2.ppat_loc with
loc_start = $1.loc.loc_start
}
} in
Ast_helper.Exp.case pat ?guard:$3 $5 }
Ast_helper.Exp.case pat $4 }
| as_loc(BAR) pattern preceded(WHEN,expr) EQUALGREATER EXPR
{ let pat = {$2 with ppat_loc =
{ $2.ppat_loc with
loc_start = $1.loc.loc_start
}
} in
Ast_helper.Exp.case pat ~guard:$3 $5 }
| as_loc(BAR) pattern EQUALGREATER as_loc(DOT)
{
let pat = {
$2 with ppat_loc =
{ $2.ppat_loc with loc_start = $1.loc.loc_start }
} in
Ast_helper.Exp.(case pat (unreachable ~loc:$4.loc ()))
}
;

fun_def(DELIM, typ):
Expand Down
1 change: 1 addition & 0 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,7 @@ let printer = object(self:'self)
let lhs = self#simple_enough_to_be_lhs_dot_send e in
let lhs = if needparens then makeList ~wrap:("(",")") [lhs] else lhs in
Some (label (makeList [lhs; atom "#";]) (atom s.txt))
| Pexp_unreachable -> Some (atom ".")
| _ -> None
in
match item with
Expand Down
2 changes: 2 additions & 0 deletions test/general-syntax-re.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -1282,3 +1282,5 @@ class y = {
let x = 1G;
let x = 1.123g;

let x = switch () { | _ => .};

5 changes: 5 additions & 0 deletions test/general-syntax-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -1467,3 +1467,8 @@ Format general implementation syntax

let x = 1G;
let x = 1.123g;

let x =
switch () {
| _ => .
};
Loading