@Override public Set<Binding> getGuiceBindingsRt(Grammar grammar) { BindFactory factory = new BindFactory() .addTypeToType(IParser.class.getName(),getParserClassName(grammar, getNaming())) .addTypeToType(ITokenToStringConverter.class.getName(),AntlrTokenToStringConverter.class.getName()) .addTypeToType(IAntlrTokenFileProvider.class.getName(),getAntlrTokenFileProviderClassName(grammar, getNaming())) .addTypeToType(Lexer.class.getName(), getLexerClassName(grammar, getNaming())) .addTypeToProviderInstance(getLexerClassName(grammar, getNaming()), "org.eclipse.xtext.parser.antlr.LexerProvider.create(" + getLexerClassName(grammar, getNaming()) + ".class)") .addConfiguredBinding("RuntimeLexer", "binder.bind(" + Lexer.class.getName() + ".class)"+ ".annotatedWith(com.google.inject.name.Names.named(" + "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME" + ")).to(" + getLexerClassName(grammar, getNaming()) +".class)") .addTypeToType(ITokenDefProvider.class.getName(), AntlrTokenDefProvider.class.getName()); if (containsUnorderedGroup(grammar)) factory = factory.addTypeToType(IUnorderedGroupHelper.class.getName(), UnorderedGroupHelper.class.getName()); return factory.getBindings(); }
@Override public Set<Binding> getGuiceBindingsRt(Grammar grammar) { BindFactory factory = new BindFactory() .addTypeToType(IParser.class.getName(),getFragmentHelper().getParserClassName(grammar)) .addTypeToType(ITokenToStringConverter.class.getName(),AntlrTokenToStringConverter.class.getName()) .addTypeToType(IAntlrTokenFileProvider.class.getName(),getFragmentHelper().getAntlrTokenFileProviderClassName(grammar)) .addTypeToType(Lexer.class.getName(), getFragmentHelper().getLexerClassName(grammar)) .addTypeToProviderInstance(getFragmentHelper().getLexerClassName(grammar), "org.eclipse.xtext.parser.antlr.LexerProvider.create(" + getFragmentHelper().getLexerClassName(grammar) + ".class)") .addConfiguredBinding("RuntimeLexer", "binder.bind(" + Lexer.class.getName() + ".class)"+ ".annotatedWith(com.google.inject.name.Names.named(" + "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME" + ")).to(" + getFragmentHelper().getLexerClassName(grammar) +".class)") .addTypeToType(ITokenDefProvider.class.getName(),AntlrTokenDefProvider.class.getName()); if (containsUnorderedGroup(grammar)) factory = factory.addTypeToType(IUnorderedGroupHelper.class.getName(), UnorderedGroupHelper.class.getName()); if (getOptions().isIgnoreCase()) { factory = factory .addTypeToType(ITokenSerializer.IKeywordSerializer.class.getName(), IgnoreCaseKeywordSerializer.class.getName()) .addTypeToType(AbstractIDValueConverter.class.getName(), IgnoreCaseIDValueConverter.class.getName()); } return factory.getBindings(); }
public Collection<FE> getFollowElements(String input, boolean strict) { TokenSource tokenSource = createTokenSource(input); InternalParser parser = createParser(); parser.setStrict(strict); ObservableXtextTokenStream tokens = new ObservableXtextTokenStream(tokenSource, parser); tokens.setInitialHiddenTokens(getInitialHiddenTokens()); parser.setTokenStream(tokens); IUnorderedGroupHelper helper = createUnorderedGroupHelper(); parser.setUnorderedGroupHelper(helper); helper.initializeWith(parser); tokens.setListener(parser); try { return Lists.newArrayList(getFollowElements(parser)); } catch (InfiniteRecursion infinite) { return Lists.newArrayList(parser.getFollowElements()); } }
@Override public void announceEof(int lookAhead) { if (!wasRecovering) { parser.announceEof(lookAhead); if (lookAhead > 1) announcedEofWithLA = true; } if (parser.isDFAPrediction()) { int lastGrammarElement = parser.getGrammarElements().size() - 1; if (elementToParse instanceof UnorderedGroup && parser.getGrammarElements().get(lastGrammarElement) == elementToParse) { IUnorderedGroupHelper helper = parser.getUnorderedGroupHelper(); if (!helper.canLeave((UnorderedGroup) elementToParse)) { wasEof = true; } } } else { wasEof = true; } }
public Collection<FollowElement> getFollowElements(String input, boolean strict) { CharStream stream = new ANTLRStringStream(input); TokenSource tokenSource = createLexer(stream); AbstractInternalContentAssistParser parser = createParser(); parser.setStrict(strict); ObservableXtextTokenStream tokens = new ObservableXtextTokenStream(tokenSource, parser); tokens.setInitialHiddenTokens(getInitialHiddenTokens()); parser.setTokenStream(tokens); IUnorderedGroupHelper helper = getUnorderedGroupHelper().get(); parser.setUnorderedGroupHelper(helper); helper.initializeWith(parser); tokens.setListener(parser); try { return Lists.newArrayList(getFollowElements(parser)); } catch(InfiniteRecursion infinite) { return Lists.newArrayList(parser.getFollowElements()); } }
/** * Initialize the parser properly with the given tokens and process it. */ private Collection<FollowElement> doGetFollowElements(AbstractInternalContentAssistParser parser, ObservableXtextTokenStream tokens) { tokens.setInitialHiddenTokens(getInitialHiddenTokens()); parser.setTokenStream(tokens); IUnorderedGroupHelper helper = getUnorderedGroupHelper().get(); parser.setUnorderedGroupHelper(helper); helper.initializeWith(parser); tokens.setListener(parser); Collection<FollowElement> followElements = getFollowElements(parser); return followElements; }
public Collection<FE> getFollowElements(FE element) { if (element.getLookAhead() <= 1) throw new IllegalArgumentException("lookahead may not be less than or equal to 1"); Collection<FE> result = new ArrayList<FE>(); for (AbstractElement elementToParse : getElementsToParse(element)) { elementToParse = unwrapSingleElementGroups(elementToParse); String ruleName = getRuleName(elementToParse); String[][] allRuleNames = getRequiredRuleNames(ruleName, element.getParamStack(), elementToParse); for (String[] ruleNames : allRuleNames) { for (int i = 0; i < ruleNames.length; i++) { InternalParser parser = createParser(); parser.setUnorderedGroupHelper(createUnorderedGroupHelper()); parser.getUnorderedGroupHelper().initializeWith(parser); ObservableXtextTokenStream tokens = setTokensFromFollowElement(parser, element); tokens.setListener(parser); parser.getGrammarElements().addAll(element.getTrace()); parser.getGrammarElements().add(elementToParse); parser.getLocalTrace().addAll(element.getLocalTrace()); parser.getLocalTrace().add(elementToParse); parser.getParamStack().addAll(element.getParamStack()); if (elementToParse instanceof UnorderedGroup && element.getGrammarElement() == elementToParse) { UnorderedGroup group = (UnorderedGroup) elementToParse; IUnorderedGroupHelper helper = getInitializedUnorderedGroupHelper(element, parser, group); parser.setUnorderedGroupHelper(ignoreFirstEntrance(helper)); } Collection<FE> elements = getFollowElements(parser, elementToParse, ruleNames, i); result.addAll(elements); } } } return result; }
/** * @since 2.14 */ protected IUnorderedGroupHelper getInitializedUnorderedGroupHelper(FE element, InternalParser parser, UnorderedGroup group) { final IUnorderedGroupHelper helper = parser.getUnorderedGroupHelper(); helper.enter(group); for (AbstractElement consumed : element.getHandledUnorderedGroupElements()) { parser.before(consumed); helper.select(group, group.getElements().indexOf(consumed)); helper.returnFromSelection(group); parser.after(consumed); } return helper; }
@Override public Set<Binding> getGuiceBindingsRt(final Grammar grammar) { BindFactory factory = new BindFactory() .addTypeToType(IParser.class.getName(), getFragmentHelper().getParserClassName(grammar)) .addTypeToType(ITokenToStringConverter.class.getName(), AntlrTokenToStringConverter.class.getName()) .addTypeToType(IAntlrTokenFileProvider.class.getName(), getFragmentHelper().getAntlrTokenFileProviderClassName(grammar)) .addTypeToType(Lexer.class.getName(), getFragmentHelper().getLexerClassName(grammar)) .addTypeToProviderInstance( getFragmentHelper().getLexerClassName(grammar), "org.eclipse.xtext.parser.antlr.LexerProvider.create(" + getFragmentHelper().getLexerClassName(grammar) + ".class)") .addConfiguredBinding("RuntimeLexer", "binder.bind(" + Lexer.class.getName() + ".class)" + ".annotatedWith(com.google.inject.name.Names.named(" + "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME" + ")).to(" + getFragmentHelper().getLexerClassName(grammar) + ".class)") .addTypeToType(ITokenDefProvider.class.getName(), AntlrTokenDefProvider.class.getName()); if (containsUnorderedGroup(grammar)) { factory = factory.addTypeToType(IUnorderedGroupHelper.class.getName(), UnorderedGroupHelper.class.getName()); } if (getOptions().isIgnoreCase()) { factory = factory .addTypeToType(ITokenSerializer.IKeywordSerializer.class.getName(), IgnoreCaseKeywordSerializer.class.getName()) .addTypeToType(AbstractIDValueConverter.class.getName(), IgnoreCaseIDValueConverter.class.getName()); } return factory.getBindings(); }
public Class<? extends IUnorderedGroupHelper> bindIUnorderedGroupHelper() { return UnorderedGroupHelper.class; }
protected IUnorderedGroupHelper getHelper() { return helper; }
/** * Factory method for the {@link IgnoreFirstEntranceUnorderedGroupHelper}. */ protected IUnorderedGroupHelper ignoreFirstEntrance(final IUnorderedGroupHelper helper) { return new IgnoreFirstEntranceUnorderedGroupHelper(helper); }
/** * Creates a new {@link IUnorderedGroupHelper} that is not yet initialized. */ protected IUnorderedGroupHelper createUnorderedGroupHelper() { return getUnorderedGroupHelper().get(); }
/** * Public for testing purpose. */ public void setUnorderedGroupHelper(Provider<IUnorderedGroupHelper> unorderedGroupHelper) { this.unorderedGroupHelper = unorderedGroupHelper; }
/** * Public for testing purpose. */ public Provider<IUnorderedGroupHelper> getUnorderedGroupHelper() { return unorderedGroupHelper; }
public void setUnorderedGroupHelper(IUnorderedGroupHelper unorderedGroupHelper) { this.unorderedGroupHelper = unorderedGroupHelper; }
public IUnorderedGroupHelper getUnorderedGroupHelper() { return unorderedGroupHelper; }
protected IUnorderedGroupHelper getUnorderedGroupHelper() { return getRecognizer().getUnorderedGroupHelper(); }
public void setUnorderedGroupHelper(Provider<IUnorderedGroupHelper> unorderedGroupHelper) { this.unorderedGroupHelper = unorderedGroupHelper; }
public Provider<IUnorderedGroupHelper> getUnorderedGroupHelper() { return unorderedGroupHelper; }
/** * @since 2.4 */ protected IUnorderedGroupHelper getUnorderedGroupHelper() { return getRecognizer().getUnorderedGroupHelper(); }
/** * Protected contructor to allow to override this type. * * @see BaseContentAssistParser#ignoreFirstEntrance(IUnorderedGroupHelper) */ protected IgnoreFirstEntranceUnorderedGroupHelper(IUnorderedGroupHelper helper) { this.helper = Preconditions.checkNotNull(helper, "helper may not be null"); }