Skip to content

Commit

Permalink
5.3 support: Backport utf8 identifiers (#2622)
Browse files Browse the repository at this point in the history
Vendor required code from Misc.Utf8_lexeme, String, Bytes and Uchar.

Backport utf8 identifiers to standard and extended parser. This reduces the
diff with upstream.

* test: Add utf8_identifiers.ml

Taken from the compiler source.

* test_branch: Ignore parsing errors on 'infer'

The project contains a syntax error, that is new in OCaml 5.3:

    (** [x < min({x'|x'∊l})] *)
  • Loading branch information
Julow authored Nov 20, 2024
1 parent 505ed6e commit cdb0099
Show file tree
Hide file tree
Showing 14 changed files with 825 additions and 268 deletions.
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ profile. This started with version 0.26.0.
This might change the formatting of some functions due to the formatting code
being completely rewritten.

- Support OCaml 5.3 syntax (#2609, #2610, #2611, @Julow)
This adds support for short functor type arguments syntax.
- Support OCaml 5.3 syntax (#2609, #2610, #2611, #2622, @Julow)
This adds support for short functor type arguments syntax and utf8
identifiers.

- Documentation comments are now formatted by default (#2390, @Julow)
Use the option `parse-docstrings = false` to restore the previous behavior.
Expand Down
4 changes: 2 additions & 2 deletions test-extra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# make DIRS=<directory> test
# By default, test projects used as regression tests
DIRS= \
code/ocamlformat code/infer code/js_of_ocaml code/dune code/irmin \
code/ocamlformat code/js_of_ocaml code/dune code/irmin \
code/dune-release code/mirage code/ppxlib code/base

# Extra test directories, for which looser checking is done
XDIRS=code/ocaml
XDIRS=code/ocaml code/infer

# Directories to ignore (given to find, compared literally)
PRUNE_DIRS= \
Expand Down
9 changes: 2 additions & 7 deletions test/failing/tests/unit_lex.ml.broken-ref
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
ocamlformat: ignoring "tests/unit_lex.ml" (syntax error)
File "tests/unit_lex.ml", line 18, characters 4-10:
18 | ������ (* this file must be iso-8859-1 *)
^^^^^^
Alert deprecated: ISO-Latin1 characters in identifiers
ocamlformat: ignoring "tests/unit_lex.ml" (syntax error)

File "tests/unit_lex.ml", line 55, characters 2-8:
55 | '\999'; (* wrong, but yet... *)
^^^^^^
Error: Illegal backslash escape in string or character ('\999'): 999 is outside the range of legal characters (0-255).
Error: Invalid encoding of identifier ������.
11 changes: 3 additions & 8 deletions test/failing/tests/unit_values.ml.broken-ref
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
File "tests/unit_values.ml", line 6, characters 10-11:
6 | let i32 = −1073741824, 1073741823
^
Alert deprecated: ISO-Latin1 characters in identifiers
ocamlformat: ignoring "tests/unit_values.ml" (syntax error)

File "tests/unit_values.ml", line 6, characters 11-12:
File "tests/unit_values.ml", line 6, characters 10-23:
6 | let i32 = −1073741824, 1073741823
^
Error: Illegal character (\136)
^^^^^^^^^^^^^
Error: Invalid character U+2212 in identifier
15 changes: 15 additions & 0 deletions test/passing/gen/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4525,6 +4525,21 @@
(alias runtest)
(action (diff use_file.mlt.err use_file.mlt.stderr)))

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

(rule
(alias runtest)
(action (diff utf8_identifiers.ml.ref utf8_identifiers.ml.stdout)))

(rule
(alias runtest)
(action (diff utf8_identifiers.ml.err utf8_identifiers.ml.stderr)))

(rule
(deps .ocamlformat dune-project)
(action
Expand Down
18 changes: 18 additions & 0 deletions test/passing/refs.default/utf8_identifiers.ml.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(* TEST
readonly_files = "genfiles.ml";
setup-ocamlc.byte-build-env;
all_modules = "genfiles.ml";
program = "./genfiles.byte.exe";
ocamlc.byte;
run;
all_modules = "été.ml ça.ml test.ml";
program = "./main.byte.exe";
ocamlc.byte;
run;
*)

let _ =
(* Source is NFC *)
assert (Été.x + Ça.x = 3);
(* Source is NFD *)
assert (Été.x + Ça.x = 3)
19 changes: 19 additions & 0 deletions test/passing/refs.janestreet/utf8_identifiers.ml.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(* TEST
readonly_files = "genfiles.ml";
setup-ocamlc.byte-build-env;
all_modules = "genfiles.ml";
program = "./genfiles.byte.exe";
ocamlc.byte;
run;
all_modules = "été.ml ça.ml test.ml";
program = "./main.byte.exe";
ocamlc.byte;
run;
*)

let _ =
(* Source is NFC *)
assert (Été.x + Ça.x = 3);
(* Source is NFD *)
assert (Été.x + Ça.x = 3)
;;
18 changes: 18 additions & 0 deletions test/passing/refs.ocamlformat/utf8_identifiers.ml.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(* TEST
readonly_files = "genfiles.ml";
setup-ocamlc.byte-build-env;
all_modules = "genfiles.ml";
program = "./genfiles.byte.exe";
ocamlc.byte;
run;
all_modules = "été.ml ça.ml test.ml";
program = "./main.byte.exe";
ocamlc.byte;
run;
*)

let _ =
(* Source is NFC *)
assert (Été.x + Ça.x = 3) ;
(* Source is NFD *)
assert (Été.x + Ça.x = 3)
18 changes: 18 additions & 0 deletions test/passing/tests/utf8_identifiers.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(* TEST
readonly_files = "genfiles.ml";
setup-ocamlc.byte-build-env;
all_modules = "genfiles.ml";
program = "./genfiles.byte.exe";
ocamlc.byte;
run;
all_modules = "été.ml ça.ml test.ml";
program = "./main.byte.exe";
ocamlc.byte;
run;
*)

let _ =
(* Source is NFC *)
assert (Été.x + Ça.x = 3);
(* Source is NFD *)
assert (Été.x + Ça.x = 3)
Loading

0 comments on commit cdb0099

Please sign in to comment.