This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.0)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(include_subdirs unqualified)
|
||||
|
||||
(library
|
||||
(name foo))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(executable
|
||||
(name pp))
|
||||
|
||||
(ocamllex pp)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
rule main = parse
|
||||
| eof { () }
|
||||
| "_STRING_" { Printf.printf "%S" "Hello, world!"; main lexbuf }
|
||||
| _ as c { print_char c; main lexbuf }
|
||||
|
||||
{
|
||||
let () =
|
||||
set_binary_mode_out stdout true;
|
||||
main (Lexing.from_channel (open_in_bin Sys.argv.(1)))
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
We can show the preprocessed output of a source code
|
||||
|
||||
$ dune describe pp src/main.ml
|
||||
;;Util.log "Hello, world!"
|
||||
|
||||
Re-running the command keeps showing output
|
||||
|
||||
$ dune describe pp src/main.ml
|
||||
;;Util.log "Hello, world!"
|
||||
|
||||
We can also show the original source if it is not preprocessed
|
||||
|
||||
$ dune describe pp src/util.ml
|
||||
let log str = print_endline str
|
||||
|
||||
We also make sure that the dump file is not present
|
||||
|
||||
$ dune_cmd exists profile.dump
|
||||
false
|
||||
|
||||
This also works for reason code
|
||||
|
||||
$ dune describe pp src/main_re.re
|
||||
# 1 "src/main_re.pp.re.ml"
|
||||
# 1 "src/main_re.pp.re"
|
||||
Util.log ("Hello, world!")
|
||||
|
||||
$ dune describe pp lib/subdir/bazy.ml
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executables
|
||||
(names main main_re)
|
||||
(preprocess (action (run pp/pp.exe %{input-file}))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
Util.log _STRING_
|
||||
|
|
@ -0,0 +1 @@
|
|||
Util.log (_STRING_)
|
||||
|
|
@ -0,0 +1 @@
|
|||
let log str = print_endline str
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.8)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(library
|
||||
(name ppx_suffix)
|
||||
(kind ppx_rewriter)
|
||||
(libraries ppxlib))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
open Ppxlib
|
||||
|
||||
let expand ~ctxt s =
|
||||
let loc = Expansion_context.Extension.extension_point_loc ctxt in
|
||||
Ast_builder.Default.estring ~loc (s ^ "_suffixed")
|
||||
|
||||
let my_extension =
|
||||
Extension.V3.declare "add_suffix" Extension.Context.expression
|
||||
Ast_pattern.(single_expr_payload (estring __))
|
||||
expand
|
||||
|
||||
let rule = Ppxlib.Context_free.Rule.extension my_extension
|
||||
let () = Driver.register_transformation ~rules:[ rule ] "add_suffix"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
It should fail with a message that `describe pp` doesn't support `staged_pps`.
|
||||
|
||||
$ dune describe pp src/main.ml
|
||||
File "src/dune", line 4, characters 2-25:
|
||||
4 | (staged_pps ppx_suffix)))
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Error: staged_pps are not supported.
|
||||
[1]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(library
|
||||
(name main)
|
||||
(preprocess
|
||||
(staged_pps ppx_suffix)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
let () = print_string [%add_suffix "hello"]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(cram
|
||||
(applies_to describe-pp)
|
||||
(deps %{bin:refmt}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue