use of ast.Expression in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method injectionCatch.
private List<Expression.Catch> injectionCatch(List<ast.ExpCore.Block.On> list) {
if (list.isEmpty()) {
return Collections.emptyList();
}
List<Expression.Catch> ks = new ArrayList<>();
for (ast.ExpCore.Block.On on : list) {
Expression inner = lift(on.getInner());
ks.add(new Expression.Catch1(on.getP(), on.getKind(), on.getT(), on.getX(), inner));
}
return ks;
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class Parser method parse.
public static synchronized Expression parse(String fileName, String s) {
String old = Parser.fileName;
Parser.fileName = fileName;
try {
checkForTab(s);
checkForBalancedParenthesis(s);
s = replaceORoundWithTab(s);
NudeEContext ctxResult = parseCtx(s);
Expression result = ctxResult.accept(new ToAst());
return result;
} finally {
Parser.fileName = old;
}
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class OnLineCodeHelper method load.
private static Expression load(String name) {
//URL res = OnLineCode.class.getResource(name+".L42");
//Path res = L42.path.resolve(name+".L42");
Path res = Paths.get("localhost", name + ".L42");
assert res != null : name;
String s = L42.pathToString(res);
Expression e = Parser.parse(res.toString(), s);
assert WellFormedness.checkAll(e);
return e;
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class ErrorFormatter method errorFormat.
public static String errorFormat(Object obj, ArrayList<Ast.Position> ps) {
if (obj instanceof ast.Ast.HasPos) {
ps.add(((ast.Ast.HasPos) obj).getP());
}
if (obj instanceof String) {
return (String) obj;
}
if (obj instanceof Integer) {
return obj.toString();
}
if (obj instanceof Expression) {
Ast.Position p = CollapsePositions.of((Expression) obj);
ps.add(p);
return ToFormattedText.ofCompact((Expression) obj);
}
if (obj instanceof ExpCore) {
//thanks to Path, this have to be after Expression
Ast.Position p = CollapsePositions.of((ExpCore) obj);
ps.add(p);
ExpCore exp = (ExpCore) obj;
Expression expression = exp.accept(new InjectionOnSugar());
return errorFormat(expression, ps);
}
if (obj instanceof Ast.MethodSelector) {
return formatSelectorCompact((Ast.MethodSelector) obj);
}
if (obj instanceof ExpCore.ClassB.MethodWithType) {
return ToFormattedText.of((MethodWithType) obj).trim().replace("\n", " ");
}
// }
if (obj instanceof Reporter) {
return ((Reporter) obj).toReport(ps);
}
if (obj instanceof Collection<?>) {
Collection<?> c = (Collection<?>) obj;
if (c.size() == 0) {
return "[]";
}
if (c.size() == 1) {
return "[" + errorFormat(c.iterator().next(), ps) + "]";
}
String res = "[\n";
for (Object o : c) {
res += " " + errorFormat(o, ps) + "\n";
}
return res + " ]\n";
}
if (obj instanceof Ast.Type) {
return obj.toString();
}
if (obj instanceof ClassB.Member) {
return ToFormattedText.of((ClassB.Member) obj);
}
//if(obj instanceof Expression){return ToFormattedText.of((Expression)obj);}
if (obj instanceof Expression.ClassB.Member) {
return ToFormattedText.of((Expression.ClassB.Member) obj);
}
if (obj instanceof java.nio.file.Path) {
return obj.toString();
}
if (obj instanceof Ast.Position) {
return obj.toString();
}
if (obj instanceof HashMap) {
return obj.toString();
}
if (obj instanceof Collection) {
return obj.toString();
}
if (obj instanceof ast.Util.PathMwt) {
return obj.toString();
}
if (obj instanceof ast.Ast.C) {
return obj.toString();
}
if (obj instanceof Boolean) {
return obj.toString();
}
if (obj instanceof ast.Ast.Path) {
return obj.toString();
}
return "unknown kind " + obj.getClass().getName();
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class L42 method runSlow.
public static ErrorMessage.FinalResult runSlow(String fileName, String code) {
try {
L42.setExecutionStage(ExecutionStage.Parsing);
Expression code1 = Parser.parse(fileName, code);
assert code1 instanceof Expression.ClassB || code1 instanceof Expression.ClassReuse;
L42.setExecutionStage(ExecutionStage.CheckingWellFormedness);
auxiliaryGrammar.WellFormedness.checkAll(code1);
L42.setExecutionStage(ExecutionStage.Desugaring);
Expression code2 = Desugar.of(code1);
assert auxiliaryGrammar.WellFormedness.checkAll(code2);
ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
// L42.usedNames.addAll(CollectDeclaredVarsAndCheckNoDeclaredTwice.of(code2));
//L42.usedNames.addAll(CollectDeclaredClassNamesAndMethodNames.of(code2));
L42.setExecutionStage(ExecutionStage.MetaExecution);
//ClassB result= (ClassB)Executor.stepStar(exe,code3);
//Refresh of position identities, it is used to generate correct Java code.
code3 = (ClassB) code3.accept(new CloneVisitor() {
@Override
public ExpCore visit(ClassB cb) {
Position p = cb.getP();
cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
return super.visit(cb);
}
});
//ClassB result= Configuration.reduction.of(code3);
ClassB result = ProgramReduction.allSteps(code3);
//System.out.println("--------------------------");
return checkFinalError(result);
} finally {
L42.setExecutionStage(ExecutionStage.None);
}
}
Aggregations