Search in sources :

Example 21 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class SchemeInterpreterVisitor method visit.

@Override
public void visit(Definitions entity) {
    super.visit(entity);
    IEntity mainDefine = getBindings().wGet("main");
    if (mainDefine == null)
        throw new VisitException("expected the definition of: main");
    stagedVisit(mainDefine);
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 22 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class SchemeInterpreterVisitor method visit.

public void visit(CondExpression entity) {
    boolean prune = false;
    Branches branches = (Branches) entity.getBranches();
    if (!branches.wGetEntityDescriptor().equals(SchemeEntityDescriptorEnum.Branches))
        throw new VisitException("expected a " + SchemeEntityDescriptorEnum.Branches);
    for (int i = 0; i < branches.wSize() && !prune; i++) {
        Branch branch = (Branch) entity.wGet(i);
        if (booleanValue(branch.getTest())) {
            branch.getBody().accept(this);
            return;
        }
    }
    entity.getElseBody().accept(this);
}
Also used : Branches(org.whole.lang.scheme.model.Branches) Branch(org.whole.lang.scheme.model.Branch) VisitException(org.whole.lang.visitors.VisitException)

Example 23 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class SchemeInterpreterVisitor method visit.

public void visit(OrExpression entity) {
    IEntity exprs = entity.getExpressions();
    if (!exprs.wGetEntityDescriptor().equals(SchemeEntityDescriptorEnum.SchemeExpressions))
        throw new VisitException("expected a " + SchemeEntityDescriptorEnum.SchemeExpressions);
    boolean result = true;
    for (int i = 0; i < exprs.wSize(); i++) result = result || booleanValue(((SchemeExpression) exprs.wGet(i)));
    setResult(SchemeEntityFactory.instance.createBooleanValue(result));
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 24 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class SchemeInterpreterVisitor method visit.

public void visit(ApplyExpression entity) {
    IEntity exprs = entity.getExpressions();
    if (!exprs.wGetEntityDescriptor().equals(SchemeEntityDescriptorEnum.SchemeExpressions))
        throw new VisitException("expected a " + SchemeEntityDescriptorEnum.SchemeExpressions);
    if (exprs.wIsEmpty())
        throw new VisitException("empty application");
    ConstExpression head = (ConstExpression) evaluate((SchemeExpression) exprs.wGet(0));
    ConstExpression[] args = new ConstExpression[exprs.wSize() - 1];
    for (int i = 1; i < exprs.wSize(); i++) args[i - 1] = (ConstExpression) evaluate(((SchemeExpression) exprs.wGet(i)));
    apply(head, args);
}
Also used : ConstExpression(org.whole.lang.scheme.model.ConstExpression) IEntity(org.whole.lang.model.IEntity) SchemeExpression(org.whole.lang.scheme.model.SchemeExpression) VisitException(org.whole.lang.visitors.VisitException)

Example 25 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class PojoArtifactsGeneratorVisitor method visit.

@Override
public void visit(Library library) {
    Name libraryName = library.getName();
    if (!EntityUtils.isNotResolver(libraryName))
        throw new VisitException("No library name");
    String modelFileName = DataTypeUtils.getAsPersistenceString(libraryName) + "Model";
    Model model = PojoMappingUtils.getModel(library);
    env().wDefValue("modelFileName", modelFileName);
    env().wDef("modelFileContent", model);
    IEntity ws = ModelsArtifactsTemplateManager.instance().create("ModelFileArtifact");
    Matcher.substitute(ws, env(), false);
    ArtifactsUtils.moveArtifactsIntoWorkspace(ws, env());
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) Model(org.whole.lang.models.model.Model) Name(org.whole.lang.pojo.model.Name)

Aggregations

VisitException (org.whole.lang.visitors.VisitException)35 IEntity (org.whole.lang.model.IEntity)25 IBindingManager (org.whole.lang.bindings.IBindingManager)6 File (java.io.File)4 AbstractVisitor (org.whole.lang.visitors.AbstractVisitor)4 HashSet (java.util.HashSet)3 GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 GenericTraversalFactory (org.whole.lang.visitors.GenericTraversalFactory)2 IVisitor (org.whole.lang.visitors.IVisitor)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 BufferedReader (java.io.BufferedReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1