use of org.antlr.v4.runtime.tree.Tree in project antlr4 by antlr.
the class TreeViewer method paint.
@Override
public void paint(Graphics g) {
super.paint(g);
if (treeLayout == null) {
return;
}
Graphics2D g2 = (Graphics2D) g;
// anti-alias the lines
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Anti-alias the text
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// AffineTransform at = g2.getTransform();
// g2.scale(
// (double) this.getWidth() / 400,
// (double) this.getHeight() / 400);
//
// g2.setTransform(at);
paintEdges(g, getTree().getRoot());
// paint the boxes
for (Tree Tree : treeLayout.getNodeBounds().keySet()) {
paintBox(g, Tree);
}
}
use of org.antlr.v4.runtime.tree.Tree in project antlr4 by antlr.
the class TreeViewer method fillTree.
private static void fillTree(TreeNodeWrapper node, Tree tree, TreeViewer viewer) {
if (tree == null) {
return;
}
for (int i = 0; i < tree.getChildCount(); i++) {
Tree childTree = tree.getChild(i);
TreeNodeWrapper childNode = new TreeNodeWrapper(childTree, viewer);
node.add(childNode);
fillTree(childNode, childTree, viewer);
}
}
use of org.antlr.v4.runtime.tree.Tree in project antlr4 by antlr.
the class BasicSemanticChecks method enterLabeledLexerElement.
@Override
protected void enterLabeledLexerElement(GrammarAST tree) {
Token label = ((GrammarAST) tree.getChild(0)).getToken();
g.tool.errMgr.grammarError(ErrorType.V3_LEXER_LABEL, g.fileName, label, label.getText());
}
use of org.antlr.v4.runtime.tree.Tree in project antlr4 by antlr.
the class BasicSemanticChecks method checkElementIsOuterMostInSingleAlt.
/**
Make sure that action is last element in outer alt; here action,
a2, z, and zz are bad, but a3 is ok:
(RULE A (BLOCK (ALT {action} 'a')))
(RULE B (BLOCK (ALT (BLOCK (ALT {a2} 'x') (ALT 'y')) {a3})))
(RULE C (BLOCK (ALT 'd' {z}) (ALT 'e' {zz})))
*/
protected void checkElementIsOuterMostInSingleAlt(GrammarAST tree) {
CommonTree alt = tree.parent;
CommonTree blk = alt.parent;
boolean outerMostAlt = blk.parent.getType() == RULE;
Tree rule = tree.getAncestor(RULE);
String fileName = tree.getToken().getInputStream().getSourceName();
if (!outerMostAlt || blk.getChildCount() > 1) {
ErrorType e = ErrorType.LEXER_COMMAND_PLACEMENT_ISSUE;
g.tool.errMgr.grammarError(e, fileName, tree.getToken(), rule.getChild(0).getText());
}
}
use of org.antlr.v4.runtime.tree.Tree in project antlr4 by antlr.
the class ParseTreePattern method findAll.
/**
* Find all nodes using XPath and then try to match those subtrees against
* this tree pattern.
*
* @param tree The {@link ParseTree} to match against this pattern.
* @param xpath An expression matching the nodes
*
* @return A collection of {@link ParseTreeMatch} objects describing the
* successful matches. Unsuccessful matches are omitted from the result,
* regardless of the reason for the failure.
*/
public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) {
Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser());
List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>();
for (ParseTree t : subtrees) {
ParseTreeMatch match = match(t);
if (match.succeeded()) {
matches.add(match);
}
}
return matches;
}
Aggregations