Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL example Pass compile but can't run . #79

Closed
JulianZhang opened this issue Oct 10, 2017 · 5 comments
Closed

DSL example Pass compile but can't run . #79

JulianZhang opened this issue Oct 10, 2017 · 5 comments

Comments

@JulianZhang
Copy link

JulianZhang commented Oct 10, 2017

Hi I had try with the DSL Expression example, I had pass compile and package with maven.

But when I try to run the example it say as

java -cp target/spl2es-0.0.1-SNAPSHOT.jar spl2es.Expression
Exception in thread "main" java.lang.Error: Unresolved compilation problem:

	at spl2es.Expression.main(Expression.java:39)

The blow is my Expression.java, And I had check only can find Expression.class and Expression$Cases.class. Does there should find an class file such as Expressions.class

import static java.util.Arrays.asList;
import org.derive4j.*;
import static spl2es.Expressions.*;
import java.util.function.Function;
import java.util.List;
import javax.json.*;

@Data
public abstract class Expression {
	interface Cases<R> {
		R Leaf(String key,String value);
		R EList(List<Expression> blist);
		R ELeaf(String key, Expression value);
    }
    public abstract <R> R match(Cases<R> cases);
	private static Function<Expression, JsonValue> eval = Expressions
    .cases()
        .Leaf((key,value)        -> Json.createObjectBuilder()
            .add(key,value).build()
        )
        .ELeaf((key, value)  -> Json.createObjectBuilder()
            .add(key,eval(value)).build()
        )
        .EList(blist -> {
                JsonArrayBuilder job =Json.createArrayBuilder();
                for (Expression e : blist) {
                    job.add(e);
                }
                return job.build();
            }
        );
    public static JsonValue eval(Expression expression) {
        return eval.apply(expression);
    }
    public static JsonValue test (){
        Expression expr = Leaf("2","3");
        eval(expr);
    }
    public static void main(String[] args) {
        System.out.print(test().toString());
    }            
}
@jbgi
Copy link
Member

jbgi commented Oct 10, 2017

Hi,
Are you using eclipse? In that case make sure to a maven clean before producing the jar, because ecj can produce this kind of error at runtime by filling uncompillable portion of the code with throw new Error. In your case it looks like the test is missing the return.

@JulianZhang
Copy link
Author

@jbgi Thanks for reply, I think my problem is cause by wrong maven setting.
Do you have any build able pom.xml example.

@jbgi
Copy link
Member

jbgi commented Oct 10, 2017

@JulianZhang
Copy link
Author

@jbgi Thank you

@JulianZhang
Copy link
Author

https://github.com/AndreasVoellmy/derive4jbenchmark is run able example with maven.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants