当前位置: 首页>>代码示例>>Java>>正文


Java Parser.getRuleNames方法代码示例

本文整理汇总了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);
}
 
开发者ID:uwol,项目名称:vb6parser,代码行数:10,代码来源:TreeUtils.java

示例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;
}
 
开发者ID:javamonkey,项目名称:beetl2.0,代码行数:10,代码来源:BeetlAntlrErrorStrategy.java

示例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();
        }
    }
}
 
开发者ID:cscorley,项目名称:srcmlolol,代码行数:52,代码来源:App.java

示例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;

}
 
开发者ID:fandianpf,项目名称:antlr4-regressionTestRig,代码行数:33,代码来源:TreePrinter.java

示例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);
}
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:10,代码来源:Trees.java

示例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);
}
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:6,代码来源:Trees.java

示例7: SaltTextVisitor

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
public SaltTextVisitor(Parser parser) {
	ruleNames = parser.getRuleNames();
}
 
开发者ID:mar9000,项目名称:salt9000,代码行数:4,代码来源:SaltTextVisitor.java


注:本文中的org.antlr.v4.runtime.Parser.getRuleNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。