Search in sources :

Example 1 with JSGLRParserConfiguration

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;
}
Also used : ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) ICompletion(org.metaborg.core.completion.ICompletion) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) JSGLRParserConfiguration(org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ISpoofaxInputUnit(org.metaborg.spoofax.core.unit.ISpoofaxInputUnit) FileObject(org.apache.commons.vfs2.FileObject)

Example 2 with JSGLRParserConfiguration

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());
}
Also used : JSGLRParserConfiguration(org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration) JSGLRParseService(org.metaborg.spoofax.core.syntax.JSGLRParseService)

Aggregations

JSGLRParserConfiguration (org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration)2 FileObject (org.apache.commons.vfs2.FileObject)1 ICompletion (org.metaborg.core.completion.ICompletion)1 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)1 JSGLRParseService (org.metaborg.spoofax.core.syntax.JSGLRParseService)1 SyntaxFacet (org.metaborg.spoofax.core.syntax.SyntaxFacet)1 ISpoofaxInputUnit (org.metaborg.spoofax.core.unit.ISpoofaxInputUnit)1 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)1 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1