caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Parsetree comparison
@ 2014-11-06 17:05 Christoph Höger
  2014-11-06 17:11 ` Gabriel Scherer
  2014-11-06 17:21 ` Rodolphe Lepigre
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Höger @ 2014-11-06 17:05 UTC (permalink / raw)
  To: caml users

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

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.

regards,

Christoph
- -- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlRbqj0ACgkQhMBO4cVSGS/rZgCfTspQtv/TYKjf8ZgeuF8XbyUE
6UYAn0HNDMobnLCQOSRpyjdAPyoRPRGf
=eXX/
-----END PGP SIGNATURE-----

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

* Re: [Caml-list] Parsetree comparison
  2014-11-06 17:05 [Caml-list] Parsetree comparison Christoph Höger
@ 2014-11-06 17:11 ` Gabriel Scherer
  2014-11-06 17:21 ` Rodolphe Lepigre
  1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Scherer @ 2014-11-06 17:11 UTC (permalink / raw)
  To: Christoph Höger; +Cc: caml users

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

The Ast_mapper module contributed by Alain Frisch to recent versions of the
OCaml distribution allows you to perform arbitrary transformations from AST
to AST in a convenient way. In particular, you could implement a
erase-all-locations pass by simply overloading the "location" method (it
uses object-oriented style for open recursion) to always return a dummy
value.

On Thu, Nov 6, 2014 at 6:05 PM, Christoph Höger <
christoph.hoeger@tu-berlin.de> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dear all,
>
> 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.
>
> regards,
>
> Christoph
> - --
> Christoph Höger
>
> Technische Universität Berlin
> Fakultät IV - Elektrotechnik und Informatik
> Übersetzerbau und Programmiersprachen
>
> Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin
>
> Tel.: +49 (30) 314-24890
> E-Mail: christoph.hoeger@tu-berlin.de
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
>
> iEYEARECAAYFAlRbqj0ACgkQhMBO4cVSGS/rZgCfTspQtv/TYKjf8ZgeuF8XbyUE
> 6UYAn0HNDMobnLCQOSRpyjdAPyoRPRGf
> =eXX/
> -----END PGP SIGNATURE-----
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> 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: 2336 bytes --]

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

* Re: [Caml-list] Parsetree comparison
  2014-11-06 17:05 [Caml-list] Parsetree comparison Christoph Höger
  2014-11-06 17:11 ` Gabriel Scherer
@ 2014-11-06 17:21 ` Rodolphe Lepigre
  1 sibling, 0 replies; 3+ messages in thread
From: Rodolphe Lepigre @ 2014-11-06 17:21 UTC (permalink / raw)
  To: Christoph Höger; +Cc: caml users

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/

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

end of thread, other threads:[~2014-11-06 17:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-06 17:05 [Caml-list] Parsetree comparison Christoph Höger
2014-11-06 17:11 ` Gabriel Scherer
2014-11-06 17:21 ` Rodolphe Lepigre

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