summaryrefslogtreecommitdiff
path: root/testsuite/tests/parsing/reloc.ml
blob: 0948d171b496a591ce4c050f18472a334eec889e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(* TEST
   flags = "-I ${ocamlsrcdir}/parsing -I ${ocamlsrcdir}/toplevel"
   include ocamlcommon
   * expect
*)

(* Check that [e.pexp_loc :: e.pexp_loc_stack] includes all
   intermediate locations of an expression. *)

let blocks =
  let s = {| ( (* comment *) (( "contant" [@attr] )  (* comment *))) |} in
  let e = Parse.expression (Lexing.from_string s) in
  let extract (loc : Location.t) =
    let a = loc.loc_start.pos_cnum in
    let b = loc.loc_end.pos_cnum in
    String.sub s a (b - a)
  in
  List.map extract (e.pexp_loc :: e.pexp_loc_stack)
;;
[%%expect {|
val blocks : string list =
  ["( (* comment *) (( \"contant\" [@attr] )  (* comment *)))";
   "(( \"contant\" [@attr] )  (* comment *))"; "( \"contant\" [@attr] )";
   "\"contant\""]
|}];;