For example:

result = <strip-annos> empty-list

Now result won’t have origin information anymore.

I’m happy to fix it if somebody can tell me where strip-annos is defined.

Submitted by Oskar van Rest on 17 September 2013 at 20:38

On 17 September 2013 at 20:40 Oskar van Rest tagged stratego


On 17 September 2013 at 23:07 Oskar van Rest commented:

Strange…

strip-annos is implemented like this:

strip-annos = bottomup(rm-annotations)
rm-annotations :  t -> t{}

if I implement it myself as

strip-annos2 = bottomup(rm-annotations2)
rm-annotations2 :  t -> t{}

then everything works fine.

But strip-annos2 = bottomup(rm-annotations) does not work.

Doing a search on Github does not result in any other implementations of rm-annotations.
Could it be the case that STRJ has been changed recently and that the file has not been recompiled afterwards?


On 17 September 2013 at 23:12 Oskar van Rest commented:

When I build to .jar instead of .ctree, my implementation (strip-annos2) also fails.


On 18 September 2013 at 10:18 Lennart Kats commented:

The problem is that origin information isn’t added to the empty list node; see https://github.com/metaborg/mb-rep/blob/master/org.spoofax.terms/src/org/spoofax/terms/attachments/OriginTermFactory.java#L174. It’s only added to leaf nodes of the tree; subnodes of lists. Empty lists are a corner case that’s not currently covered. A problem is that they often are just instances of the singleton object at https://github.com/metaborg/mb-rep/blob/master/org.spoofax.terms/src/org/spoofax/terms/TermFactory.java#L47, so you can’t just write an origin to it.

One runtime solution could be to create a new, unshared object for empty lists in the runtime when origin tracking is enabled. And then check each empty list’s storage type in OriginTermFactory to decide if an origin can be assigned to it. [edit]Note that you would still get a shared object for a literal [] in your Stratego program, since the compiler caches all literals used in fields.[/edit] Other than that, strip-annos could work for unannotated empty lists as long as it doesn’t actually rewrite those into a new object.


On 18 September 2013 at 23:01 Oskar van Rest commented:

Thanks for your help.

I now ‘fixed’ it by changing the implementation of rm-annotations: rm-annotations = ?[]{} <+ ?t; !t{}

This is not the ideal solution, but I tried it by changing OriginTermFactory as you said and got this working, but then it started failing somewhere else because of missing parent attachments (layout preservation algorithm relies on those). I had a look at ParentTermFactory to see if I can fix it there too, but gave up on that because I don’t really know what is going on there and I believe it is also unclear whether we really want to keep supporting parent attachments, so I rather not spend too much time on that.


On 18 September 2013 at 23:01 Oskar van Rest closed this issue.

Log in to post comments