title: antlr - loop through nodes
body: <p>I have the following grammar (simplified):</p>
  
  <pre><code>filter   : eq | and;
  
  eq       : 'eq' '(' property ',' value ')';
  
  and      : 'and' '(' filter ',' filter (',' filter)* ')';
  
  ...
  </code></pre>
  
  <p>I am parsing simple prefix constructions like:</p>
  
  <pre><code>and(eq(name,john),eq(location,usa))
  </code></pre>
  
  <p>What is the best way to loop through the <code>filter</code> nodes of a <code>and</code> node? The generated class <code>AndContext</code> has a function <code>filter(int index)</code>, but nothing more. I want to do something like:</p>
  
  <pre><code>AndContext c = ...;
  
  for (int i = 0; i &lt; c.numberOfFilters(); ++i) {
      FilterContext f = c.filter(i);
  }
  </code></pre>
  
  <p>There is the function <code>getChildCount()</code>, but it returns the count of all nodes (including the terminal nodes representing <code>(</code>, <code>)</code>, etc.), and not just the interesting <code>filter</code> nodes.</p>