caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Max Kirillov <max630@mail.ru>
To: caml-list@inria.fr
Subject: [Caml-list] camlp4 -- troubles with printer
Date: Wed, 11 Sep 2002 23:59:22 +0700	[thread overview]
Message-ID: <20020911235922.A633@max.home> (raw)

[-- 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);;

             reply	other threads:[~2002-09-11 17:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-11 16:59 Max Kirillov [this message]
2002-09-12 14:36 ` Daniel de Rauglaudre
2002-09-12 17:59   ` Max Kirillov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020911235922.A633@max.home \
    --to=max630@mail.ru \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).