caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] analyzing Camlp4 nodes
@ 2012-07-13  8:48 Dan Bensen
  2012-07-13 10:12 ` Gabriel Scherer
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Bensen @ 2012-07-13  8:48 UTC (permalink / raw)
  To: caml-list

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

Is there a way to compare a Camlp4 ast node to a quotation 
that ignores the locations?
Camlp4 seems to rely on quotations as much as possible, 
but it seems like you have to either compare a quotation 
with another quotation, so they have the same location, 
or write out the ast code explicitly.

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

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

* Re: [Caml-list] analyzing Camlp4 nodes
  2012-07-13  8:48 [Caml-list] analyzing Camlp4 nodes Dan Bensen
@ 2012-07-13 10:12 ` Gabriel Scherer
  2012-07-13 10:24   ` Wojciech Meyer
  2012-07-13 11:10   ` Dan Bensen
  0 siblings, 2 replies; 4+ messages in thread
From: Gabriel Scherer @ 2012-07-13 10:12 UTC (permalink / raw)
  To: Dan Bensen; +Cc: caml-list

I'm sorry but I don't understand your question.
What do you mean by "comparing" ast nodes? Is it an equality/ordering
test between the node as OCaml values?
I don't understand what you mean by the idea of "a quotation and
another quotation" having "the same location".
Maybe a concrete example would be clearer.

If your question is: how do I text that two pieces of ASTs are equal
*modulo* the location (the term structure is the same but the
locations are allowed to be different), then you can do that by
erasing the locations. Untested code:

  let strip_locations = Ast.map_loc (fun _ -> Loc.ghost)
  let equal_modulo_loc a b = (strip_locations a) = (strip_locations b)

On Fri, Jul 13, 2012 at 10:48 AM, Dan Bensen <danbensen@att.net> wrote:
>
> Is there a way to compare a Camlp4 ast node to a quotation
> that ignores the locations?
> Camlp4 seems to rely on quotations as much as possible,
> but it seems like you have to either compare a quotation
> with another quotation, so they have the same location,
> or write out the ast code explicitly.

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

* Re: [Caml-list] analyzing Camlp4 nodes
  2012-07-13 10:12 ` Gabriel Scherer
@ 2012-07-13 10:24   ` Wojciech Meyer
  2012-07-13 11:10   ` Dan Bensen
  1 sibling, 0 replies; 4+ messages in thread
From: Wojciech Meyer @ 2012-07-13 10:24 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: Dan Bensen, caml-list

There is Camlp4LocationStripper.ml filter in Camlp4/Filters.

On Fri, Jul 13, 2012 at 11:12 AM, Gabriel Scherer
<gabriel.scherer@gmail.com> wrote:
> I'm sorry but I don't understand your question.
> What do you mean by "comparing" ast nodes? Is it an equality/ordering
> test between the node as OCaml values?
> I don't understand what you mean by the idea of "a quotation and
> another quotation" having "the same location".
> Maybe a concrete example would be clearer.
>
> If your question is: how do I text that two pieces of ASTs are equal
> *modulo* the location (the term structure is the same but the
> locations are allowed to be different), then you can do that by
> erasing the locations. Untested code:
>
>   let strip_locations = Ast.map_loc (fun _ -> Loc.ghost)
>   let equal_modulo_loc a b = (strip_locations a) = (strip_locations b)
>
> On Fri, Jul 13, 2012 at 10:48 AM, Dan Bensen <danbensen@att.net> wrote:
>>
>> Is there a way to compare a Camlp4 ast node to a quotation
>> that ignores the locations?
>> Camlp4 seems to rely on quotations as much as possible,
>> but it seems like you have to either compare a quotation
>> with another quotation, so they have the same location,
>> or write out the ast code explicitly.
>
> --
> 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] 4+ messages in thread

* Re: [Caml-list] analyzing Camlp4 nodes
  2012-07-13 10:12 ` Gabriel Scherer
  2012-07-13 10:24   ` Wojciech Meyer
@ 2012-07-13 11:10   ` Dan Bensen
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Bensen @ 2012-07-13 11:10 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

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

> > Is there a way to compare a Camlp4 ast node to a quotation
> > that ignores the locations?

> If your question is: how do I text that two pieces of ASTs are equal
> *modulo* the location (the term structure is the same but the
> locations are allowed to be different), then you can do that by
> erasing the locations. Untested code:
> 
>   let strip_locations = Ast.map_loc (fun _ -> Loc.ghost)
>   let equal_modulo_loc a b = (strip_locations a) = (strip_locations b)

Yes, that's it.  Thanks.

(sorry about the double post)

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

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

end of thread, other threads:[~2012-07-13 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13  8:48 [Caml-list] analyzing Camlp4 nodes Dan Bensen
2012-07-13 10:12 ` Gabriel Scherer
2012-07-13 10:24   ` Wojciech Meyer
2012-07-13 11:10   ` Dan Bensen

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