title: How to trigger functions in subnodes in Ruby Treetop tree. (was:How to prevent ruby Treetop doing AST squashing)
body: <p>I am been using treetop for a while. I wrote rules following </p>
  
  <p><a href="http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html" rel="nofollow noreferrer">http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html</a></p>
  
  <p>I can parse my whole input string but i none of the other <code>to_array</code> function gets triggered other than the initial one.</p>
  
  <p>Then I found <a href="https://whitequark.org/blog/2011/09/08/treetop-typical-errors/" rel="nofollow noreferrer">https://whitequark.org/blog/2011/09/08/treetop-typical-errors/</a> which talk about <code>AST squashing</code> and I figured out that my rule is doing the same.</p>
  
  <p>The first rule I have is </p>
  
  <pre><code>  rule bodies
      blankLine* interesting:(body+) blankLine* &lt;Bodies&gt;
    end
  </code></pre>
  
  <p>and everything is getting gobbled up by <code>body</code>.</p>
  
  <p>Can someone suggest me what can I do to fix this?</p>
  
  <p><strong>Edit</strong>
  Adding code snippet:</p>
  
  <pre><code>grammar Sexp
  
    rule bodies
      blankLine* interesting:(body+) blankLine* &lt;Bodies&gt;
    end
  
    rule body
      commentPortString (ifdef_blocks / interface)+ (blankLine / end_of_file) &lt;Body&gt;
    end
  
    rule interface
      space? (intf / intfWithSize) space?  newLine &lt;Interface&gt;
    end
  
    rule commentPortString
      space? '//' space portString space?  &lt;CommentPortString&gt;
    end
  
    rule portString
      'Port' space? '.' newLine &lt;PortString&gt;
    end
  
    rule expression
      space? '(' body ')' space? &lt;Expression&gt;
    end
  
    rule intf
      (input / output) space wire:wireName space? ';' &lt;Intf&gt;
    end
  
    rule intfWithSize
      (input / output) space? width:ifWidth space? wire:wireName space? ';' &lt;IntfWithSize&gt;
    end
  
    rule input
      'input' &lt;InputDir&gt;
    end
  
    rule output
      'output' &lt;OutputDir&gt;
    end
  
    rule ifdef_blocks
      ifdef_line (interface / ifdef_block)* endif_line &lt;IfdefBlocks&gt;
    end
  
    rule ifdef_block
      ifdef_line interface* endif_line &lt;IfdefBlocks&gt;
    end
  
    rule ifdef_line
      space? (ifdef / ifndef) space+  allCaps space? newLine &lt;IfdefLine&gt;
    end
  
    rule endif_line
      space? (endif) space? newLine &lt;EndifLine&gt;
    end
  
    rule ifdef
      '`ifdef' &lt;Ifdef&gt;
    end
  
    rule ifndef
      '`ifndef' &lt;Ifndef&gt;
    end
  
    rule endif
      '`endif' &lt;Endif&gt;
    end
  
    rule ifWidth
      '[' space? msb:digits space? ':' space? lsb:digits ']' &lt;IfWidth&gt;
    end
  
    rule digits
      [0-9]+ &lt;Digits&gt;
    end
  
    rule integer
      ('+' / '-')? [0-9]+ &lt;IntegerLiteral&gt;
    end
  
    rule float
      ('+' / '-')? [0-9]+ (('.' [0-9]+) / ('e' [0-9]+)) &lt;FloatLiteral&gt;
    end
  
    rule string
      '"' ('\"' / !'"' .)* '"' &lt;StringLiteral&gt;
    end
  
    rule identifier
      [a-zA-Z\=\*] [a-zA-Z0-9_\=\*]* &lt;Identifier&gt;
    end
  
    rule allCaps
      [A-Z] [A-Z0-9_]*
    end
  
    rule wireName
      [a-zA-Z] [a-zA-Z0-9_]* &lt;WireName&gt;
    end
  
    rule non_space
      !space .
    end
  
    rule space
      [^\S\n]+
    end
  
    rule non_space
      !space .
    end
  
    rule blankLine
      space* newLine
    end
  
    rule not_newLine
      !newLine .
    end
  
    rule newLine
      [\n\r]
    end
  
    rule end_of_file
      !.
    end
  
  end
  </code></pre>
  
  <p>Test string</p>
  
  <pre><code>// Port.
  input         CLK;
  
  // Port.
  input         REFCLK;
  
  // Port.
  input [ 41:0] mem_power_ctrl;
  output data;
  </code></pre>
  
  <p>EDIT: Adding more details</p>
  
  <p>The test code is checked into:
  <a href="https://github.com/justrajdeep/treetop_ruby_issue" rel="nofollow noreferrer">https://github.com/justrajdeep/treetop_ruby_issue</a>.</p>
  
  <p>As you would see in my <code>node_extensions.rb</code> all the nodes except the <code>Bodies</code> raise an exception in the method <code>to_array</code>. But none of the exceptions trigger.</p>