本文整理汇总了Java中org.antlr.v4.runtime.Parser.getRuleNames方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.getRuleNames方法的具体用法?Java Parser.getRuleNames怎么用?Java Parser.getRuleNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.Parser
的用法示例。
在下文中一共展示了Parser.getRuleNames方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStringTree
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
/**
* @see org.antlr.v4.runtime.tree.Trees.toStringTree(Tree, Parser)
*/
public static String toStringTree(final Tree t, @Nullable 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);
}
示例2: reportFailedPredicate
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
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;
}
示例3: process
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void process(Lexer lexer, Class<? extends Parser> parserClass, Parser parser,
InputStream is, Reader r, String filename) throws IOException, IllegalAccessException,
InvocationTargetException, PrintException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException {
try {
ANTLRInputStream input = new ANTLRInputStream(r);
lexer.setInputStream(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
if (this.startRuleName.equals(App.LEXER_START_RULE_NAME)) {
return;
}
parser.setBuildParseTree(true);
parser.setTokenStream(tokens);
if (this.startRuleName.equals("")){
this.startRuleName = parser.getRuleNames()[0];
}
try {
Method startRule = parserClass.getMethod(this.startRuleName);
ParserRuleContext tree = (ParserRuleContext) startRule.invoke(parser,
(Object[]) null);
ParseTreeWalker walker = new ParseTreeWalker();
XMLListener proxy = new XMLListener(filename, lexer.getTokenTypeMap());
walker.walk(proxy, tree);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(proxy.doc),
new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));
} catch (NoSuchMethodException nsme) {
System.err.println("No method for rule " + this.startRuleName
+ " or it has arguments");
}
} finally {
if (r != null) {
r.close();
}
if (is != null) {
is.close();
}
}
}
示例4: TreePrinter
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param aPrimaryIndentAmount A String containing the characters used to
* increase the indent for each recursive call to
* {@link #printTree}.
* See: {@link #newIndent}.
* @param aSecondaryIndentAmount A String containing the characters used to
* increase the indent for each recursive call
* to {@link #printTree}.
* See: {@link #newIndent}.
* @param anIndentCyclePeriod The secondaryIndentAmount is used at the end of
* each indent cycle period.
* See: {@link #newIndent}.
* @param recog The lexer/parser used to obtain the rule names to be
* printed in the printTree output.
*/
public TreePrinter(@Nullable String aPrimaryIndentAmount,
@Nullable String aSecondaryIndentAmount,
int anIndentCyclePeriod,
@Nullable Parser recog) {
if (aPrimaryIndentAmount != null) primaryIndentAmount = aPrimaryIndentAmount;
if (aSecondaryIndentAmount != null) secondaryIndentAmount = aSecondaryIndentAmount;
if (0 < anIndentCyclePeriod) {
indentCyclePeriod = anIndentCyclePeriod;
indentCycleLength = primaryIndentAmount.length() * (indentCyclePeriod - 1) +
secondaryIndentAmount.length();
}
String[] ruleNamesArray = (recog != null) ? recog.getRuleNames() : null;
ruleNames = (ruleNamesArray != null) ? Arrays.asList(ruleNamesArray) : null;
}
示例5: toStringTree
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
/** Print out a whole tree in LISP form. {@link #getNodeText} is used on the
* node payloads to get the text for the nodes. Detect
* parse trees and extract data appropriately.
*/
public static String toStringTree(@NotNull Tree t, @Nullable Parser recog) {
String[] ruleNames = recog != null ? recog.getRuleNames() : null;
List<String> ruleNamesList = ruleNames != null ? Arrays.asList(ruleNames) : null;
return toStringTree(t, ruleNamesList);
}
示例6: getNodeText
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
public static String getNodeText(@NotNull Tree t, @Nullable Parser recog) {
String[] ruleNames = recog != null ? recog.getRuleNames() : null;
List<String> ruleNamesList = ruleNames != null ? Arrays.asList(ruleNames) : null;
return getNodeText(t, ruleNamesList);
}
示例7: SaltTextVisitor
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
public SaltTextVisitor(Parser parser) {
ruleNames = parser.getRuleNames();
}