return r;
}
private IStrategoTerm parseCompletionTree(String input, String filename, Result result) throws IOException {
//TODO fix: adapt to parsing with parseMax
RetractableTreeBuilder treeBuilder = new RetractableTreeBuilder();
ParseTable table;
try {
table = ATermCommands.parseTableManager.loadFromFile(result.getParseTable().getAbsolutePath());
} catch (InvalidParseTableException e) {
return null;
}
SGLR parser = new SGLR(treeBuilder, table);
parser.setUseStructureRecovery(true);
String remainingInput = input;
List<IStrategoTerm> list = new LinkedList<IStrategoTerm>();
while (true) {
if (remainingInput == null || remainingInput.isEmpty())
return null;
IStrategoTerm term;
try {
term = (IStrategoTerm) parser.parse(remainingInput, filename, "NextToplevelDeclaration");
} catch (SGLRException e) {
return null;
} catch (InterruptedException e) {
return null;
}
if (!ATermCommands.isApplication(term, "NextToplevelDeclaration"))
return null;
IStrategoTerm nextDecl = ATermCommands.getApplicationSubterm(term, "NextToplevelDeclaration", 0);
list.add(nextDecl);
if (nextDecl.toString().contains(ContentProposerSemantic.COMPLETION_TOKEN)) {
IStrategoList termList = ATermCommands.makeList("NextToplevelDeclaration", list);
IStrategoList listIt = termList;
while (!listIt.isEmpty()) {
ParentAttachment.putParent(listIt.head(), termList, listIt);
listIt = listIt.tail();
}
return termList;
}
IStrategoTerm remainingInputTerm = ATermCommands.getApplicationSubterm(term, "NextToplevelDeclaration", 1);
treeBuilder.retract(remainingInputTerm);
remainingInput = ((IStrategoString) remainingInputTerm).stringValue();
}
}