From cbd947461ee99824a467c6c27acd138de48043c0 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Tue, 6 Jun 2023 23:17:14 +0100 Subject: [PATCH 1/4] Update CHANGES.md --- CHANGES.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3519969e..28535f0f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,21 +1,35 @@ -2.0.0 ------ +# 3.0.0 + +### Fixed + +- Better handling of reference syntax (@EmileTrotignon, #13) + +### Added + +- Delimited code blocks with associated output (@jonludlam, #17) +- New @hidden tag (@3Rafal, #16) +- Table syntax (@gpetiot, #11, @panglesd, #14) + +# 2.0.0 - 2022-07-07 + +### Added - New inline and display math markup (@giltho, #5) -1.0.1 ------ +# 1.0.1 - 2022-07-05 + +### Added - OCaml 5.0 support (@talex5, #6) -1.0.0 ------ +# 1.0.0 - 2021-12-11 + +### Added - New syntax to allow associating metadata with code blocks (@Julow, #2, #3) -0.9.0 ------ +# 0.9.0 - 2021-07-02 - Extracted from odoc repository From 85423ca2527310f36c1ec858396b8038736bd33a Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Wed, 7 Jun 2023 00:01:43 +0100 Subject: [PATCH 2/4] Remove astring dependency We were only using it for 2 functions, both of which are in stdlib. Unfortunately they're also added in 4.03 and 4.04, and we support 4.02, so the code has been spliced in until we drop support for these early versions. --- dune-project | 3 +-- odoc-parser.opam | 3 +-- odoc-parser.opam.template | 1 - package.json | 1 - src/dune | 2 +- src/lexer.mll | 18 +++++++++++++++++- src/parse_error.ml | 18 +++++++++++++++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/dune-project b/dune-project index 55706d52..16a29afa 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,6 @@ (lang dune 2.8) (name odoc-parser) -(version 2.0.0) +(version 3.0.0) (generate_opam_files true) @@ -18,7 +18,6 @@ understood by ocamldoc.") (depends dune (ocaml (>= 4.02.0)) - astring result camlp-streams (ppx_expect :with-test))) diff --git a/odoc-parser.opam b/odoc-parser.opam index 7d485752..ea6a86dc 100644 --- a/odoc-parser.opam +++ b/odoc-parser.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "2.0.0" +version: "3.0.0" synopsis: "Parser for ocaml documentation comments" description: """ Odoc_parser is a library for parsing the contents of OCaml documentation @@ -18,7 +18,6 @@ doc: "https://ocaml-doc.github.io/odoc-parser/" depends: [ "dune" {>= "2.8"} "ocaml" {>= "4.02.0"} - "astring" "result" "camlp-streams" "ppx_expect" {with-test} diff --git a/odoc-parser.opam.template b/odoc-parser.opam.template index 47ac9f5d..6c2730a2 100644 --- a/odoc-parser.opam.template +++ b/odoc-parser.opam.template @@ -4,7 +4,6 @@ doc: "https://ocaml-doc.github.io/odoc-parser/" depends: [ "dune" {>= "2.8"} "ocaml" {>= "4.02.0"} - "astring" "result" "camlp-streams" "ppx_expect" {with-test} diff --git a/package.json b/package.json index 9a1623b6..888b094c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "buildsInSource": "_build" }, "dependencies": { - "@opam/astring": "^0.8.3", "@opam/dune": "^2.8.5", "@opam/result": "*", "@opam/ppx_expect": "*", diff --git a/src/dune b/src/dune index 36bd5bf2..c0db1e31 100644 --- a/src/dune +++ b/src/dune @@ -7,4 +7,4 @@ (backend bisect_ppx)) (flags (:standard -w -50)) - (libraries astring result camlp-streams)) + (libraries result camlp-streams)) diff --git a/src/lexer.mll b/src/lexer.mll index 0cde0b43..407b179b 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -1,5 +1,21 @@ { +(* The following function is taken from the ocaml stdlib. It's here because we support building + om OCaml < 4.04. Once we drop support for 4.03 and before we can remove the following function *) + +let split_on_char sep s = + let open String in + let r = ref [] in + let j = ref (length s) in + for i = length s - 1 downto 0 do + if unsafe_get s i = sep then begin + r := sub s (i + 1) (!j - i - 1) :: !r; + j := i + end + done; + sub s 0 !j :: !r + + let unescape_word : string -> string = fun s -> (* The common case is that there are no escape sequences. *) match String.index s '\\' with @@ -94,7 +110,7 @@ let trim_leading_whitespace : first_line_offset:int -> string -> string = count_leading_whitespace' 0 len in - let lines = Astring.String.cuts ~sep:"\n" s in + let lines = split_on_char '\n' s in let least_amount_of_whitespace = List.fold_left (fun least_so_far line -> diff --git a/src/parse_error.ml b/src/parse_error.ml index 4ee22c47..f09c1c7a 100644 --- a/src/parse_error.ml +++ b/src/parse_error.ml @@ -1,4 +1,20 @@ -let capitalize_ascii = Astring.String.Ascii.capitalize +(* This is taken from the ocaml stdlib (more or less) - only here because we support + 4.02 and capitalize_ascii only arrived in 4.03. When we drop support + for 4.02 we can remove the following 3 functions *) +let uppercase_ascii = + let open Char in + function + | 'a' .. 'z' as c -> unsafe_chr(code c - 32) + | c -> c + +let apply1 f s = + let open String in + if length s = 0 then s else begin + let r = sub s 1 (length s - 1) in + (make 1 (f(unsafe_get s 0))) ^ r + end + +let capitalize_ascii s = apply1 uppercase_ascii s let bad_markup : ?suggestion:string -> string -> Loc.span -> Warning.t = fun ?suggestion -> Warning.make ?suggestion "'%s': bad markup." From 46d95535ff41001c68902ef8fe639a0b7c57bec1 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Wed, 7 Jun 2023 00:22:15 +0100 Subject: [PATCH 3/4] Formatting --- src/parse_error.ml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/parse_error.ml b/src/parse_error.ml index f09c1c7a..8612f5d2 100644 --- a/src/parse_error.ml +++ b/src/parse_error.ml @@ -3,16 +3,14 @@ for 4.02 we can remove the following 3 functions *) let uppercase_ascii = let open Char in - function - | 'a' .. 'z' as c -> unsafe_chr(code c - 32) - | c -> c + function 'a' .. 'z' as c -> unsafe_chr (code c - 32) | c -> c let apply1 f s = let open String in - if length s = 0 then s else begin + if length s = 0 then s + else let r = sub s 1 (length s - 1) in - (make 1 (f(unsafe_get s 0))) ^ r - end + make 1 (f (unsafe_get s 0)) ^ r let capitalize_ascii s = apply1 uppercase_ascii s From b88594d33a1515340ef0ced4fb6abbbd93b4bda1 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Wed, 7 Jun 2023 09:33:12 +0100 Subject: [PATCH 4/4] Move backported string functions to compat --- CHANGES.md | 4 ++++ src/compat.ml | 33 +++++++++++++++++++++++++++++++++ src/lexer.mll | 18 +----------------- src/parse_error.ml | 28 +++++++--------------------- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 28535f0f..07f4445c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # 3.0.0 +### Changed + +- Remove astring dependency (@jonludlam, #18) + ### Fixed - Better handling of reference syntax (@EmileTrotignon, #13) diff --git a/src/compat.ml b/src/compat.ml index a7b535d1..97ccc957 100644 --- a/src/compat.ml +++ b/src/compat.ml @@ -29,4 +29,37 @@ module String = struct else false in aux 0 + + (* This is taken from the OCaml stdlib (more or less) - only here because we support + 4.02 and capitalize_ascii only arrived in 4.03. When we drop support + for 4.02 we can remove the following 3 functions *) + + let capitalize_ascii = + let uppercase_ascii = + let open Char in + function 'a' .. 'z' as c -> unsafe_chr (code c - 32) | c -> c + in + + let apply1 f s = + let open String in + if length s = 0 then s + else + let r = sub s 1 (length s - 1) in + make 1 (f (unsafe_get s 0)) ^ r + in + + apply1 uppercase_ascii + + (* The following function is taken from the OCaml stdlib. It's here because we support building + om OCaml < 4.04. Once we drop support for 4.03 and before we can remove the following function *) + let split_on_char sep s = + let open String in + let r = ref [] in + let j = ref (length s) in + for i = length s - 1 downto 0 do + if unsafe_get s i = sep then ( + r := sub s (i + 1) (!j - i - 1) :: !r; + j := i) + done; + sub s 0 !j :: !r end diff --git a/src/lexer.mll b/src/lexer.mll index 407b179b..2af3b866 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -1,21 +1,5 @@ { -(* The following function is taken from the ocaml stdlib. It's here because we support building - om OCaml < 4.04. Once we drop support for 4.03 and before we can remove the following function *) - -let split_on_char sep s = - let open String in - let r = ref [] in - let j = ref (length s) in - for i = length s - 1 downto 0 do - if unsafe_get s i = sep then begin - r := sub s (i + 1) (!j - i - 1) :: !r; - j := i - end - done; - sub s 0 !j :: !r - - let unescape_word : string -> string = fun s -> (* The common case is that there are no escape sequences. *) match String.index s '\\' with @@ -110,7 +94,7 @@ let trim_leading_whitespace : first_line_offset:int -> string -> string = count_leading_whitespace' 0 len in - let lines = split_on_char '\n' s in + let lines = String.split_on_char '\n' s in let least_amount_of_whitespace = List.fold_left (fun least_so_far line -> diff --git a/src/parse_error.ml b/src/parse_error.ml index 8612f5d2..8b454a5c 100644 --- a/src/parse_error.ml +++ b/src/parse_error.ml @@ -1,19 +1,3 @@ -(* This is taken from the ocaml stdlib (more or less) - only here because we support - 4.02 and capitalize_ascii only arrived in 4.03. When we drop support - for 4.02 we can remove the following 3 functions *) -let uppercase_ascii = - let open Char in - function 'a' .. 'z' as c -> unsafe_chr (code c - 32) | c -> c - -let apply1 f s = - let open String in - if length s = 0 then s - else - let r = sub s 1 (length s - 1) in - make 1 (f (unsafe_get s 0)) ^ r - -let capitalize_ascii s = apply1 uppercase_ascii s - let bad_markup : ?suggestion:string -> string -> Loc.span -> Warning.t = fun ?suggestion -> Warning.make ?suggestion "'%s': bad markup." @@ -21,27 +5,29 @@ let leading_zero_in_heading_level : string -> Loc.span -> Warning.t = Warning.make "'%s': leading zero in heading level." let should_not_be_empty : what:string -> Loc.span -> Warning.t = - fun ~what -> Warning.make "%s should not be empty." (capitalize_ascii what) + fun ~what -> + Warning.make "%s should not be empty." (String.capitalize_ascii what) let markup_should_not_be_used : what:string -> Loc.span -> Warning.t = fun ~what -> Warning.make "%s should not be used because it has no effect." - (capitalize_ascii what) + (String.capitalize_ascii what) let should_begin_on_its_own_line : what:string -> Loc.span -> Warning.t = fun ~what -> - Warning.make "%s should begin on its own line." (capitalize_ascii what) + Warning.make "%s should begin on its own line." (String.capitalize_ascii what) let should_be_followed_by_whitespace : what:string -> Loc.span -> Warning.t = fun ~what -> Warning.make "%s should be followed by space, a tab, or a new line." - (capitalize_ascii what) + (String.capitalize_ascii what) let not_allowed : ?suggestion:string -> what:string -> in_what:string -> Loc.span -> Warning.t = fun ?suggestion ~what ~in_what -> - Warning.make ?suggestion "%s is not allowed in %s." (capitalize_ascii what) + Warning.make ?suggestion "%s is not allowed in %s." + (String.capitalize_ascii what) in_what let unclosed_bracket :