use of coreVisitors.InjectionOnSugar 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 coreVisitors.InjectionOnSugar in project L42 by ElvisResearchGroup.
the class BigStep method executeAtomicStep.
protected ExpCore executeAtomicStep(PData p1, ExpCore _e1) {
if (!IsCompiled.of(_e1)) {
return step(p1, _e1);
}
return Resources.withPDo(p1, () -> {
ExpCore e1 = _e1;
boolean runned = false;
e1 = NormalizeBlocks.of(e1);
try {
while (!(e1 instanceof ClassB)) {
log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
e1 = step(p1, e1);
e1 = NormalizeBlocks.of(e1);
runned = true;
}
} catch (Throwable t) {
if (!runned) {
throw t;
}
}
log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
return e1;
});
}
use of coreVisitors.InjectionOnSugar in project L42 by ElvisResearchGroup.
the class ToFormattedText method of.
public static String of(ExpCore.ClassB.Member m) {
List<ExpCore.ClassB.Member> ms = new ArrayList<>();
ms.add(m);
ExpCore e = ExpCore.ClassB.membersClass(ms, m.getP(), Phase.None);
Expression.ClassB es = (ClassB) e.accept(new InjectionOnSugar());
ToFormattedText tft = new ToFormattedText();
//for the injection
tft.formatMembers(es.getMs());
return tft.result.toString();
}
Aggregations