Skip to content

Commit cdb0099

Browse files
authored
5.3 support: Backport utf8 identifiers (#2622)
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})] *)
1 parent 505ed6e commit cdb0099

File tree

14 files changed

+825
-268
lines changed

14 files changed

+825
-268
lines changed

CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ profile. This started with version 0.26.0.
1414
This might change the formatting of some functions due to the formatting code
1515
being completely rewritten.
1616

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

2021
- Documentation comments are now formatted by default (#2390, @Julow)
2122
Use the option `parse-docstrings = false` to restore the previous behavior.

test-extra/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# make DIRS=<directory> test
1414
# By default, test projects used as regression tests
1515
DIRS= \
16-
code/ocamlformat code/infer code/js_of_ocaml code/dune code/irmin \
16+
code/ocamlformat code/js_of_ocaml code/dune code/irmin \
1717
code/dune-release code/mirage code/ppxlib code/base
1818

1919
# Extra test directories, for which looser checking is done
20-
XDIRS=code/ocaml
20+
XDIRS=code/ocaml code/infer
2121

2222
# Directories to ignore (given to find, compared literally)
2323
PRUNE_DIRS= \
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1+
ocamlformat: ignoring "tests/unit_lex.ml" (syntax error)
12
File "tests/unit_lex.ml", line 18, characters 4-10:
23
18 | ������ (* this file must be iso-8859-1 *)
34
^^^^^^
4-
Alert deprecated: ISO-Latin1 characters in identifiers
5-
ocamlformat: ignoring "tests/unit_lex.ml" (syntax error)
6-
7-
File "tests/unit_lex.ml", line 55, characters 2-8:
8-
55 | '\999'; (* wrong, but yet... *)
9-
^^^^^^
10-
Error: Illegal backslash escape in string or character ('\999'): 999 is outside the range of legal characters (0-255).
5+
Error: Invalid encoding of identifier ������.
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
File "tests/unit_values.ml", line 6, characters 10-11:
2-
6 | let i32 = −1073741824, 1073741823
3-
^
4-
Alert deprecated: ISO-Latin1 characters in identifiers
51
ocamlformat: ignoring "tests/unit_values.ml" (syntax error)
6-
7-
File "tests/unit_values.ml", line 6, characters 11-12:
2+
File "tests/unit_values.ml", line 6, characters 10-23:
83
6 | let i32 = −1073741824, 1073741823
9-
^
10-
Error: Illegal character (\136)
4+
^^^^^^^^^^^^^
5+
Error: Invalid character U+2212 in identifier

test/passing/gen/dune.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4525,6 +4525,21 @@
45254525
(alias runtest)
45264526
(action (diff use_file.mlt.err use_file.mlt.stderr)))
45274527

4528+
(rule
4529+
(deps .ocamlformat dune-project)
4530+
(action
4531+
(with-stdout-to utf8_identifiers.ml.stdout
4532+
(with-stderr-to utf8_identifiers.ml.stderr
4533+
(run %{bin:ocamlformat} --name utf8_identifiers.ml --margin-check %{dep:../tests/utf8_identifiers.ml})))))
4534+
4535+
(rule
4536+
(alias runtest)
4537+
(action (diff utf8_identifiers.ml.ref utf8_identifiers.ml.stdout)))
4538+
4539+
(rule
4540+
(alias runtest)
4541+
(action (diff utf8_identifiers.ml.err utf8_identifiers.ml.stderr)))
4542+
45284543
(rule
45294544
(deps .ocamlformat dune-project)
45304545
(action
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(* TEST
2+
readonly_files = "genfiles.ml";
3+
setup-ocamlc.byte-build-env;
4+
all_modules = "genfiles.ml";
5+
program = "./genfiles.byte.exe";
6+
ocamlc.byte;
7+
run;
8+
all_modules = "été.ml ça.ml test.ml";
9+
program = "./main.byte.exe";
10+
ocamlc.byte;
11+
run;
12+
*)
13+
14+
let _ =
15+
(* Source is NFC *)
16+
assert (Été.x + Ça.x = 3);
17+
(* Source is NFD *)
18+
assert (Été.x + Ça.x = 3)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(* TEST
2+
readonly_files = "genfiles.ml";
3+
setup-ocamlc.byte-build-env;
4+
all_modules = "genfiles.ml";
5+
program = "./genfiles.byte.exe";
6+
ocamlc.byte;
7+
run;
8+
all_modules = "été.ml ça.ml test.ml";
9+
program = "./main.byte.exe";
10+
ocamlc.byte;
11+
run;
12+
*)
13+
14+
let _ =
15+
(* Source is NFC *)
16+
assert (Été.x + Ça.x = 3);
17+
(* Source is NFD *)
18+
assert (Été.x + Ça.x = 3)
19+
;;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(* TEST
2+
readonly_files = "genfiles.ml";
3+
setup-ocamlc.byte-build-env;
4+
all_modules = "genfiles.ml";
5+
program = "./genfiles.byte.exe";
6+
ocamlc.byte;
7+
run;
8+
all_modules = "été.ml ça.ml test.ml";
9+
program = "./main.byte.exe";
10+
ocamlc.byte;
11+
run;
12+
*)
13+
14+
let _ =
15+
(* Source is NFC *)
16+
assert (Été.x + Ça.x = 3) ;
17+
(* Source is NFD *)
18+
assert (Été.x + Ça.x = 3)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(* TEST
2+
readonly_files = "genfiles.ml";
3+
setup-ocamlc.byte-build-env;
4+
all_modules = "genfiles.ml";
5+
program = "./genfiles.byte.exe";
6+
ocamlc.byte;
7+
run;
8+
all_modules = "été.ml ça.ml test.ml";
9+
program = "./main.byte.exe";
10+
ocamlc.byte;
11+
run;
12+
*)
13+
14+
let _ =
15+
(* Source is NFC *)
16+
assert (Été.x + Ça.x = 3);
17+
(* Source is NFD *)
18+
assert (Été.x + Ça.x = 3)

0 commit comments

Comments
 (0)