How can I find the cause for a failing pretty-printing strategy?
I try to translate a DSL to another language. Parsing the source file into ATerm is okay, but rewriting fails and I try to find out where the error is. Rule
genPcd
is defined. And to my knowledge,pp_java
and so
on may be related to tools such asast2abox
andabox2text
. So how can I locate errors ?PS: The transformation is developed with
libjava-front
andlibaspectj-front
. To be specific, the DSL
extends Java and is transformed to AspectJ with the help of Spoofax.Console output:
Asked by Guido Wachsmuth on 31 July 2013 at 05:40EventCJ: rewriting failed, trace: generate_java_0_0 to_java_0_0 map_1_0 map_1_0 genPcd_0_3 pp_java_string_0_0 pp_java5_to_string_0_0 box2text_string_0_1 abox2text_0_1 abox2text_1_2 abox2text_list_1_2
1 Answer
The trace tells us that pretty-printing fails. Typically, this is caused by an erroneous AST, which contains terms which cannot be handled by the pretty-printer. To find such terms, you can use the following code:
output := <the-pp-strategy> input <+ <bottomup(try(not(is-string) ; not(is-list) ; not(the-pp-strategy) ; debug(!"cannot pp "))); fail> input
Make sure to replace
Answered by Guido Wachsmuth on 31 July 2013 at 05:47the-pp-strategy
with your actual pretty-printing strategy. The second line performs a bottomup traversal and tries to find terms which cannot be pretty-printed and reports those terms to the console (debug
).