caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 char stream
@ 2005-09-11 20:19 Christophe Raffalli
  2005-09-11 21:51 ` [Caml-list] " Martin Jambon
  0 siblings, 1 reply; 6+ messages in thread
From: Christophe Raffalli @ 2005-09-11 20:19 UTC (permalink / raw)
  To: caml-list


I would like to know how I can access directly the input char stream in 
camlp4

i want a

c-code { ... }

producing an empty str_item, but consuming the c-code in the { ... "} 
and outputing it in a separate file. An easy way is to access directly 
the char stream, but I do not find it (actually, looking at the source 
it is not stored in an accessible variable.

Someonce see a solution, other that parsing a string ?

[ [ c_code STRING -> ... ] ] would be easy, but is not very satisfactory.



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

* Re: [Caml-list] camlp4 char stream
  2005-09-11 20:19 camlp4 char stream Christophe Raffalli
@ 2005-09-11 21:51 ` Martin Jambon
  2005-09-12  5:39   ` Christophe Raffalli
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Jambon @ 2005-09-11 21:51 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

On Sun, 11 Sep 2005, Christophe Raffalli wrote:

> I would like to know how I can access directly the input char stream in 
> camlp4
>
> i want a
>
> c-code { ... }
>
> producing an empty str_item, but consuming the c-code in the { ... "} and 
> outputing it in a separate file. An easy way is to access directly the char 
> stream, but I do not find it (actually, looking at the source it is not 
> stored in an accessible variable.
>
> Someonce see a solution, other that parsing a string ?
>
> [ [ c_code STRING -> ... ] ] would be easy, but is not very satisfactory.

See paragraph "Do it yourself" at
http://wwwtcs.inf.tu-dresden.de/~tews/ocamlp4/camlp4-undoc.html#power



Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr


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

* Re: [Caml-list] camlp4 char stream
  2005-09-11 21:51 ` [Caml-list] " Martin Jambon
@ 2005-09-12  5:39   ` Christophe Raffalli
  2005-09-12  6:40     ` Martin Jambon
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe Raffalli @ 2005-09-12  5:39 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list


OK, I found it (quote from your tutorial):

let operator_rparen =
   Grammar.Entry.of_parser gram "operator_rparen"
     (fun strm ->
        match Stream.npeek 2 strm with
	 | [("", s); ("", ")")] when is_operator s ->
	     begin
	       Stream.junk strm;
	       Stream.junk strm;
	       s
	     end
	 | _ -> raise Stream.Failure)

OK, I read your tutorial, but did not get the point ... thks

and what is the first member of the tuple ?
Why is the second member a string and not a char ?

> 
> See paragraph "Do it yourself" at
> http://wwwtcs.inf.tu-dresden.de/~tews/ocamlp4/camlp4-undoc.html#power
> 
> 
> 
> Martin
> 
> -- 
> Martin Jambon, PhD
> http://martin.jambon.free.fr


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

* Re: [Caml-list] camlp4 char stream
  2005-09-12  5:39   ` Christophe Raffalli
@ 2005-09-12  6:40     ` Martin Jambon
  2005-09-12 13:27     ` Olivier Andrieu
  2005-09-12 22:31     ` Pietro Abate
  2 siblings, 0 replies; 6+ messages in thread
From: Martin Jambon @ 2005-09-12  6:40 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: Martin Jambon, caml-list

On Mon, 12 Sep 2005, Christophe Raffalli wrote:

> OK, I found it (quote from your tutorial):
>
> let operator_rparen =
>  Grammar.Entry.of_parser gram "operator_rparen"
>    (fun strm ->
>       match Stream.npeek 2 strm with
> 	 | [("", s); ("", ")")] when is_operator s ->
> 	     begin
> 	       Stream.junk strm;
> 	       Stream.junk strm;
> 	       s
> 	     end
> 	 | _ -> raise Stream.Failure)
>
> OK, I read your tutorial, but did not get the point ... thks

It's not my tutorial, it's a page by Hendrik Tews.
And it's my mistake: you don't have access to the char stream like this, 
but to the token stream.

Why not define a quotation expander?


Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr


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

* Re: [Caml-list] camlp4 char stream
  2005-09-12  5:39   ` Christophe Raffalli
  2005-09-12  6:40     ` Martin Jambon
@ 2005-09-12 13:27     ` Olivier Andrieu
  2005-09-12 22:31     ` Pietro Abate
  2 siblings, 0 replies; 6+ messages in thread
From: Olivier Andrieu @ 2005-09-12 13:27 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

 Christophe Raffalli [Monday 12 September 2005] :
 > 
 > OK, I found it (quote from your tutorial):
 > 
 > let operator_rparen =
 >    Grammar.Entry.of_parser gram "operator_rparen"
 >      (fun strm ->
 >         match Stream.npeek 2 strm with
 > 	 | [("", s); ("", ")")] when is_operator s ->
 > 	     begin
 > 	       Stream.junk strm;
 > 	       Stream.junk strm;
 > 	       s
 > 	     end
 > 	 | _ -> raise Stream.Failure)
 > 
 > OK, I read your tutorial, but did not get the point ... thks
 > 
 > and what is the first member of the tuple ?
 > Why is the second member a string and not a char ?

That's just how the camlp4 lexer works, cf. :
  http://caml.inria.fr/pub/docs/manual-camlp4/manual005.html#toc13
  http://caml.inria.fr/pub/docs/manual-camlp4/lib/Plexer.html

If I understand, you'd want to switch to a different lexer (and
parser) at some point. As Martin said, quotation expanders let you
basically do that. But IIRC camlp4 (the program) only expands
quotations in expression or pattern levels, not at the structure item
level so that won't work for you. But the ocpp program (installed with
camlp4) expands quotation in any file (only quotations returning
string of course).

-- 
   Olivier


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

* Re: [Caml-list] camlp4 char stream
  2005-09-12  5:39   ` Christophe Raffalli
  2005-09-12  6:40     ` Martin Jambon
  2005-09-12 13:27     ` Olivier Andrieu
@ 2005-09-12 22:31     ` Pietro Abate
  2 siblings, 0 replies; 6+ messages in thread
From: Pietro Abate @ 2005-09-12 22:31 UTC (permalink / raw)
  To: caml-list, caml-list

If I understand you problem correctly,

here there is a small example to parse string of the type
TEST ------ END 
where ----- can be whatever you want.

http://caml.inria.fr/pub/ml-archives/caml-list/2005/07/244afe98fd8ddfb6aff6f0bcda52d9ac.en.html

read the thread further as you need to add Stream.junk strm to the
function test.

this way you can basically switch to an other parser (to parse "----" )
and get back to camlp4.

hope it helps.

:)
p

On Mon, Sep 12, 2005 at 07:39:35AM +0200, Christophe Raffalli wrote:
> 
> OK, I found it (quote from your tutorial):
> 
> let operator_rparen =
>   Grammar.Entry.of_parser gram "operator_rparen"
>     (fun strm ->
>        match Stream.npeek 2 strm with
> 	 | [("", s); ("", ")")] when is_operator s ->
> 	     begin
> 	       Stream.junk strm;
> 	       Stream.junk strm;
> 	       s
> 	     end
> 	 | _ -> raise Stream.Failure)
> 
> OK, I read your tutorial, but did not get the point ... thks
> 
> and what is the first member of the tuple ?
> Why is the second member a string and not a char ?
> 
> >
> >See paragraph "Do it yourself" at
> >http://wwwtcs.inf.tu-dresden.de/~tews/ocamlp4/camlp4-undoc.html#power
> >
> >
> >
> >Martin
> >
> >-- 
> >Martin Jambon, PhD
> >http://martin.jambon.free.fr
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

-- 
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++ 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html


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

end of thread, other threads:[~2005-09-12 22:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-11 20:19 camlp4 char stream Christophe Raffalli
2005-09-11 21:51 ` [Caml-list] " Martin Jambon
2005-09-12  5:39   ` Christophe Raffalli
2005-09-12  6:40     ` Martin Jambon
2005-09-12 13:27     ` Olivier Andrieu
2005-09-12 22:31     ` Pietro Abate

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).