caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] how (within camlp4 printer) can I traverse AST ?
@ 2012-01-31 21:26 Matej Košík
  2012-01-31 22:58 ` Gabriel Scherer
  0 siblings, 1 reply; 5+ messages in thread
From: Matej Košík @ 2012-01-31 21:26 UTC (permalink / raw)
  To: caml-list

Hello,

I would like to write a (camlp4 pluggable) printer.

My starting-point is this:

http://brion.inria.fr/gallium/index.php/Setup_a_new_printer

It was easy to figure out that "ast" arguments have type "Ast.sig_item"
or "Ast.str_item" respectively which are both abstract types
http://camlunity.ru/doc/camlp4-3.12/Camlp4.Sig.Ast.html
so I cannot try to match them---I cannot use any of the constructors
defined in:

http://camlunity.ru/doc/camlp4-3.12/Camlp4.Sig.Camlp4Ast.html

What is thus a proper way of traversing ASTs?

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

* Re: [Caml-list] how (within camlp4 printer) can I traverse AST ?
  2012-01-31 21:26 [Caml-list] how (within camlp4 printer) can I traverse AST ? Matej Košík
@ 2012-01-31 22:58 ` Gabriel Scherer
  2012-02-01 12:01   ` Matej Košík
  0 siblings, 1 reply; 5+ messages in thread
From: Gabriel Scherer @ 2012-01-31 22:58 UTC (permalink / raw)
  To: Matej Košík; +Cc: caml-list

Sig.Ast is the most general structure available, that you use if you
want to manipulate any kind of grammar for Camlp4. If you know the AST
you're manipulating corresponds to an OCaml program, you should use
the more specific Sig.Camlp4Ast signature (as advertized in the
documentation page for Sig.Ast, btw.). Registering a printer for
Sig.Camlp4Ast is done with Register.OcamlPrinter, and if you want to
see a full-blown example of printer, you just have too look at
camlp4/Camlp4/Printers/OCaml.ml in the ocaml source.

On Tue, Jan 31, 2012 at 10:26 PM, Matej Košík
<5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> Hello,
>
> I would like to write a (camlp4 pluggable) printer.
>
> My starting-point is this:
>
> http://brion.inria.fr/gallium/index.php/Setup_a_new_printer
>
> It was easy to figure out that "ast" arguments have type "Ast.sig_item"
> or "Ast.str_item" respectively which are both abstract types
> http://camlunity.ru/doc/camlp4-3.12/Camlp4.Sig.Ast.html
> so I cannot try to match them---I cannot use any of the constructors
> defined in:
>
> http://camlunity.ru/doc/camlp4-3.12/Camlp4.Sig.Camlp4Ast.html
>
> What is thus a proper way of traversing ASTs?
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


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

* Re: [Caml-list] how (within camlp4 printer) can I traverse AST ?
  2012-01-31 22:58 ` Gabriel Scherer
@ 2012-02-01 12:01   ` Matej Košík
  2012-02-02 16:38     ` Gabriel Scherer
  2012-02-13  9:34     ` Hendrik Tews
  0 siblings, 2 replies; 5+ messages in thread
From: Matej Košík @ 2012-02-01 12:01 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

On 01/31/2012 10:58 PM, Gabriel Scherer wrote:
> Sig.Ast is the most general structure available, that you use if you
> want to manipulate any kind of grammar for Camlp4. If you know the AST
> you're manipulating corresponds to an OCaml program, you should use
> the more specific Sig.Camlp4Ast signature (as advertized in the
> documentation page for Sig.Ast, btw.). Registering a printer for
> Sig.Camlp4Ast is done with Register.OcamlPrinter, and if you want to
> see a full-blown example of printer, you just have too look at
> camlp4/Camlp4/Printers/OCaml.ml in the ocaml source.

Thank you.

Concerning camlp4/Camlp4/Printers*.ml I am struggling with two problems:

1. these examples are not compiled with ordinary ocamlc/camlp4 tools but
with special ocamlc/camlp4* version built at the "boot time" which are
not interchangeable with regular ocamlc/camlp4* programs. If I try to
use regular ocamlc/camlp4* tools in an attempt to compile those
printers, I will get syntax errors in those printers.

2. the code that registers the printers is not in printers themselves
but it is located in another file, in another context and it is not
obvious how to achieve this action in the context of the code of
individual printers (in an analogous way how sample printer
  http://brion.inria.fr/gallium/index.php/Setup_a_new_printer
directly registers itself.

How would the printer described here:
  http://brion.inria.fr/gallium/index.php/Setup_a_new_printer
look like if I wanted to use concrete instead of abstract syntax---like in:
- DumpOCamlAst
- OCaml.ml
- OCamlr.ml
?

(So that presumably I can compile the printer as shown in the HOWTO.)

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

* Re: [Caml-list] how (within camlp4 printer) can I traverse AST ?
  2012-02-01 12:01   ` Matej Košík
@ 2012-02-02 16:38     ` Gabriel Scherer
  2012-02-13  9:34     ` Hendrik Tews
  1 sibling, 0 replies; 5+ messages in thread
From: Gabriel Scherer @ 2012-02-02 16:38 UTC (permalink / raw)
  To: Matej Košík; +Cc: caml-list

I think that just replacing Camlp4.Sig.Syntax and
Camlp4.Register.Printer by Camlp4.Sig.Camlp4Syntax and
Camlp4.Register.OCamlPrinter works.

I'm not sure what you mean by "using concrete instead of abstract
syntax"; if you mean using quotations instead of writing the AST
constructor names in full, then that is not related to printers
specifically. Feel free to look at existing syntax extensions, such as
http://bluestorm.info/camlp4/list.php , for inspiration. But none of
them, if I remember correctly, touch the printers.

On Wed, Feb 1, 2012 at 1:01 PM, Matej Košík
<5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> On 01/31/2012 10:58 PM, Gabriel Scherer wrote:
>> Sig.Ast is the most general structure available, that you use if you
>> want to manipulate any kind of grammar for Camlp4. If you know the AST
>> you're manipulating corresponds to an OCaml program, you should use
>> the more specific Sig.Camlp4Ast signature (as advertized in the
>> documentation page for Sig.Ast, btw.). Registering a printer for
>> Sig.Camlp4Ast is done with Register.OcamlPrinter, and if you want to
>> see a full-blown example of printer, you just have too look at
>> camlp4/Camlp4/Printers/OCaml.ml in the ocaml source.
>
> Thank you.
>
> Concerning camlp4/Camlp4/Printers*.ml I am struggling with two problems:
>
> 1. these examples are not compiled with ordinary ocamlc/camlp4 tools but
> with special ocamlc/camlp4* version built at the "boot time" which are
> not interchangeable with regular ocamlc/camlp4* programs. If I try to
> use regular ocamlc/camlp4* tools in an attempt to compile those
> printers, I will get syntax errors in those printers.
>
> 2. the code that registers the printers is not in printers themselves
> but it is located in another file, in another context and it is not
> obvious how to achieve this action in the context of the code of
> individual printers (in an analogous way how sample printer
>  http://brion.inria.fr/gallium/index.php/Setup_a_new_printer
> directly registers itself.
>
> How would the printer described here:
>  http://brion.inria.fr/gallium/index.php/Setup_a_new_printer
> look like if I wanted to use concrete instead of abstract syntax---like in:
> - DumpOCamlAst
> - OCaml.ml
> - OCamlr.ml
> ?
>
> (So that presumably I can compile the printer as shown in the HOWTO.)


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

* Re: [Caml-list] how (within camlp4 printer) can I traverse AST ?
  2012-02-01 12:01   ` Matej Košík
  2012-02-02 16:38     ` Gabriel Scherer
@ 2012-02-13  9:34     ` Hendrik Tews
  1 sibling, 0 replies; 5+ messages in thread
From: Hendrik Tews @ 2012-02-13  9:34 UTC (permalink / raw)
  To: caml-list

Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> writes:

   1. these examples are not compiled with ordinary ocamlc/camlp4 tools but
   with special ocamlc/camlp4* version built at the "boot time" which are
   not interchangeable with regular ocamlc/camlp4* programs. If I try to
   use regular ocamlc/camlp4* tools in an attempt to compile those
   printers, I will get syntax errors in those printers.

I can compile camlp4/Camlp4/Printers/OCaml.{mli,ml} from 3.12.1
with an installed version of 3.12.1 as follows:

- Add ``open Camlp4;'' as first line in OCaml.mli and OCaml.ml
- In directory camlp4/Camlp4/Printers, compile with
   ocamlc -c -pp camlp4rf -I +camlp4 OCaml.mli
   ocamlc -c -pp camlp4rf -I +camlp4 OCaml.ml

The ``open'' is only necessary because the OCaml installation
procedure does not install all compiled module interfaces. 

Bye,

Hendrik


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

end of thread, other threads:[~2012-02-13  9:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 21:26 [Caml-list] how (within camlp4 printer) can I traverse AST ? Matej Košík
2012-01-31 22:58 ` Gabriel Scherer
2012-02-01 12:01   ` Matej Košík
2012-02-02 16:38     ` Gabriel Scherer
2012-02-13  9:34     ` 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).