This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,7 @@
(executable
(name pp)
(libraries ppxlib))
(cram
(applies_to print_attr_loc)
(deps pp.exe))

View file

@ -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 ()

View file

@ -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

View file

@ -0,0 +1,14 @@
(rule
(package ppxlib)
(alias runtest)
(enabled_if
(>= %{ocaml_version} "4.08.0"))
(deps
(:test test.ml)
(package ppxlib))
(action
(chdir
%{project_root}
(progn
(run expect-test %{test})
(diff? %{test} %{test}.corrected)))))

View file

@ -0,0 +1,17 @@
open Ppxlib.Location
let catch_as_compiler_exception =
try raise_errorf ~loc:none "foo" with
| Ocaml_common.Location.Error _ -> "caught"
| _ -> "uncaught"
[%%expect{|
val catch_as_compiler_exception : string = "caught"
|}]
let catch_as_ppxlib_exception =
try raise_errorf ~loc:none "foo" with
| Error _ -> "caught"
| _ -> "uncaught"
[%%expect{|
val catch_as_ppxlib_exception : string = "caught"
|}]