Pretty-Print does not parenthesize
A test project can be found at: https://github.com/arian/spoofax-parens-bug
Related by in my own project: https://github.com/arian/metac/issues/25Consider the program:
(1 + 2) * 3
This can be parsed with SDF3 by:
module parens-test imports Common context-free start-symbols Expr context-free syntax Expr = <(<Expr>)> {bracket} Expr.Plus = <<Expr> + <Expr>> {left} Expr.Mult = <<Expr> * <Expr>> {left} Expr.Num = INT context-free priorities { left: Expr.Mult } > { left: Expr.Plus }
The AST will look as follows, which is expected:
Mult(Plus(Num("1"), Num("2")), Num("2"))
However when running the
pp-debug
rule on this AST, the result is:1 + 2 * 3
Which has not same meaning as the original expression.
Submitted by Arian on 23 December 2015 at 12:39
pp-parens-test-string
runsparenthesize-parens-test
from include/parens-test-parenethesize, but that rule is justid
, so does not add parenthesis at the right AST nodes.
Issue Log
Looking at the build logs, this seems to be a problem:
sdf2parenthesize: [trycatch] Caught exception: required attribute nativepath not set
I think it’s broken since https://github.com/metaborg/strategoxt/commit/551e0d9bfabc8842c3b023a0d4605ca3ca09d86a
<arg value="--nativepath" /> <arg value="" />
Should be added to https://github.com/metaborg/spoofax/blob/new-spoofax-plugin/org.metaborg.spoofax.meta.core/src/main/resources/org/metaborg/spoofax/meta/core/build.xml
But instead of an empty value, it should be the location of
sdf2table
Or maybe the
<attribute name="nativepath" />
is not be necessary in https://github.com/metaborg/strategoxt/blob/new-spoofax-plugin/strategoxt/ant-contrib/org/strategoxt/antcontrib/strategoxt-antlib.xml for sdf2parenthesize.
Nice catch, we don’t use the parenthesizer often so we didn’t notice it was broken. I’ll fix it in the ant build and new build system that I am integrating.
Fixed with the new build system
Log in to post comments