From: Rodolphe Lepigre <rodolphe.lepigre@univ-savoie.fr>
To: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Parsetree comparison
Date: Thu, 6 Nov 2014 18:21:30 +0100 [thread overview]
Message-ID: <20141106172130.GA32182@HPArchRod> (raw)
In-Reply-To: <545BAA3D.5070606@tu-berlin.de>
Hi,
> is there a way to compare two abstract syntax trees for equality
> without taking into account locations? Or rather a way to stratify the
> location information inside a parsetree? I want to unit-test a parser
> that invokes the OCaml parser itself.
One quick, dirty and hackish way to do that is to use the -dparsetree option
to print the parse tree, use sed to remove position indication and the compare
files with diff...
I used that trick to compare the ast generated by an OCaml parser generated
using DeCaP (http://lama.univ-savoie.fr/decap/), and the ast generated by
other OCaml parsers.
Here is the script we used:
##########
#!/bin/bash
ocamlc -dparsetree $1 2> /tmp/$1.ocaml
ocamlc -dparsetree -pp ../pa_ocaml $1 2> /tmp/$1.pa_ocaml
cat /tmp/$1.ocaml | sed -e 's/(.*\.ml\[.*\]\.\.\[.*\])\( ghost\)\?//' > /tmp/$1.ocaml.out
cat /tmp/$1.pa_ocaml | sed -e 's/(.*\.ml\[.*\]\.\.\[.*\])\( ghost\)\?//' > /tmp/$1.pa_ocaml.out
# diff -y /tmp/$1.ocaml.out /tmp/$1.pa_ocaml.out | less
diff $2 /tmp/$1.ocaml.out /tmp/$1.pa_ocaml.out
##########
Regards,
Rodolphe
--
Rodolphe Lepigre
LAMA, Université de Savoie, FRANCE
http://lama.univ-savoie.fr/~lepigre/
prev parent reply other threads:[~2014-11-06 17:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 17:05 Christoph Höger
2014-11-06 17:11 ` Gabriel Scherer
2014-11-06 17:21 ` Rodolphe Lepigre [this message]
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=20141106172130.GA32182@HPArchRod \
--to=rodolphe.lepigre@univ-savoie.fr \
--cc=caml-list@inria.fr \
--cc=christoph.hoeger@tu-berlin.de \
/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