-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Location.is_none and fix loc_of_attributes
Location.is_none provides a means to check whether a given location is none for all supported compiler versions (as the none location changed). We then use this is loc_of_attributes to correctly pick-up none-located, compiler attributes like documentation comments. Signed-off-by: Patrick Ferris <[email protected]>
- Loading branch information
1 parent
562a9fa
commit 139d7e1
Showing
6 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(executable | ||
(name pp) | ||
(libraries ppxlib)) | ||
|
||
(cram | ||
(applies_to print_attr_loc) | ||
(deps pp.exe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open Ppxlib | ||
|
||
let pp_attr str = | ||
let iter = | ||
object | ||
inherit Ast_traverse.iter as super | ||
|
||
method! attribute v = | ||
let loc = loc_of_attribute v in | ||
Format.printf "%a %s" Location.print loc v.attr_name.txt; | ||
super#attribute v | ||
end | ||
in | ||
iter#structure str; | ||
str | ||
|
||
let () = Driver.register_transformation ~impl:pp_attr "print-attributes" | ||
let () = Ppxlib.Driver.standalone () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The compiler inserts documentation comments with their location set to | ||
`Location.none`. The value for `Location.none` has changed in the compiler (at | ||
4.08.0). We provide a function, `loc_of_attribute` to handle deriving better location | ||
errors for attributes with a none location. | ||
|
||
$ cat > test.ml << EOF | ||
> let v = 1 | ||
> (** A documentation comment! *) | ||
> EOF | ||
|
||
We run an identity driver that prints the locations of attributes. | ||
|
||
$ ./pp.exe --impl test.ml -o ignore.ml | ||
File "test.ml", line 2, characters 0-31: ocaml.doc | ||
|