treeparser.java

来自「ANTLR(ANother Tool for Language Recognit」· Java 代码 · 共 57 行

JAVA
57
字号
package org.antlr.runtime.tree;import org.antlr.runtime.*;import java.util.List;import java.util.ArrayList;/** A parser for a stream of tree nodes.  "tree grammars" result in a subclass *  of this.  All the error reporting and recovery is shared with Parser via *  the BaseRecognizer superclass.*/public class TreeParser extends BaseRecognizer {	protected TreeNodeStream input;	public TreeParser(TreeNodeStream input) {		setTreeNodeStream(input);	}	/** Set the input stream and reset the parser */	public void setTreeNodeStream(TreeNodeStream input) {		this.input = input;		reset();	}	public TreeNodeStream getTreeNodeStream() {		return input;	}	/** Convert a List<RuleReturnScope> to List<StringTemplate> by copying	 *  out the .st property.  Useful when converting from	 *  list labels to template attributes:	 *	 *    a : ids+=rule -> foo(ids={toTemplates($ids)})	 *      ;	 */	public List toTemplates(List retvals) {		if ( retvals==null ) return null;		List strings = new ArrayList(retvals.size());		for (int i=0; i<retvals.size(); i++) {			strings.add(((TreeRuleReturnScope)retvals.get(i)).getTemplate());		}		return strings;	}	/** We have DOWN/UP nodes in the stream that have no line info; override.	 *  plus we want to alter the exception type.	 */	protected void mismatch(IntStream input, int ttype, BitSet follow)		throws RecognitionException	{		MismatchedTreeNodeException mte =			new MismatchedTreeNodeException(ttype, (TreeNodeStream)input);		recoverFromMismatchedToken(input, mte, ttype, follow);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?