use of org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration in project spoofax by metaborg.
the class JSGLRCompletionService method get.
@Override
public Iterable<ICompletion> get(int position, ISpoofaxParseUnit parseInput, boolean nested) throws MetaborgException {
ISpoofaxParseUnit completionParseResult = null;
if (!nested && !parseInput.success()) {
final JSGLRParserConfiguration config = new JSGLRParserConfiguration(true, true, true, 3000, position);
final ISpoofaxInputUnit input = parseInput.input();
final ISpoofaxInputUnit modifiedInput = unitService.inputUnit(input.source(), input.text(), input.langImpl(), input.dialect(), config);
completionParseResult = syntaxService.parse(modifiedInput);
}
Collection<ICompletion> completions = Lists.newLinkedList();
// Completion in case of empty input
String inputText = parseInput.input().text();
if (inputText.trim().isEmpty()) {
final ILanguageImpl language = parseInput.input().langImpl();
final FileObject location = parseInput.source();
final Iterable<String> startSymbols = language.facet(SyntaxFacet.class).startSymbols;
completions.addAll(completionEmptyProgram(startSymbols, inputText.length(), language, location));
return completions;
}
if (completionParseResult != null && completionParseResult.ast() == null) {
return completions;
}
Collection<IStrategoTerm> nestedCompletionTerms = getNestedCompletionTermsFromAST(completionParseResult);
Collection<IStrategoTerm> completionTerms = getCompletionTermsFromAST(completionParseResult);
boolean blankLineCompletion = isCompletionBlankLine(position, parseInput.input().text());
if (!completionTerms.isEmpty()) {
completions.addAll(completionErroneousPrograms(position, completionTerms, completionParseResult));
}
if (!nestedCompletionTerms.isEmpty()) {
completions.addAll(completionErroneousProgramsNested(position, nestedCompletionTerms, completionParseResult));
}
if (completionTerms.isEmpty() && nestedCompletionTerms.isEmpty()) {
completions.addAll(completionCorrectPrograms(position, blankLineCompletion, parseInput));
}
return completions;
}
use of org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration in project spoofax by metaborg.
the class SpoofaxModule method bindParsers.
protected void bindParsers(MapBinder<String, IParser<ISpoofaxInputUnit, ISpoofaxParseUnit>> parserBinder, MapBinder<String, ISpoofaxParser> spoofaxParserBinder) {
bind(JSGLRParseService.class).in(Singleton.class);
parserBinder.addBinding(JSGLRParseService.name).to(JSGLRParseService.class);
spoofaxParserBinder.addBinding(JSGLRParseService.name).to(JSGLRParseService.class);
languageCacheBinder.addBinding().to(JSGLRParseService.class);
bind(JSGLRParserConfiguration.class).toInstance(new JSGLRParserConfiguration());
}
Aggregations