本文整理了Java中org.antlr.v4.runtime.Parser.getRuleNames()
方法的一些代码示例,展示了Parser.getRuleNames()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.getRuleNames()
方法的具体详情如下:
包路径:org.antlr.v4.runtime.Parser
类名称:Parser
方法名:getRuleNames
暂无
代码示例来源:origin: org.antlr/antlr4-runtime
public String getRuleName(int index) {
if ( parser!=null && index>=0 ) return parser.getRuleNames()[index];
return "<rule "+index+">";
}
代码示例来源:origin: org.antlr/antlr4-runtime
protected String getDecisionDescription(Parser recognizer, DFA dfa) {
int decision = dfa.decision;
int ruleIndex = dfa.atnStartState.ruleIndex;
String[] ruleNames = recognizer.getRuleNames();
if (ruleIndex < 0 || ruleIndex >= ruleNames.length) {
return String.valueOf(decision);
}
String ruleName = ruleNames[ruleIndex];
if (ruleName == null || ruleName.isEmpty()) {
return String.valueOf(decision);
}
return String.format("%d (%s)", decision, ruleName);
}
代码示例来源:origin: org.antlr/antlr4-runtime
/** 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(Tree t, Parser recog) {
String[] ruleNames = recog != null ? recog.getRuleNames() : null;
List<String> ruleNamesList = ruleNames != null ? Arrays.asList(ruleNames) : null;
return toStringTree(t, ruleNamesList);
}
代码示例来源:origin: org.antlr/antlr4-runtime
public static String getNodeText(Tree t, Parser recog) {
String[] ruleNames = recog != null ? recog.getRuleNames() : null;
List<String> ruleNamesList = ruleNames != null ? Arrays.asList(ruleNames) : null;
return getNodeText(t, ruleNamesList);
}
代码示例来源:origin: org.antlr/antlr4-runtime
public List<String> getRuleInvocationStack(RuleContext p) {
String[] ruleNames = getRuleNames();
List<String> stack = new ArrayList<String>();
while ( p!=null ) {
// compute what follows who invoked us
int ruleIndex = p.getRuleIndex();
if ( ruleIndex<0 ) stack.add("n/a");
else stack.add(ruleNames[ruleIndex]);
p = p.parent;
}
return stack;
}
代码示例来源:origin: org.antlr/antlr4-runtime
@Override
public void enterEveryRule(ParserRuleContext ctx) {
System.out.println("enter " + getRuleNames()[ctx.getRuleIndex()] +
", LT(1)=" + _input.LT(1).getText());
}
代码示例来源:origin: org.antlr/antlr4-runtime
@Override
public void exitEveryRule(ParserRuleContext ctx) {
System.out.println("exit "+getRuleNames()[ctx.getRuleIndex()]+
", LT(1)="+_input.LT(1).getText());
}
}
代码示例来源:origin: org.antlr/antlr4-runtime
@Override
public void visitTerminal(TerminalNode node) {
System.out.println("consume "+node.getSymbol()+" rule "+
getRuleNames()[_ctx.getRuleIndex()]);
}
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* This is called by {@link #reportError} when the exception is a
* {@link FailedPredicateException}.
*
* @see #reportError
*
* @param recognizer the parser instance
* @param e the recognition exception
*/
protected void reportFailedPredicate(Parser recognizer,
FailedPredicateException e)
{
String ruleName = recognizer.getRuleNames()[recognizer._ctx.getRuleIndex()];
String msg = "rule "+ruleName+" "+e.getMessage();
recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
代码示例来源:origin: org.antlr/antlr4-runtime
Arrays.asList(parser.getRuleNames()),
parser.getATNWithBypassAlts(),
tokens);
代码示例来源:origin: org.antlr/antlr4
/** Save this tree in a postscript file */
public static void save(Tree t, Parser parser, String fileName)
throws IOException, PrintException
{
List<String> ruleNames = parser != null ? Arrays.asList(parser.getRuleNames()) : null;
save(t, ruleNames, fileName);
}
代码示例来源:origin: org.antlr/antlr4
/** Save this tree in a postscript file using a particular font name and size */
public static void save(Tree t, Parser parser, String fileName,
String fontName, int fontSize)
throws IOException
{
List<String> ruleNames = parser != null ? Arrays.asList(parser.getRuleNames()) : null;
save(t, ruleNames, fileName, fontName, fontSize);
}
代码示例来源:origin: org.antlr/antlr4
/** Call this method to view a parse tree in a dialog box visually. */
public static Future<JFrame> inspect(Tree t, Parser parser) {
List<String> ruleNames = parser != null ? Arrays.asList(parser.getRuleNames()) : null;
return inspect(t, ruleNames);
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
public List<String> getRuleInvocationStack(RuleContext p) {
String[] ruleNames = getRuleNames();
List<String> stack = new ArrayList<String>();
while ( p!=null ) {
// compute what follows who invoked us
int ruleIndex = p.getRuleIndex();
if ( ruleIndex<0 ) stack.add("n/a");
else stack.add(ruleNames[ruleIndex]);
p = p.parent;
}
return stack;
}
代码示例来源:origin: uk.co.nichesolutions/antlr4
/** Call this method to view a parse tree in a dialog box visually. */
public static Future<JDialog> inspect(Tree t, Parser parser) {
List<String> ruleNames = parser != null ? Arrays.asList(parser.getRuleNames()) : null;
return inspect(t, ruleNames);
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
@Override
public void exitEveryRule(ParserRuleContext ctx) {
System.out.println("exit "+getRuleNames()[ctx.getRuleIndex()]+
", LT(1)="+_input.LT(1).getText());
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
/** For debugging and other purposes. */
public List<String> getDFAStrings() {
List<String> s = new ArrayList<String>();
for (int d = 0; d < _interp.atn.decisionToDFA.length; d++) {
DFA dfa = _interp.atn.decisionToDFA[d];
s.add( dfa.toString(getVocabulary(), getRuleNames()) );
}
return s;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@Override
public void enterEveryRule(ParserRuleContext ctx) {
System.out.println("enter " + getRuleNames()[ctx.getRuleIndex()] +
", LT(1)=" + _input.LT(1).getText());
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
/** 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);
}
代码示例来源:origin: javamonkey/beetl2.0
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;
}
内容来源于网络,如有侵权,请联系作者删除!