System.err.println(ERROR("FATAL") + LOTUS("\tLotus failed: ") + ERROR(t));
}
}
// benchmark the AtFormulaParser
ASTNode ast = null;
FormulaParser parser = Formulas.getParser();
try {
ast = parser.parse(line);
} catch (FormulaParseException e) {
errors.append(NTF("\tParser failed: ") + ERROR(e) + "\n");
e.printStackTrace();
parserFailed = true;
} catch (Throwable t) {
System.err.println(ERROR("FATAL") + NTF("\tParser failed: ") + ERROR(t));
t.printStackTrace();
}
if (!parserFailed) {
if (testDoc) {
try {
FormulaContext ctx1 = Formulas.createContext(ntfDoc, parser);
ntfDocResult = ast.solve(ctx1);
} catch (EvaluateException e) {
errors.append(NTF("\tDoc-Evaluate failed: ") + ERROR(e) + "\n");
ntfError = e;
parserFailed = true;
} catch (Throwable t) {
System.err.println(ERROR("FATAL") + NTF("\tDoc-Evaluate failed: ") + ERROR(t));
t.printStackTrace();
}
}
if (testMap) {
try {
// benchmark the evaluate with a map as context
FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
ntfMapResult = ast.solve(ctx2);
} catch (EvaluateException e) {
errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
ntfError = e;
parserFailed = true;
} catch (Throwable t) {
System.err.println(ERROR("FATAL") + NTF("\tMap-Evaluate failed: ") + ERROR(t));
t.printStackTrace();
}
}
}
if (lotusFailed && parserFailed) {
System.out.println(SUCCESS() + dump(line + " = UNDEFINED"));
return;
}
if (testLotus && testDoc) {
if (compareList(ntfDocResult, lotusResult)) {
System.out.println(SUCCESS() + line + " = " + dump(ntfDocResult));
} else {
System.err.println(FAIL() + NTF("DOC:") + line);
System.err.println("\tResult: " + dump(ntfDocResult) + " Size: " + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
System.err.println("\tExpected: " + dump(lotusResult) + " Size: " + ((lotusResult == null) ? 0 : lotusResult.size()));
if (parserFailed || lotusFailed) {
System.err.println(errors.toString());
if (ntfError != null) {
ntfError.printStackTrace(System.err);
}
}
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
try {
console.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
if (parserFailed) {
ntfError.printStackTrace();
}
System.err.println("\tDocResult: " + dump(ntfDocResult) + " Size: " + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
System.err.println("\tMapResult: " + dump(ntfMapResult) + " Size: " + ((ntfMapResult == null) ? 0 : ntfMapResult.size()));
}
System.out.println(NTF("Read fields\t") + ast.getReadFields());
System.out.println(NTF("Modified fields\t") + ast.getModifiedFields());
System.out.println(NTF("Variables\t") + ast.getVariables());
System.out.println(NTF("Functions\t") + ast.getFunctions());
}