Skip to content

Commit

Permalink
Implement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
anfelor committed Oct 4, 2024
1 parent 43b8144 commit b91ca94
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions ocaml/parsing/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ let keyword_table =
"once_", ONCE;
"open", OPEN;
"or", OR;
(* CR uniqueness: Check that there are no variables named overwrite_ in Jane *)
"overwrite_", OVERWRITE;
(* "parser", PARSER; *)
"private", PRIVATE;
Expand Down
6 changes: 6 additions & 0 deletions ocaml/parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,12 @@ and expression ?(jane_syntax_parens = false) ctxt f x =
(expression ctxt) body
| Pexp_extension e -> extension ctxt f e
| Pexp_unreachable -> pp f "."
| Pexp_overwrite (x, e) ->
(* Similar to the case of [Pexp_stack] *)
pp f "@[<hov2>overwrite_@ %a@ with@ %a@]"
longident_loc x
(expression2 reset_ctxt) e
| Pexp_hole -> pp f "_"
| _ -> expression1 ctxt f x

and expression1 ctxt f x =
Expand Down
31 changes: 31 additions & 0 deletions ocaml/testsuite/tests/parsetree/source_jane_street.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,34 @@ module type S' =
module M : sig val foo : 'a -> 'a end
end
|}]

(***************)
(* Overwriting *)


let overwrite_tuple = function
(a, b) as t -> overwrite_ t with (b, _)

type record = { a : int; b : int }

let overwrite_record = function
{ a; b } as t -> overwrite_ t with { b = a; a = _ }

let overwrite_record = function
{ a; b } as t -> overwrite_ t with { b = a }

type constructor = C of { a : int; b : int }

let overwrite_constructor = function
C { a; b } as t -> overwrite_ t with C { b = a; a = _ }

let overwrite_constructor = function
C { a; b } as t -> overwrite_ t with C { b = a }
[%%expect{|
Line 2, characters 19-43:
2 | (a, b) as t -> overwrite_ t with (b, _)
^^^^^^^^^^^^^^^^^^^^^^^^
Alert : Overwrite not implemented.
Uncaught exception: File "ocaml/parsing/location.ml", line 1106, characters 2-8: Assertion failed
|}]

0 comments on commit b91ca94

Please sign in to comment.