[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Sylvain LE GALL <sylvain.le-gall@p...> |
| Subject: | Re: [Caml-list] parsing OCaml code |
Hello,
On Tue, Jul 19, 2005 at 01:05:58PM -0400, Nathaniel J. Gaylinn wrote:
>
> I'm trying to figure out a nice way to parse OCaml code in a C++ program.
> All I need is a very basic parse tree for use in syntax highlighting and
> indenting OCaml code.
>
> I would love to make use of some of the programs that already come with
> OCaml. For instance, ocamlc and camlp4 can both output OCaml parse trees
> already! The only problem is the formats that these programs output are
> (to my knowledge) completely undocumented.
>
> If I don't use these programs, I could always try using Lex and Yacc to do
> the job, but I'm completely unfamiliar with these utilities and it would
> take me quite some time to write input for parsing OCaml.
>
> Does anyone know where I could find reference to the various OCaml parse
> tree formats? Does anyone know where I could find Yacc grammar
> descriptions of OCaml, or would I have to write them myself? Does anyone
> have any other suggestions of how to tackle the parsing problem?
>
You should have a look to ocaml-ast-analyze
(http://www.carva.org/sylvain.le-gall/ocaml-ast-analyze.html). It is a
module build around camlp4 which can overridde the output of camlp4 (ie
it can replace pr_dump.cmo for example).
I use it to analyze ocaml code in order to find functions (which are
"s_", "f_"... ) followed by a string (s_ 'Coucou') and output only the
string ("msgstrid 'Coucou').
I think it is very useful to do analysis on Ocaml AST.
There is no documentation, but i am planning to write some.
Kind regard
Sylvain Le Gall