caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Camlp4 questions
@ 2002-02-08 21:24 Harrison, John R
  2002-02-09 10:30 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 7+ messages in thread
From: Harrison, John R @ 2002-02-08 21:24 UTC (permalink / raw)
  To: 'caml-list@inria.fr'; +Cc: Harrison, John R, 'johnh

I've recently been porting HOL Light from CAML Light to OCaml. Since HOL
relies heavily on the use of uppercase value identifiers and infix
alphanumeric identifiers, I had to use Camlp4 to make some syntax
modifications. This works fine, and I was also able to fix up the lexer
so that quotations are accepted using `...` rather than <<...>>. (The
former is standard for HOL, and looks more natural to the Anglo-Saxon
eye, James Joyce excepted.) Nevertheless, my modifications were made by
fairly naive brutish hacking, and I wondered if there are more elegant
ways of doing things. In particular:

1. There is an example of adding new infixes in section 4.3.1 of the
   Camlp4 documentation. However following this example still left 
   two problems. First, the level of precedence was unexpectedly
   high, with "f x o g y" not parsing as "(f x) o (g y)" as expected.
   I changed this by using AFTER "<" instead of AFTER "apply", which
   seemed to work, but is that the recommended solution? Secondly,
   enclosing the new infix in parentheses to suppress its infix
   status, e.g. "(o)", doesn't work; it still expects an operator
   name. It was easy enough to hack the parser a bit more, but is
   there a nice solution using simple extensions?

2. Most of my changes are at the lexical level. Yet the only way I
   could figure out of changing the lexer was to rebuild the CAML
   parser in "camlp4/etc/pa_o.ml" from scratch with a new lexer and
   additional modifications. Is it possible to change the lexer but
   otherwise make only simple extensions? This is for the toplevel,
   by the way.

John.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Camlp4 questions
  2002-02-08 21:24 [Caml-list] Camlp4 questions Harrison, John R
@ 2002-02-09 10:30 ` Daniel de Rauglaudre
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel de Rauglaudre @ 2002-02-09 10:30 UTC (permalink / raw)
  To: caml-list

Hi,

>    I changed this by using AFTER "<" instead of AFTER "apply", which
>    seemed to work, but is that the recommended solution?

Yes.

> Secondly, enclosing the new infix in parentheses to suppress its
> infix status, e.g. "(o)", doesn't work; it still expects an operator
> name. It was easy enough to hack the parser a bit more, but is there
> a nice solution using simple extensions?

Yes, the fact to accept an added infix between parentheses is not
automatic and you have to add a grammar rule to parse that. At the
expr level "simple". It should work, but I have not tested.

> 2. Most of my changes are at the lexical level. Yet the only way I
>    could figure out of changing the lexer was to rebuild the CAML
>    parser in "camlp4/etc/pa_o.ml" from scratch with a new lexer and
>    additional modifications. Is it possible to change the lexer but
>    otherwise make only simple extensions? This is for the toplevel,
>    by the way.

The lexer Plexer is not extensible. It is possible to create an
extensible lexer with extensible grammars but the time performances
are very bad. I would like to find a solution to be able to extend it
without slowing down the system, but for the moment, I have no idea...

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] [Camlp4] questions
  2010-08-06 14:57 [Camlp4] questions Raphael Proust
@ 2010-08-09  7:04 ` Hendrik Tews
  0 siblings, 0 replies; 7+ messages in thread
From: Hendrik Tews @ 2010-08-09  7:04 UTC (permalink / raw)
  To: caml-list

Raphael Proust <raphlalou@gmail.com> writes:

   Is there a (nice) way to input/output multiple files? I managed reading from a
   second file while transforming one but the code is (really) ugly.

How about

    let start_loc_1 = Syntax.Loc.mkloc file_1 in
    let stream_1 = Stream.of_channel (open_in file_1) in
    let ast_1 = Syntax.parse_implem start_loc_1 stream_1 in

    let start_loc_2 = Syntax.Loc.mkloc file_2 in
    let stream_2 = Stream.of_channel (open_in file_2) in
    let ast_2 = Syntax.parse_implem start_loc_2 stream_2


   For those who ever need it camlunity as the ocamldoc online:
   http://camlunity.ru/camlp4/

Nice, but the main camlp4 problem still needs to be fixed: The
sources are almost not documented. Just look at
http://camlunity.ru/camlp4/Camlp4.html, it _only_ says

   Add an option to the command line options.

;-0

BTW, where are all the modules from the Camlp4Parsers directory,
eg Camlp4OCamlParser?

Bye,

Hendrik


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

* Re: [Caml-list] camlp4 questions
  2008-04-04  7:59 Conglun Yao
  2008-04-04  8:38 ` [Caml-list] " Richard Jones
@ 2008-04-04 13:42 ` Nicolas Pouillard
  1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Pouillard @ 2008-04-04 13:42 UTC (permalink / raw)
  To: Conglun Yao; +Cc: Caml_mailing list

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

Excerpts from Conglun Yao's message of Fri Apr 04 09:59:09 +0200 2008:
> Hi,

Hi,

> While doing my little camlp4 (3.10) practice, I had the following questions:
> 

[...]

> (2) How to extend operators like '@', for example if I want to change the
> expression
> list_1 @ list_2 => List.append list_1 list_2
> 
> In 3.09, it could be achieved by deleting rules
> DELETE_RULE Gram expr: SELF; "@"; SELF END
> 
> however, in 3.10, it seems I can't find the above grammar, only can find in
> Camlp4OCamlParser.ml
> expr: AFTER "^"
> [ "::" RIGHTA
> [ e1 = SELF; "::"; e2 = SELF -> <:expr< [$e1$ :: $e2$] >> ]
> ];

You   should   have   to  also  check  in  Camlp4OCamlRevisedParser.ml,  since
Camlp4OCamlParser.ml is now just an extension of the former.

> Furthermore, if I want to extend the expr: "["; sem_expr_for_list; "]",
> where to find the rule definition.
> In 3.09, all of these exist in pa_o.ml

Same answer.

Regards,

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

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

* Re: [Caml-list] camlp4 questions
  2008-04-04  8:38 ` [Caml-list] " Richard Jones
@ 2008-04-04  9:56   ` Conglun Yao
  0 siblings, 0 replies; 7+ messages in thread
From: Conglun Yao @ 2008-04-04  9:56 UTC (permalink / raw)
  To: caml-list

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

Thanks for your quick response.

Sorry, I thought these two caml-list & ocaml-beginners were different
mail-list.

And Is there any suggestion for the second problem.

Conglun

On Fri, Apr 4, 2008 at 9:38 AM, Richard Jones <rich@annexia.org> wrote:

> On Fri, Apr 04, 2008 at 08:59:09AM +0100, Conglun Yao wrote:
> > While doing my little camlp4 (3.10) practice, I had the following
> questions:
>
> You don't need to post the same message on both caml-list &
> ocaml-beginners.
>
> > (1) Is there a simple approach to add some 'open' directive at the
> beginning
> > of file.
>
> This was raised on ocaml-beginners last week and the answer is here:
>
> http://tech.groups.yahoo.com/group/ocaml_beginners/message/9558
>
> Rich.
>
> --
> Richard Jones
> Red Hat
>
> _______________________________________________
> 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
>

[-- Attachment #2: Type: text/html, Size: 1839 bytes --]

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

* Re: [Caml-list] camlp4 questions
  2008-04-04  7:59 Conglun Yao
@ 2008-04-04  8:38 ` Richard Jones
  2008-04-04  9:56   ` Conglun Yao
  2008-04-04 13:42 ` Nicolas Pouillard
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Jones @ 2008-04-04  8:38 UTC (permalink / raw)
  To: caml-list

On Fri, Apr 04, 2008 at 08:59:09AM +0100, Conglun Yao wrote:
> While doing my little camlp4 (3.10) practice, I had the following questions:

You don't need to post the same message on both caml-list &
ocaml-beginners.

> (1) Is there a simple approach to add some 'open' directive at the beginning
> of file.

This was raised on ocaml-beginners last week and the answer is here:

http://tech.groups.yahoo.com/group/ocaml_beginners/message/9558

Rich.

-- 
Richard Jones
Red Hat


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

* Re: [Caml-list] camlp4 questions
  2007-07-23  9:46 camlp4 questions Christophe Raffalli
@ 2007-07-25  8:29 ` Nicolas Pouillard
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Pouillard @ 2007-07-25  8:29 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

On 7/23/07, Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr> wrote:
>
> Dear list members,
>
> I am finishing to port binlib to camlp4 of 3.10 and have a few problems
> left :
>
> 1) a bug in my extension, I have:
>
[...]

> produces the following error message:
>
> File "programs.ml", line 1259, characters 1-48:
> Failure: "expr, expr: not allowed here"
> Preprocessor error

This is because a comma node as been encountered << $_$, $_$ >>
without it's surrounding tuple node << ($tup:_$) >>. In other words
you have to put more parenthesis in your extension.

> 2) with 3.09 I used to produce a bytecode similar to camlp4o with my
> extension buildin. I could not find
> the proper line to compile this bytecode (I tried to copy the compile
> line of camlp4o and to add
> pa_bindlib.cmo somewhere, but I failed)

Jeremy Yallop has explained this in a previous email [1] while
building deriving, it will be soon integrated to the documentation.

[1]: http://caml.inria.fr/pub/ml-archives/caml-list/2007/06/a568d6eb0631a9a4ea0542109695a76f.fr.html

> 3) I like the fact that my new delimiter "(^", "^)", ... are now
> supported by the standard lexer of camlp4, But I think
> that spaces should not be mandatory between delimiters and therefore,
> keywords should only be allowed to contain
> one "(", "{" or "[" at the beginning and/or one ")","}","]" at the end.
> Still, I prefer the 3.10 version needing a few extra spaces that having
> to rewrite my own lexer.

I don't know how to do that without breaking any existing OCaml source code.

Regards,

-- 
Nicolas Pouillard


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

end of thread, other threads:[~2010-08-09  7:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-08 21:24 [Caml-list] Camlp4 questions Harrison, John R
2002-02-09 10:30 ` Daniel de Rauglaudre
2007-07-23  9:46 camlp4 questions Christophe Raffalli
2007-07-25  8:29 ` [Caml-list] " Nicolas Pouillard
2008-04-04  7:59 Conglun Yao
2008-04-04  8:38 ` [Caml-list] " Richard Jones
2008-04-04  9:56   ` Conglun Yao
2008-04-04 13:42 ` Nicolas Pouillard
2010-08-06 14:57 [Camlp4] questions Raphael Proust
2010-08-09  7:04 ` [Caml-list] " Hendrik Tews

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