Skip to content

Commit

Permalink
Support unboxed float literals (janestreet#25)
Browse files Browse the repository at this point in the history
* Automatic changes to patch files

This just happened when I hit `dune build`. Don't really know what's
going on.

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Updated the standard parsetree for unboxed literals

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Support unboxed literals

Testing story not complete yet; want advice.

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Make parsetree changes separated

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Checkpoint

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Still not quite working, but done for tonight

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Vendor in jane-syntax into standard

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* Separate out Jane Street stuff more

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

* More tests, and a bugfix

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>

---------

Signed-off-by: Richard Eisenberg <reisenberg@janestreet.com>
  • Loading branch information
goldfirere authored Jul 21, 2023
1 parent f581f28 commit 7b4d203
Show file tree
Hide file tree
Showing 31 changed files with 3,521 additions and 1,198 deletions.
8 changes: 8 additions & 0 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ let fmt_constant c ?epi {pconst_desc; pconst_loc= loc} =
Cmts.fmt c loc
@@
match pconst_desc with

(* Jane Street extension *)
| Pconst_unboxed_integer (sign, lit, suf)
| Pconst_unboxed_float (sign, lit, suf) ->
(match sign with Positive -> noop | Negative -> char '-') $
char '#' $ str lit $ opt suf char
(* End Jane Street extension *)

| Pconst_integer (lit, suf) | Pconst_float (lit, suf) ->
str lit $ opt suf char
| Pconst_char _ -> wrap "'" "'" @@ str (Source.char_literal c.source loc)
Expand Down
36 changes: 36 additions & 0 deletions test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5398,6 +5398,42 @@
(package ocamlformat)
(action (diff tests/unary_hash.ml.err unary_hash.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to unboxed_types.ml.stdout
(with-stderr-to unboxed_types.ml.stderr
(run %{bin:ocamlformat} --margin-check %{dep:tests/unboxed_types.ml})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/unboxed_types.ml unboxed_types.ml.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/unboxed_types.ml.err unboxed_types.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to unboxed_types2.ml.stdout
(with-stderr-to unboxed_types2.ml.stderr
(run %{bin:ocamlformat} --margin-check %{dep:tests/unboxed_types2.ml})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/unboxed_types2.ml.ref unboxed_types2.ml.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/unboxed_types2.ml.err unboxed_types2.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
Expand Down
4 changes: 2 additions & 2 deletions test/passing/tests/line_directives.ml.err
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ocamlformat: ignoring "tests/line_directives.ml" (syntax error)
File "tests/line_directives.ml", line 1, characters 1-9:
File "tests/line_directives.ml", line 1, characters 0-9:
1 | #3 "f.ml"
^^^^^^^^
^^^^^^^^^
Error: Invalid lexer directive "#3 \"f.ml\"": line directives are not supported
21 changes: 21 additions & 0 deletions test/passing/tests/unboxed_types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let x = #3l

let x = #3L

let x = #3n

let x = -#3l

let x = #3.0

let x = -#3.0

let x = #3.0 + #4.0

let x = #3.0 - #4.0

let x = (#3.0 [@attr])

let x = (#3.0 + #4.0) [@attr]

let x = f #3.0 #4.0 #5.0 x y #0.
8 changes: 8 additions & 0 deletions test/passing/tests/unboxed_types2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(* this one is purposefully misformatted *)

let x = +#3.14
let x = #3.14+#5.82
let x = #3l-#4n
let x = #4n+ -#5.0
let x = f #3n#4l#5.0-#6L+-#7.0z#3n
let x = f #3n#4l#5.0-#6L+-#7.0 z#3n
13 changes: 13 additions & 0 deletions test/passing/tests/unboxed_types2.ml.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(* this one is purposefully misformatted *)

let x = #3.14

let x = #3.14 + #5.82

let x = #3l - #4n

let x = #4n + -#5.0

let x = f #3n #4l #5.0 - #6L +- #7.0z #3n

let x = f #3n #4l #5.0 - #6L +- #7.0 z #3n
Loading

0 comments on commit 7b4d203

Please sign in to comment.