use of org.eclipse.xtext.ide.editor.contentassist.antlr.internal.InfiniteRecursion in project xtext-core by eclipse.
the class BaseContentAssistParser method getFollowElements.
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());
}
}
use of org.eclipse.xtext.ide.editor.contentassist.antlr.internal.InfiniteRecursion in project xtext-core by eclipse.
the class BaseContentAssistParser method getFollowElements.
public Collection<FE> getFollowElements(IParseResult parseResult, EntryPointFinder entryPointFinder, int offset, boolean strict) {
ICompositeNode entryPoint = entryPointFinder.findEntryPoint(parseResult, offset);
if (entryPoint != null) {
String parseMe = getTextToParse(parseResult, entryPoint, offset);
TokenSource tokenSource = createTokenSource(parseMe);
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 {
Collection<FE> followElements = getFollowElements(parser, getEntryGrammarElement(entryPoint));
return Lists.newArrayList(followElements);
} catch (InfiniteRecursion infinite) {
return Lists.newArrayList(parser.getFollowElements());
}
} else {
String text = parseResult.getRootNode().getText();
String parseMe = text.substring(0, offset);
initializeFor(NodeModelUtils.getEntryParserRule(parseResult.getRootNode()));
Collection<FE> followElements = getFollowElements(parseMe, strict);
return followElements;
}
}
use of org.eclipse.xtext.ide.editor.contentassist.antlr.internal.InfiniteRecursion in project xtext-core by eclipse.
the class BaseContentAssistParser method getFollowElements.
/**
* @since 2.14
*/
protected Set<FE> getFollowElements(final InternalParser parser, String ruleName, boolean swallowInfiniteRecursion) throws Exception {
Method method = parser.getClass().getMethod(ruleName);
method.setAccessible(true);
try {
method.invoke(parser);
} catch (InvocationTargetException targetException) {
Throwable cause = targetException.getCause();
if (cause instanceof InfiniteRecursion) {
if (swallowInfiniteRecursion) {
return parser.getFollowElements();
} else {
throw (InfiniteRecursion) cause;
}
}
throw targetException;
}
return parser.getFollowElements();
}
use of org.eclipse.xtext.ide.editor.contentassist.antlr.internal.InfiniteRecursion in project n4js by eclipse.
the class CustomN4JSParser method collectFollowElements.
/**
* First pass. Use the tokens that have been computed from the production parser's result and collect the follow
* elements from those.
*/
private CustomInternalN4JSParser collectFollowElements(TokenSource tokens, boolean strict, Set<FollowElement> result) {
CustomInternalN4JSParser parser = createParser();
parser.setStrict(strict);
try {
ObservableXtextTokenStream tokenStream = new ObservableXtextTokenStream(tokens, parser);
result.addAll(doGetFollowElements(parser, tokenStream));
} catch (InfiniteRecursion infinite) {
// this guards against erroneous infinite recovery loops in Antlr.
// Grammar dependent and not expected something that is expected for N4JS
// is used in the base class thus also used here.
result.addAll(parser.getFollowElements());
}
return parser;
}
Aggregations