}
if (parseResult == null || parseResult.a == null)
throw new ParseException("could not parse toplevel declaration in:\n" + input, -1);
IStrategoTerm toplevelDecl = parseResult.a;
String rest = input.substring(Math.min(parseResult.b, input.length()));
if (input.equals(rest))
if (driver.getParser().getCollectedErrors().isEmpty())
throw new SGLRException(driver.getParser(), "empty toplevel declaration parse rule");
else
throw driver.getParser().getCollectedErrors().iterator().next();
// try {
// if (!rest.isEmpty())
// inputTreeBuilder.retract(restTerm);
// } catch (Throwable t) {
// t.printStackTrace();
// }
Path tmpFile = FileCommands.newTempFile("aterm");
FileCommands.writeToFile(tmpFile, toplevelDecl.toString());
log.log("next toplevel declaration parsed: " + tmpFile, Log.PARSE);
return new IncrementalParseResult(toplevelDecl, rest);
} catch (Exception e) {
// if (!recovery)
// throw new SGLRException(driver.getParser(), "parsing failed", e);
String msg = e.getClass().getName() + " " + e.getLocalizedMessage() != null ? e.getLocalizedMessage() : e.toString();
if (!(e instanceof StrategoException) && !(e instanceof ParseException) && (!(e instanceof SGLRException) || (e instanceof FilterException)))
e.printStackTrace();
else
log.logErr(msg, Log.DETAIL);
if (!treeBuilder.isInitialized()) {
SGLR parser = driver.getParser();
if (parser == null && (e instanceof SGLRException))
parser = ((SGLRException) e).getParser();
if (parser == null)
return new IncrementalParseResult(ATermCommands.factory.makeString(input), "");
treeBuilder.initializeTable(parser.getParseTable(), 0, 0, 0);
treeBuilder.initializeInput(input, null);
}
else if (treeBuilder.getTokenizer().getStartOffset() > start) {
IToken token = treeBuilder.getTokenizer().getTokenAtOffset(start);
((RetractableTokenizer) treeBuilder.getTokenizer()).retractTo(token.getIndex());
treeBuilder.setOffset(start);
}
IToken right = treeBuilder.getTokenizer().makeToken(start + input.length() - 1, IToken.TK_STRING, true);
IToken left = treeBuilder.getTokenizer().getTokenAtOffset(start);
treeBuilder.getTokenizer().makeToken(treeBuilder.getTokenizer().getStartOffset() - 1, IToken.TK_EOF, true);
IStrategoTerm term = ATermCommands.factory.makeString(input);
ImploderAttachment.putImploderAttachment(term, false, "String", left, right);
if (!lookahead)
driver.setErrorMessage(term, msg);
return new IncrementalParseResult(term, "");
} finally {