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

fix(ocamlc_loc): parse alerts #6678

Merged
merged 1 commit into from
Dec 13, 2022
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Fix the parsing of alerts. They will now show up in diagnostics correctly.
(#6678, @rginberg)

- Fix the compilation of modules generated at link time when
`implicit_transitive_deps` is enabled (#6642, @rgrinberg)

Expand Down
4 changes: 4 additions & 0 deletions otherlibs/ocamlc_loc/src/lexer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type source =
type severity =
| Error of source option
| Warning of source
| Alert of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't alerts handled by the type above? Or what is the relation between them?

{ name : string
; source : string
}

type loc =
{ chars : (int * int) option
Expand Down
8 changes: 7 additions & 1 deletion otherlibs/ocamlc_loc/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
type severity =
| Error of source option
| Warning of source
| Alert of { name : string ; source : string }

type loc =
{ chars : (int * int) option
Expand Down Expand Up @@ -45,6 +46,8 @@ let range = digits "-" digits

let any = _ *

let alert_name = ['a' - 'z'] ['A' - 'Z' 'a' - 'z' '0' - '9' '_']*

rule skip_excerpt = parse
| blank digits " | " [^ '\n']* "\n"?
{ `Continue }
Expand All @@ -66,9 +69,12 @@ and severity = parse
(blank any as rest)
{ Some (Error (Some (Code { code = int_of_string code ; name })), rest)
}
| "Alert " blank (alert_name as name) ":" (any as source)
{ Some (Alert { name ; source }, "")
}
| (("Error" | "Warning") as kind) " (alert " ([^ ')']+ as alert) "):"
(blank any as rest)
{ let alert = Alert alert in
{ let alert : source = Alert alert in
let res =
match kind with
| "Error" -> Error (Some alert)
Expand Down
5 changes: 5 additions & 0 deletions otherlibs/ocamlc_loc/src/ocamlc_loc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ let dyn_of_severity =
function
| Error w -> variant "Error" [ option dyn_of_source w ]
| Warning w -> variant "Warning" [ dyn_of_source w ]
| Alert { name; source } ->
variant "Alert"
[ record [ ("name", string name); ("source", string source) ] ]

let dyn_of_loc { path; lines; chars } =
let open Dyn in
Expand Down Expand Up @@ -86,6 +89,8 @@ end
let indent_of_severity = function
| Error _ -> String.length "Error: "
| Warning _ -> String.length "Warning: "
| Alert { name; source } ->
String.length "Alert :" + String.length name + String.length source + 1

let severity tokens =
match Tokens.peek tokens with
Expand Down
4 changes: 4 additions & 0 deletions otherlibs/ocamlc_loc/src/ocamlc_loc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type loc =
type severity =
| Error of source option
| Warning of source
| Alert of
{ name : string
; source : string
}

type report =
{ loc : loc
Expand Down
18 changes: 16 additions & 2 deletions otherlibs/ocamlc_loc/test/ocamlc_loc_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,14 @@ File "foo.ml", line 8, characters 9-12:
Alert deprecated: A.f
foo
|};
[%expect {||}];
[%expect
{|
>> error 0
{ loc = { path = "foo.ml"; line = Single 8; chars = Some (9, 12) }
; message = "foo"
; related = []
; severity = Alert { name = "deprecated"; source = " A.f" }
} |}];
test_error
{|
File "foo.ml", line 8, characters 9-12:
Expand All @@ -409,4 +416,11 @@ File "foo.ml", line 8, characters 9-12:
Alert foobar: A.f
blah
|};
[%expect {||}]
[%expect
{|
>> error 0
{ loc = { path = "foo.ml"; line = Single 8; chars = Some (9, 12) }
; message = "blah"
; related = []
; severity = Alert { name = "foobar"; source = " A.f" }
} |}]