Skip to content

Commit ba0f782

Browse files
authored
Backport 5.3 changes to Format_doc and Location (#2609)
* Backport 5.3 changes to Format_doc and Location Backport compiler libs changes related to printing to the vendored parsers. * Backport changes to code highlighting in errors * Disable Build_path_prefix_map feature Instead of vendoring Build_path_prefix_map as well, the file name rewriting is commented-out. This feature doesn't make sense in ocamlformat. * Fix build on 4.08 Stdlib shims are needed by the parser shims
1 parent 2ba5471 commit ba0f782

File tree

20 files changed

+883
-356
lines changed

20 files changed

+883
-356
lines changed

CHANGES.md

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

16+
- Support OCaml 5.3 syntax (#2609, @Julow)
17+
1618
- Documentation comments are now formatted by default (#2390, @Julow)
1719
Use the option `parse-docstrings = false` to restore the previous behavior.
1820

lib/Extended_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ module Parse = struct
242242
map fg (normalize_mapper ~ocaml_version ~preserve_beginend)
243243
@@
244244
let lexbuf = Lexing.from_string str in
245-
Location.init lexbuf input_name ;
245+
Location.init_info lexbuf input_name ;
246246
match fg with
247247
| Structure -> Parse.implementation lexbuf
248248
| Signature -> Parse.interface lexbuf

lib/Parse_with_comments.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let tokens lexbuf =
4444

4545
let fresh_lexbuf source =
4646
let lexbuf = Lexing.from_string source in
47-
Location.init lexbuf !Location.input_name ;
47+
Location.init_info lexbuf !Location.input_name ;
4848
let hash_bang =
4949
Lexer.skip_hash_bang lexbuf ;
5050
let len = lexbuf.lex_last_pos in
@@ -54,7 +54,7 @@ let fresh_lexbuf source =
5454

5555
let split_hash_bang source =
5656
let lexbuf = Lexing.from_string source in
57-
Location.init lexbuf !Location.input_name ;
57+
Location.init_info lexbuf !Location.input_name ;
5858
Lexer.skip_hash_bang lexbuf ;
5959
let len = lexbuf.lex_last_pos in
6060
let hash_bang = String.sub source ~pos:0 ~len in

lib/Std_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let map (type a) (x : a t) (m : Ast_mapper.mapper) : a -> a =
5858
module Parse = struct
5959
let ast (type a) (fg : a t) ~input_name str : a =
6060
let lexbuf = Lexing.from_string str in
61-
Location.init lexbuf input_name ;
61+
Location.init_info lexbuf input_name ;
6262
match fg with
6363
| Structure -> Parse.implementation lexbuf
6464
| Signature -> Parse.interface lexbuf

test/unit/test_translation_unit.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ let test_parse_and_format_core_type =
4040
(Error
4141
{|test_unit: ignoring "<test>" (syntax error)
4242
File "<test>", line 1, characters 0-2:
43+
1 | ;;
44+
^^
4345
Error: Syntax error
4446
|}
4547
) ]
@@ -69,6 +71,8 @@ let test_parse_and_format_module_type =
6971
File "<test>", line 1, characters 3-3:
7072
Error: Syntax error: "end" expected
7173
File "<test>", line 1, characters 0-3:
74+
1 | sig
75+
^^^
7276
This "sig" might be unmatched
7377
|}
7478
)

0 commit comments

Comments
 (0)