org.antlr.v4.runtime.tree.RuleNode Java Examples
The following examples show how to use
org.antlr.v4.runtime.tree.RuleNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeUsesProvider.java From sonar-tsql-plugin with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public Object visitChildren(final RuleNode node) { final int n = node.getChildCount(); for (int i = 0; i < n; i++) { final ParseTree c = node.getChild(i); c.accept(this); } final String textToFind = node.getText(); if (StringUtils.containsIgnoreCase(textToFind, tempText) || StringUtils.containsIgnoreCase(tempText, textToFind)) { nodes.add(new ParsedNode(node)); } return null; }
Example #2
Source File: AstTSRendererTest.java From doov with Apache License 2.0 | 6 votes |
@Test void mapping() { TypeScriptParser parser = TypeScriptParserFactory.parse(CharStreams.fromString(mapping_stmt)); assertThat(parser.getNumberOfSyntaxErrors()).isEqualTo(0); CallExpressionContext callExpressionContext = parser.callExpression(); System.out.println(callExpressionContext.getText()); callExpressionContext.accept(new AbstractParseTreeVisitor<Object>() { @Override public Object visitChildren(RuleNode node) { if (node instanceof CallExpressionContext) { CallExpressionContext call = (CallExpressionContext) node; System.out.println(call.getText()); if (call.identifierName() != null) { System.out.println(call.identifierName().getText()); } if (call.memberExpression() != null) { System.out.println(call.memberExpression().getText()); } } return super.visitChildren(node); } }); }
Example #3
Source File: ParseTreeNavigator.java From kalang with MIT License | 6 votes |
private void enterParseTree(ParseTree tree){ int cc = tree.getChildCount(); for(int i=0;i<cc;i++){ ParseTree c = tree.getChild(i); if(c instanceof RuleNode){ enterParseTree(c); }else if (c instanceof TerminalNode){ Token t = ((TerminalNode)c).getSymbol(); index2token.put(tokenCounter, t); token2tree.put(t, c); tokenCounter ++; }else{ System.err.println("unknown node:" + c); } } }
Example #4
Source File: BatfishParseTreeWalker.java From batfish with Apache License 2.0 | 5 votes |
@Override protected void enterRule(ParseTreeListener listener, RuleNode r) { ParserRuleContext ctx = (ParserRuleContext) r.getRuleContext(); try { listener.enterEveryRule(ctx); ctx.enterRule(listener); } catch (Exception e) { throw new BatfishParseException( String.format("Exception while walking parse tree: %s", e.getMessage()), e, new ErrorDetails( Throwables.getStackTraceAsString(e), new ParseExceptionContext(ctx, _parser, _parser.getInput()))); } }
Example #5
Source File: ProgramParser.java From vespa with Apache License 2.0 | 5 votes |
public static int getParseTreeIndex(ParseTree parseTree) { if (parseTree instanceof TerminalNode) { return ((TerminalNode)parseTree).getSymbol().getType(); } else { return ((RuleNode)parseTree).getRuleContext().getRuleIndex(); } }
Example #6
Source File: IndexRQL.java From indexr with Apache License 2.0 | 5 votes |
private static void parseTreeWalker(ParseTree node, Consumer<RuleNode> f) { RuleNode rule = checkNode(node, RuleNode.class); if (rule == null) { return; } f.accept(rule); for (int i = 0; i < rule.getChildCount(); i++) { parseTreeWalker(rule.getChild(i), f); } }
Example #7
Source File: IndexRQL.java From indexr with Apache License 2.0 | 5 votes |
public LogicalPlan parseToPlan() { ParseTree root = parseSQL(sql); checkNode(root, RuleNode.class); if (root.getChildCount() == 0 || checkNode(root.getChild(0), RuleNode.class) == null) { return new OneRowRelation(); } StatementContext statementContext = (StatementContext) root.getChild(0); return parseToSelectPlan(statementContext.selectStatement()); }
Example #8
Source File: Visitor.java From swift-js-transpiler with MIT License | 5 votes |
public String visitWithoutClasses(RuleNode node, Class nodeType) { String result = this.defaultResult(); int n = node.getChildCount(); for(int i = 0; i < n && this.shouldVisitNextChild(node, result); ++i) { ParseTree c = node.getChild(i); if(c.getClass() == nodeType) continue; String childResult = c instanceof TerminalNode ? printTerminalNode((TerminalNode) c) : c.accept(this); result = this.aggregateResult(result, childResult); } return result; }
Example #9
Source File: Visitor.java From swift-js-transpiler with MIT License | 5 votes |
public String visitWithoutStrings(RuleNode node, String string) { String result = this.defaultResult(); int n = node.getChildCount(); for(int i = 0; i < n && this.shouldVisitNextChild(node, result); ++i) { ParseTree c = node.getChild(i); if(string.contains(c.getText())) continue; String childResult = c instanceof TerminalNode ? printTerminalNode((TerminalNode) c) : c.accept(this); result = this.aggregateResult(result, childResult); } return result; }
Example #10
Source File: Visitor.java From swift-js-transpiler with MIT License | 5 votes |
public String visitWithoutTerminals(RuleNode node) { String result = this.defaultResult(); int n = node.getChildCount(); for(int i = 0; i < n && this.shouldVisitNextChild(node, result); ++i) { ParseTree c = node.getChild(i); if(c instanceof TerminalNode) continue; String childResult = c.accept(this); result = this.aggregateResult(result, childResult); } return result; }
Example #11
Source File: Visitor.java From swift-js-transpiler with MIT License | 5 votes |
public String visitChildren(RuleNode node, List<Integer> withoutNodes) { if(node == null) return ""; String result = this.defaultResult(); int n = node.getChildCount(); for(int i = 0; i < n && this.shouldVisitNextChild(node, result); ++i) { if(withoutNodes != null && withoutNodes.contains(i)) continue; ParseTree c = node.getChild(i); String childResult = c instanceof TerminalNode ? printTerminalNode((TerminalNode) c) : c.accept(this); result = this.aggregateResult(result, childResult); } return result; }
Example #12
Source File: ProgramParser.java From yql-plus with Apache License 2.0 | 5 votes |
public static int getParseTreeIndex(ParseTree parseTree) { if (parseTree instanceof TerminalNode) { return ((TerminalNode) parseTree).getSymbol().getType(); } else { return ((RuleNode) parseTree).getRuleContext().getRuleIndex(); } }
Example #13
Source File: ParseTree.java From smartcheck with GNU General Public License v3.0 | 5 votes |
/** * @return root */ default RuleNode rootUnchecked() { try { return this.root(); } catch (Exception ex) { throw new RuntimeException(ex); } }
Example #14
Source File: ParseTreeCached.java From smartcheck with GNU General Public License v3.0 | 5 votes |
@Override public RuleNode root() { return this.cache.updateAndGet( root -> Optional .ofNullable(root) .orElseGet(this.origin::rootUnchecked) ); }
Example #15
Source File: ParseTreeBasicVyper.java From smartcheck with GNU General Public License v3.0 | 5 votes |
@Override public RuleNode root() throws Exception { return parserSetup( new ru.smartdec.smartcheck.VyperParser( new CommonTokenStream( lexerSetup( new ru.smartdec.smartcheck.VyperLexer( this.source.chars() ) ) ) ) ) .file_input(); }
Example #16
Source File: ParseTreeBasicSolidity.java From smartcheck with GNU General Public License v3.0 | 5 votes |
@Override public RuleNode root() throws Exception { return parserSetup( new ru.smartdec.smartcheck.SolidityParser( new CommonTokenStream( lexerSetup( new ru.smartdec.smartcheck.SolidityLexer( this.source.chars() ) ) ) ) ) .sourceUnit(); }
Example #17
Source File: ElasticSearchVisitor.java From elasticsearch-jdbc with MIT License | 4 votes |
@Override public ParserResult visitChildren(RuleNode node) { throw new UnsupportedOperationException("No children visitor implemented"); }
Example #18
Source File: ParseTreeCached.java From smartcheck with GNU General Public License v3.0 | 4 votes |
/** * @param tree parse tree to cache * @param reference cached tree */ public ParseTreeCached( final ParseTree tree, final AtomicReference<RuleNode> reference) { this.origin = tree; this.cache = reference; }
Example #19
Source File: RuleFilterVisitorImpl.java From SkaETL with Apache License 2.0 | 4 votes |
protected String text(RuleNode node) { return node == null ? "" : node.getText(); }
Example #20
Source File: RuleMetricVisitorImpl.java From SkaETL with Apache License 2.0 | 4 votes |
protected String text(RuleNode node) { return node == null ? "" : node.getText(); }
Example #21
Source File: DocumentTree.java From smartcheck with GNU General Public License v3.0 | 2 votes |
/** * @return root as rule node */ RuleNode ruleNode();
Example #22
Source File: ParseTree.java From smartcheck with GNU General Public License v3.0 | 2 votes |
/** * @return root * @throws Exception exception */ RuleNode root() throws Exception;
Example #23
Source File: Visitor.java From swift-js-transpiler with MIT License | votes |
@Override public String visitChildren(RuleNode node) { return visitChildren(node, null); }