本文整理汇总了Java中org.antlr.v4.runtime.tree.Trees类的典型用法代码示例。如果您正苦于以下问题:Java Trees类的具体用法?Java Trees怎么用?Java Trees使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Trees类属于org.antlr.v4.runtime.tree包,在下文中一共展示了Trees类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getCurrentEditorElement
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
/** From editor's cursor, find associated parse tree node so we can highlight
* in structure view. It wants the parse tree node not a
* StructureViewTreeElement. It will try to find a path from root to
* that node and highlight it.
*/
@Nullable
public Object getCurrentEditorElement() {
if (editor==null) return null;
final int offset = editor.getCaretModel().getOffset();
if ( parseTree==null ) return null;
Tree selectedNode = Trees.findNodeSuchThat(parseTree, new Predicate<Tree>() {
@Override
public boolean test(Tree node) {
if ( !(node instanceof TerminalNode) ) return false;
Token t = ((TerminalNode) node).getSymbol();
return offset>=t.getStartIndex() && offset<=t.getStopIndex();
}
});
if ( selectedNode==null ) return null;
// now walk up looking for template def node
ParseTree p = (ParseTree)selectedNode;
while ( p!=null && !(p instanceof STGParser.TemplateContext) ) {
p = p.getParent();
}
if ( p!=null ) {
return ((STGParser.TemplateContext)p).ID(0);
}
return null;
}
开发者ID:antlr,项目名称:jetbrains-plugin-st4,代码行数:30,代码来源:STGroupStructureViewModel.java
示例2: doCompareParseTree
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
protected void doCompareParseTree(final File treeFile, final StartRuleContext startRule,
final VisualBasic6Parser parser) throws IOException {
final String treeFileData = FileUtils.readFileToString(treeFile);
if (!Strings.isBlank(treeFileData)) {
LOG.info("Comparing parse tree with file {}.", treeFile.getName());
final String inputFileTree = Trees.toStringTree(startRule, parser);
final String cleanedInputFileTree = io.proleap.vb6.util.StringUtils.cleanFileTree(inputFileTree);
final String cleanedTreeFileData = io.proleap.vb6.util.StringUtils.cleanFileTree(treeFileData);
assertEquals(cleanedTreeFileData, cleanedInputFileTree);
} else {
LOG.info("Ignoring empty parse tree file {}.", treeFile.getName());
}
}
开发者ID:uwol,项目名称:vb6parser,代码行数:18,代码来源:VbParseTestRunnerImpl.java
示例3: evaluate
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public Collection<ParseTree> evaluate(ParseTree t) {
// return all children of t that match nodeName
List<ParseTree> nodes = new ArrayList<ParseTree>();
for (Tree c : Trees.getChildren(t)) {
if ( c instanceof ParserRuleContext ) {
ParserRuleContext ctx = (ParserRuleContext)c;
if ( (ctx.getRuleIndex() == ruleIndex && !invert) ||
(ctx.getRuleIndex() != ruleIndex && invert) )
{
nodes.add(ctx);
}
}
}
return nodes;
}
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:17,代码来源:XPathRuleElement.java
示例4: evaluate
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public Collection<ParseTree> evaluate(ParseTree t) {
// return all children of t that match nodeName
List<ParseTree> nodes = new ArrayList<ParseTree>();
for (Tree c : Trees.getChildren(t)) {
if ( c instanceof TerminalNode ) {
TerminalNode tnode = (TerminalNode)c;
if ( (tnode.getSymbol().getType() == tokenType && !invert) ||
(tnode.getSymbol().getType() != tokenType && invert) )
{
nodes.add(tnode);
}
}
}
return nodes;
}
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:17,代码来源:XPathTokenElement.java
示例5: getText
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public String getText(Tree node) {
if ( node instanceof PreviewInterpreterRuleContext) {
PreviewInterpreterRuleContext inode = (PreviewInterpreterRuleContext)node;
Rule r = g.getRule(inode.getRuleIndex());
String[] altLabels = getAltLabels(r);
String name = r.name;
int outerAltNum = inode.getOuterAltNum();
if ( altLabels!=null ) {
if ( outerAltNum>=0 && outerAltNum<altLabels.length ) {
return name+":"+altLabels[outerAltNum];
}
else {
return name;
}
}
else if ( r.getOriginalNumberOfAlts()>1 ) {
return name + ":" +outerAltNum;
}
else {
return name; // don't display an alternative number if there's only one
}
}
return Trees.getNodeText(node, Arrays.asList(parser.getRuleNames()));
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:26,代码来源:AltLabelTextProvider.java
示例6: findOverriddenDecisionRoot
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
/** Same as loadGrammar(fileName) except import vocab from existing lexer */
// public static Grammar loadGrammar(Tool tool, String fileName, LexerGrammar lexerGrammar) {
// GrammarRootAST grammarRootAST = parseGrammar(fileName);
// if ( grammarRootAST==null ) return null;
// final Grammar g = tool.createGrammar(grammarRootAST);
// g.fileName = fileName;
// if ( lexerGrammar!=null ) {
// g.importVocab(lexerGrammar);
// }
// tool.process(g, false);
// return g;
// }
public static Tree findOverriddenDecisionRoot(Tree ctx) {
return Trees.findNodeSuchThat(ctx, new Predicate<Tree>() {
@Override
public boolean test(Tree t) {
return t instanceof PreviewInterpreterRuleContext ?
((PreviewInterpreterRuleContext) t).isDecisionOverrideRoot() :
false;
}
});
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:24,代码来源:ParsingUtils.java
示例7: parse
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Test
public void parse() throws IOException {
System.out.println(file.getName() + "-------------------------------");
final LLVMLexer lexer = new LLVMLexer(new ANTLRFileStream(file.getAbsolutePath()));
final CommonTokenStream stream = new CommonTokenStream(lexer);
final LLVMParser parser = new LLVMParser(stream);
parser.setErrorHandler(new BailErrorStrategy());
final ModuleContext module = parser.module();
System.out.println(Trees.toStringTree(module));
}
开发者ID:snefru,项目名称:io.alef.llvm,代码行数:11,代码来源:LLVMParserTest.java
示例8: enterEveryRule
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
public void enterEveryRule(ParserRuleContext ctx) {
// Find sibling lists that are children of this parent node
Set<Class> completed = new HashSet<>(); // only count sibling list for each subtree type once
for (int i = 0; i<ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if ( completed.contains(child.getClass()) ) continue; // avoid counting repeatedly
completed.add(child.getClass());
if ( child instanceof TerminalNode ) continue; // tokens are separators at most not siblings
// found subtree child
List<? extends ParserRuleContext> siblings =
ctx.getRuleContexts(((ParserRuleContext) child).getClass());
if ( siblings.size()>1 ) { // we found a list
// check for separator by looking between first two siblings (assume all are same)
ParserRuleContext first = siblings.get(0);
ParserRuleContext second = siblings.get(1);
List<Tree> children = Trees.getChildren(ctx);
int firstIndex = children.indexOf(first);
int secondIndex = children.indexOf(second);
if ( firstIndex+1 == secondIndex ) continue; // nothing between first and second so no separator
ParseTree between = ctx.getChild(firstIndex+1);
if ( between instanceof TerminalNode ) { // is it a token?
Token separator = ((TerminalNode) between).getSymbol();
visitNonSingletonWithSeparator(ctx, siblings, separator);
}
}
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:33,代码来源:VisitSiblingLists.java
示例9: getSeparators
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
public static List<Tree> getSeparators(ParserRuleContext ctx, List<? extends ParserRuleContext> siblings) {
ParserRuleContext first = siblings.get(0);
ParserRuleContext last = siblings.get(siblings.size()-1);
int start = BuffUtils.indexOf(ctx, first);
int end = BuffUtils.indexOf(ctx, last);
List<Tree> elements = Trees.getChildren(ctx).subList(start, end+1);
return BuffUtils.filter(elements, c -> c instanceof TerminalNode);
}
开发者ID:antlr,项目名称:codebuff,代码行数:9,代码来源:VisitSiblingLists.java
示例10: visitTerminal
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public void visitTerminal(TerminalNode node) {
if (builder.length() > 0) {
builder.append(' ');
}
builder.append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false));
}
开发者ID:TransputerSystems,项目名称:TSS,代码行数:9,代码来源:ParseTreePretty.java
示例11: visitErrorNode
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public void visitErrorNode(ErrorNode node) {
if (builder.length() > 0) {
builder.append(' ');
}
builder.append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false));
}
开发者ID:TransputerSystems,项目名称:TSS,代码行数:9,代码来源:ParseTreePretty.java
示例12: getChildren
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@NotNull
@Override
public TreeElement[] getChildren() {
ParserRuleContext root = (ParserRuleContext) this.node;
Collection<ParseTree> rules = Trees.findAllRuleNodes(root, STGParser.RULE_template);
if ( rules.size()==0 ) return EMPTY_ARRAY;
List<TreeElement> treeElements = new ArrayList<TreeElement>(rules.size());
for (ParseTree t : rules) {
ParseTree nameNode = t.getChild(0);
treeElements.add(new STGroupTemplateDefTreeElement(model, nameNode));
}
// System.out.println("rules="+rules);
return treeElements.toArray(new TreeElement[treeElements.size()]);
}
开发者ID:antlr,项目名称:jetbrains-plugin-st4,代码行数:15,代码来源:STGroupRootTreeElement.java
示例13: process
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
private String process(final Tree t, final List<String> ruleNames) {
if (t.getChildCount() == 0) return Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
StringBuilder sb = new StringBuilder();
sb.append(lead(level));
level++;
String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
sb.append(s + ' ');
for (int i = 0; i < t.getChildCount(); i++) {
sb.append(process(t.getChild(i), ruleNames));
}
level--;
sb.append(lead(level));
return sb.toString();
}
开发者ID:grosenberg,项目名称:SnippetsTest,代码行数:15,代码来源:TestBase.java
示例14: visitTerminal
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public void visitTerminal(TerminalNode node) {
String text = Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false);
if(text.startsWith(" ") || text.endsWith(" ")){
text = "'" + text + "'";
}
stack.get(node.getParent()).add(text);
}
开发者ID:rpgleparser,项目名称:rpgleparser,代码行数:9,代码来源:TreePrinterListener.java
示例15: toStringTree
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
/**
* @see org.antlr.v4.runtime.tree.Trees.toStringTree(Tree, List<String>)
*/
public static String toStringTree(final Tree t, @Nullable final List<String> ruleNames, final int depth) {
String s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
if (t.getChildCount() == 0) {
return s;
}
final StringBuilder buf = new StringBuilder();
if (depth > 0) {
buf.append(NEWLINE);
}
buf.append(indent(depth));
buf.append("(");
s = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i < t.getChildCount(); i++) {
if (i > 0) {
buf.append(' ');
}
buf.append(toStringTree(t.getChild(i), ruleNames, depth + 1));
}
buf.append(")");
return buf.toString();
}
开发者ID:uwol,项目名称:vb6parser,代码行数:35,代码来源:TreeUtils.java
示例16: evaluate
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public Collection<ParseTree> evaluate(final ParseTree t) {
if ( invert ) return new ArrayList<ParseTree>(); // !* is weird but valid (empty)
List<ParseTree> kids = new ArrayList<ParseTree>();
for (Tree c : Trees.getChildren(t)) {
kids.add((ParseTree)c);
}
return kids;
}
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:10,代码来源:XPathWildcardElement.java
示例17: save
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
/** Save this tree in a postscript file using a particular font name and size */
public void save(@Nullable List<String> ruleNames, String fileName,
String fontName, int fontSize)
throws IOException
{
Trees.writePS(this, ruleNames, fileName, fontName, fontSize);
}
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:8,代码来源:RuleContext.java
示例18: visitTerminal
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public void visitTerminal(TerminalNode node) {
if (builder.length() > 0) {
builder.append(' ');
}
append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false));
}
开发者ID:MontysCoconut,项目名称:moco,代码行数:9,代码来源:ParseTreePrinter.java
示例19: visitErrorNode
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
@Override
public void visitErrorNode(ErrorNode node) {
if (builder.length() > 0) {
builder.append(' ');
}
append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false));
}
开发者ID:MontysCoconut,项目名称:moco,代码行数:9,代码来源:ParseTreePrinter.java
示例20: getParseTreeNodeWithToken
import org.antlr.v4.runtime.tree.Trees; //导入依赖的package包/类
public static ParseTree getParseTreeNodeWithToken(ParseTree tree, Token token) {
if ( tree==null || token==null ) {
return null;
}
Collection<ParseTree> tokenNodes = Trees.findAllTokenNodes(tree, token.getType());
for (ParseTree t : tokenNodes) {
TerminalNode tnode = (TerminalNode)t;
if ( tnode.getPayload() == token ) {
return tnode;
}
}
return null;
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:15,代码来源:ParsingUtils.java
注:本文中的org.antlr.v4.runtime.tree.Trees类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论