Java Code Examples for org.antlr.v4.runtime.Parser#getRuleNames()

The following examples show how to use org.antlr.v4.runtime.Parser#getRuleNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserWrapper.java    From antlr4-autosuggest with Apache License 2.0 5 votes vote down vote up
public ParserWrapper(ParserFactory parserFactory, Vocabulary lexerVocabulary) {
    this.lexerVocabulary = lexerVocabulary;
    
    Parser parserForAtnOnly = parserFactory.createParser(null);
    this.parserAtn = parserForAtnOnly.getATN();
    this.parserRuleNames = parserForAtnOnly.getRuleNames();
    logger.debug("Parser rule names: " + StringUtils.join(parserForAtnOnly.getRuleNames(), ", "));
}
 
Example 2
Source File: TreeUtils.java    From proleap-vb6-parser with MIT License 5 votes vote down vote up
/**
 * @see org.antlr.v4.runtime.tree.Trees.toStringTree(Tree, Parser)
 */
public static String toStringTree(final Tree t, final Parser recog) {
	final String[] ruleNames = recog != null ? recog.getRuleNames() : null;
	final List<String> ruleNamesList = ruleNames != null ? Arrays.asList(ruleNames) : null;

	return toStringTree(t, ruleNamesList, 0);
}
 
Example 3
Source File: BeetlAntlrErrorStrategy.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e)
{
	String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()];
	BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e);
	//		exception.token = this.getGrammarToken(e.getOffendingToken());
	exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

	throw exception;
}