Source locations and structured errors for text codecs (extracted from jsont)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-linkedin: apply dune fmt

Pure formatting changes from `dune fmt`: doc comment placement moves
from above the binding to below it for `type`s, multi-line `match`
expressions collapse onto one line where they fit, and infix operator
applications pick up spaces (`Soup.($?)` -> `Soup.( $? )`). No
semantic changes.

+30 -13
+23 -13
README.md
··· 22 22 - `exception Loc.Error of Loc.Error.t` — single shared exception for 23 23 cross-package error propagation 24 24 25 - ## Install 25 + ## Installation 26 + 27 + Install with opam: 26 28 29 + ```shell 30 + $ opam install loc 27 31 ``` 28 - opam install loc 32 + 33 + If opam cannot find the package, it may not yet be released in the public 34 + `opam-repository`. Add the overlay repository, then install it: 35 + 36 + ```shell 37 + $ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git 38 + $ opam update 39 + $ opam install loc 29 40 ``` 30 41 31 42 Requires OCaml >= 4.14 and `fmt`. ··· 35 46 Raise a structured error at a specific source location: 36 47 37 48 ```ocaml 38 - let loc = 39 - Loc.make ~file:"config.toml" 40 - ~first_byte:42 ~last_byte:47 41 - ~first_line_num:3 ~first_line_byte:0 42 - ~last_line_num:3 ~last_line_byte:0 43 - 44 - let meta = Loc.Meta.make loc 45 - 46 - let () = 49 + let demo_raise () = 50 + let loc = 51 + Loc.make ~file:"config.toml" 52 + ~first_byte:42 ~last_byte:47 53 + ~first_line_num:3 ~first_line_byte:0 54 + ~last_line_num:3 ~last_line_byte:0 55 + in 56 + let meta = Loc.Meta.make loc in 47 57 try Loc.Error.failf meta "expected %s, got %s" "integer" "\"nope\"" 48 58 with Loc.Error e -> print_endline (Loc.Error.to_string e) 49 59 ``` ··· 52 62 nested object members: 53 63 54 64 ```ocaml 55 - let () = 65 + let demo_push () = 56 66 let table = ("table [server]", Loc.Meta.none) in 57 67 try 58 68 try Loc.Error.fail Loc.Meta.none "not a number" ··· 67 77 ```ocaml 68 78 type Loc.Error.kind += Unknown_key of string 69 79 70 - let () = 80 + let register () = 71 81 Loc.Error.register_kind_printer (function 72 82 | Unknown_key k -> Some (fun ppf -> Format.fprintf ppf "unknown key %S" k) 73 83 | _ -> None)
+4
dune
··· 1 1 (env 2 2 (dev 3 3 (flags :standard %{dune-warnings}))) 4 + 5 + (mdx 6 + (files README.md) 7 + (libraries loc))
+2
dune-project
··· 1 1 (lang dune 3.21) 2 + (using mdx 0.4) 2 3 3 4 (name loc) 4 5 ··· 27 28 (dune (>= 3.21)) 28 29 fmt 29 30 (alcotest :with-test) 31 + (mdx :with-test) 30 32 (odoc :with-doc)))
+1
loc.opam
··· 21 21 "dune" {>= "3.21" & >= "3.21"} 22 22 "fmt" 23 23 "alcotest" {with-test} 24 + "mdx" {with-test} 24 25 "odoc" {with-doc} 25 26 ] 26 27 build: [