Search in sources :

Example 51 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarVars method visit.

public Expression visit(CurlyBlock s) {
    Expression inner;
    if (s.getContents().size() == 1 && s.getContents().get(0).get_catch().isEmpty() && s.getContents().get(0).getDecs().size() == 1 && s.getContents().get(0).getDecs().get(0) instanceof VarDecE) {
        inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
    } else {
        inner = new RoundBlock(s.getP(), s.getDoc(), Expression._void.instance, s.getContents());
    }
    inner = inner.accept(this);
    List<VarDec> vd = Collections.singletonList((VarDec) new VarDecE(inner));
    BlockContent o = new BlockContent(vd, Collections.emptyList());
    return new CurlyBlock(s.getP(), Doc.empty(), Collections.singletonList(o));
}
Also used : Expression(ast.Expression) CurlyBlock(ast.Expression.CurlyBlock) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE)

Example 52 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class OnLineCodeHelper method getL42Code.

static Expression.ClassB getL42Code(String url) {
    try {
        //can be classB or classBReuse
        Expression data = load(url);
        //TODO: can be removed later, but now allows librares to be real source code
        data = Desugar.of(data);
        //    Configuration.reduction.of((ClassB) data.accept(new InjectionOnCore()));
        return (Expression.ClassB) data;
    } catch (org.antlr.v4.runtime.misc.ParseCancellationException pce) {
        System.err.println("Url is: " + url);
        throw pce;
    }
}
Also used : Expression(ast.Expression) ClassB(ast.ExpCore.ClassB)

Example 53 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method oldWith_noUseKw.

private void oldWith_noUseKw(SquareWithCall s, X xX, List<VarDec> decs) {
    List<With.On> ons = s.getWith().getOns();
    List<With.On> onsPrime = new ArrayList<>();
    for (With.On on : ons) {
        onsPrime.add(on.withInner(withSquareAdd(s.getP(), xX, on.getInner())));
    }
    Optional<Expression> def = s.getWith().getDefaultE();
    Optional<Expression> defPrime = Map.of(e -> withSquareAdd(s.getP(), xX, e), def);
    With w = s.getWith().withOns(onsPrime).withDefaultE(defPrime);
    decs.add(new VarDecE(w));
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) On(ast.Expression.With.On) VarDecE(ast.Ast.VarDecE) On(ast.Expression.With.On) With(ast.Expression.With)

Example 54 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method innerWithXs.

private static Expression innerWithXs(With e) {
    //right side of case b and part of right side of case d
    Expression inner = e.getDefaultE().get();
    List<String> xs = new ArrayList<String>(e.getXs());
    for (VarDecXE d : e.getDecs()) {
        xs.add(d.getX());
    }
    for (VarDecXE d : e.getIs()) {
        xs.add(d.getX());
    }
    inner = new With(e.getP(), xs, Collections.emptyList(), Collections.emptyList(), e.getOns(), e.getDefaultE());
    return inner;
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) VarDecXE(ast.Ast.VarDecXE) With(ast.Expression.With)

Example 55 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method visit.

public Expression visit(With e) {
    Position pos = e.getP();
    //case a
    e = with_A_applyDefault(e);
    if (e.getIs().isEmpty() && e.getDecs().isEmpty()) {
        //case c
        return with_C_resolveXsBaseCase(pos, e.getXs(), e.getOns(), e.getDefaultE().get()).accept(this);
    }
    //case b
    if (e.getIs().isEmpty()) {
        return with_B_noI_makeBlock(e).accept(this);
    }
    //assert !e.getIs().isEmpty();
    if (e.getXs().isEmpty() && e.getDecs().isEmpty() && e.getOns().isEmpty()) {
        //case e
        Expression b = e.getDefaultE().get();
        //NOTE WELL: needed to avoid xs that can not be replaced in with xs... this is also the reason we need DesugarW in the first place.
        b = b.accept(this);
        return with_E_handleIs(pos, e.getIs(), b).accept(this);
    }
    //case d
    return with_D_replace_XID_with_InestedDwithX(e).accept(this);
}
Also used : Position(ast.Ast.Position) Expression(ast.Expression)

Aggregations

Expression (ast.Expression)66 ArrayList (java.util.ArrayList)24 VarDec (ast.Ast.VarDec)14 X (ast.Expression.X)13 Type (ast.Ast.Type)11 VarDecXE (ast.Ast.VarDecXE)11 ExpCore (ast.ExpCore)11 Catch (ast.Expression.Catch)11 RoundBlock (ast.Expression.RoundBlock)11 VarDecE (ast.Ast.VarDecE)10 Doc (ast.Ast.Doc)8 Position (ast.Ast.Position)8 MethodSelectorX (ast.Ast.MethodSelectorX)7 Parameters (ast.Ast.Parameters)7 MethodWithType (ast.Expression.ClassB.MethodWithType)7 MethodType (ast.Ast.MethodType)6 ClassB (ast.ExpCore.ClassB)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Path (ast.Ast.Path)4