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));
}
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;
}
}
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));
}
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;
}
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);
}
Aggregations