Library
Module
Module type
Parameter
Class
Class type
Code for parsing toplevel expect test files
type chunk = {
part : string option;
The part the chunk is in, None if it's not in any part.
*)phrases : Ppxlib.toplevel_phrase list;
test_node : Ppx_expect_runtime.Test_node.t;
node_loc : Ppxlib.Location.t;
phrases_loc : Ppxlib.Location.t;
}
val expect_node_formatting : Ppx_expect_runtime.Expect_node_formatting.t
val split_chunks :
fname:string ->
Ppxlib.toplevel_phrase list ->
chunk list
* (Ppxlib.toplevel_phrase list * Ppxlib.position * string option) option
Recursively parses toplevel phrases (i.e., contiguous units of code separated by ;;
) into "chunks", one chunk per %%expect
statement.
For example if the mlt contents are:
let x = 1 + 1;;
printf "%d" x + 2;;
[%%expect {|
- : int: 4
|}];;
print_string "f" ^ "o" ^ "o";;
[%%expect {|
- : string: "foo"
|}];;
print_string 3 + 3 + 3;;
then you'd have two chunks, where the first has two phrases ("x = 1 + 1"
and "printf "%d" x + 2"
) and an expectation.body
of ": int 4"
. The second chunk would have just the one phrase.
"print_line 3 + 3 + 3"
is not part of a chunk because there is no expectation following it, so instead it is returned as trailing_code
, which is just a list of toplevel phrases with some position metadata.
"part" refers to @@@part "foo"
statements, which are arbitrary section breaks. Each chunk, and the trailing code, belongs to a part (which is just the empty string ""
if none has been specified).
val sexp_of_mlt_block : mlt_block -> Sexplib0.Sexp.t
val mlt_block_of_sexp : Sexplib0.Sexp.t -> mlt_block
val parse : Ppxlib.toplevel_phrase list -> contents:string -> mlt_block list
Takes a list of toplevel phrases and the raw string they're embedded in and returns a list of labeled blocks, so that for instance the following raw toplevel code:
[%%org {|
Here comes a very /simple/ example.
|}];;
1 + 1;;
[%%expect {|
- : int: 2
|}];;
is parsed into its constituent parts:
[
(Org "Here comes a very /simple/ example.");
(Code "1 + 1");
(Expect "- : int: 2")
]
Note that we only care about these three kinds of element (org blocks, expect blocks, and regular OCaml code blocks); everything else -- including toplevel comments -- is silently discarded.