Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] camlp4 -- troubles with printer
@ 2002-09-11 16:59 Max Kirillov
  2002-09-12 14:36 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 3+ messages in thread
From: Max Kirillov @ 2002-09-11 16:59 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

Hello.

Let's consider the attached file. It splits a file at words
"WHERE", reverses the order of the pieces, and concat them
back.

Trying to print the result, I got an error:

: $cat test.ml 
: let _ = print_string "1\n"; flush stdout
: WHERE
: let _ = print_string "2\n"; flush stdout
: $camlp4o ./syntax1.cmo pr_o.cmo test.ml                                 
: let _ = print_string "1\n"; flush stdout
: WHERE
: let _ = print_string "2\n"; flush stdoutUncaught exception: End_of_file

But, the code works:

: $ocamlc -pp "camlp4o ./syntax1.cmo"  test.ml
: $./a.out 
: 2
: 1

More complex code works as well, but the printing always fails.

I suspect this is due to 'loc' values are not accendind. The
error is displayed at ocaml-3.06 as well as ocaml-3.04

Max.

[-- Attachment #2: syntax1.ml --]
[-- Type: text/plain, Size: 1056 bytes --]

(*
    ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c syntax1.ml
*)

open Pcaml;;

EXTEND
    str_item: LAST
	[[ EOI -> assert false
	| "WHERE" -> <:str_item< $lid:"wHERE"$ >> ]];
END;;

(* generally, this splits a list, then reverses the large parts
    and concat  them back *)
let wrap f x = 
    let split pred l =
    (* cound not found it *)
	let rec s1 rl add argl = 
	    try let e = List.hd argl
		and tl = List.tl argl in
		match (pred e,add,rl)
		    with (false,true,rl) -> s1 ([e]::rl) false tl
		    | (false,false,re::rl') -> s1 ((e::re)::rl') false tl
		    | (false,false,[]) -> assert false
		    | (true,false,rl) -> s1 rl true tl
		    | (true,true,rl) -> s1 ([]::rl) true tl
	    with Failure "hd" | Failure "tl" -> rl
	in
	s1 [] true l in
    let wrapV (l,fl) =
	let m1 = function (<:str_item< $lid:"wHERE"$ >>,_) -> true
			| _ -> false in
	let (&>) f1 f2 x = f2 (f1 x) in
	let res = (split m1 &> List.map List.rev &> List.concat) l in
	(res,fl) in
    wrapV (f x);;

Pcaml.parse_implem := wrap (!Pcaml.parse_implem);;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-12 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-11 16:59 [Caml-list] camlp4 -- troubles with printer Max Kirillov
2002-09-12 14:36 ` Daniel de Rauglaudre
2002-09-12 17:59   ` Max Kirillov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox