Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ocamlc_loc): uniform handling of codes #6694

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ understood by dune language."))
(package
(name ocamlc-loc)
(synopsis "Parse ocaml compiler output into structured form")
(conflicts
(ocaml-lsp-server (< 1.15.0)))
(depends
(ocaml (>= 4.08.0))
(dyn (= :version)))
Expand Down
3 changes: 3 additions & 0 deletions ocamlc-loc.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ depends: [
"dyn" {= version}
"odoc" {with-doc}
]
conflicts: [
"ocaml-lsp-server" {< "1.15.0"}
]
dev-repo: "git+https://github.com/ocaml/dune.git"
build: [
["dune" "subst"] {dev}
Expand Down
12 changes: 7 additions & 5 deletions otherlibs/ocamlc_loc/src/lexer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ type lines =
| Single of int
| Range of int * int

type code =
{ code : int
; name : string
}

type source =
| Code of
{ code : int
; name : string
}
| Code of code
| Alert of string

type severity =
| Error of source option
| Warning of source
| Warning of code
| Alert of
{ name : string
; source : string
Expand Down
18 changes: 11 additions & 7 deletions otherlibs/ocamlc_loc/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
| Single of int
| Range of int * int

type code =
{ code : int
; name : string
}

type source =
| Code of { code : int ; name : string }
| Code of code
| Alert of string

type severity =
| Error of source option
| Warning of source
| Warning of code
| Alert of { name : string ; source : string }

type loc =
Expand Down Expand Up @@ -62,7 +67,7 @@ and severity = parse
{ Some (Error None, rest) }
| "Warning" blank (digits as code) blank "[" ([^ ']']+ as name) "]:"
(blank any as rest)
{ Some (Warning (Code { code = int_of_string code ; name }), rest)
{ Some (Warning { code = int_of_string code ; name }, rest)
}
| "Error" blank
"(warning" blank (digits as code) blank "[" ([^ ']']+ as name) "]):"
Expand All @@ -74,11 +79,10 @@ and severity = parse
}
| (("Error" | "Warning") as kind) " (alert " ([^ ')']+ as alert) "):"
(blank any as rest)
{ let alert : source = Alert alert in
let res =
{ let res =
match kind with
| "Error" -> Error (Some alert)
| "Warning" -> Warning alert
| "Error" -> Error (Some (Alert alert))
| "Warning" -> Alert { name = alert ; source = "" }
| _ -> assert false
in
Some (res, rest)
Expand Down
6 changes: 5 additions & 1 deletion otherlibs/ocamlc_loc/src/ocamlc_loc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ type report =
; related : (loc * string) list
}

let dyn_of_code { code; name } =
let open Dyn in
record [ ("code", int code); ("name", string name) ]

let dyn_of_source =
let open Dyn in
function
Expand All @@ -18,7 +22,7 @@ let dyn_of_severity =
let open Dyn in
function
| Error w -> variant "Error" [ option dyn_of_source w ]
| Warning w -> variant "Warning" [ dyn_of_source w ]
| Warning w -> variant "Warning" [ dyn_of_code w ]
| Alert { name; source } ->
variant "Alert"
[ record [ ("name", string name); ("source", string source) ] ]
Expand Down
12 changes: 7 additions & 5 deletions otherlibs/ocamlc_loc/src/ocamlc_loc.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[@@@alert
unstable "The API of this library is not stable and may change without notice."]

type code =
{ code : int
; name : string
}

type source =
| Code of
{ code : int
; name : string
}
| Code of code
| Alert of string

type lines =
Expand All @@ -20,7 +22,7 @@ type loc =

type severity =
| Error of source option
| Warning of source
| Warning of code
| Alert of
{ name : string
; source : string
Expand Down