當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。