title: How to parse selected expressions until an end keyword in pyparsing
body: <p>I am parsing a verilog file to extract the dependencies within it.  I don't need to parse most of the module contents, but am only interested in include statements and module instantiations.  I first am attempting to only extract the include statements. This is my code so far:</p>
  
  <pre><code>include_pragma = Group(Keyword("`include") + quotedString + lineEnd.suppress())
  module_definition = ZeroOrMore(~Keyword("endmodule") + MatchFirst([include_pragma, restOfLine])) + Keyword("endmodule")
  </code></pre>
  
  <p>My point is that I will either match an include pragma, or a line of anything until I reach "endmodule".  If I try this grammer on the following string, pyparsing gets into some kind of infinite loop.</p>
  
  <pre><code>`include "InternalInclude.v"
  
  localparam COMMA_WIDTH = 10;
  
  localparam  UNKNOWN = 1'b0,
              KNOWN   = 1'b1;
  
  reg     [DATA_WIDTH-1:0] TtiuPosQ2;
  reg                      TtiuDetQ2;
  reg     [           7:0] TtiuDetQ2Save;
  
  assign DebugQO = {  DataQI,         // 65:34
                      TxTrainingEnQI, // 33
                      TtiuDetQ2,      // 32
                      TtiuPosQ2       // 31:0
                    };
  
  always @(posedge Clk or posedge ResetI) begin
      if (ResetI) begin
          CommaPosQO &lt;= {(DATA_WIDTH){1'b0}};
          CommaDetQO &lt;= 0;
          CommaPosQ1 &lt;= {(DATA_WIDTH){1'b0}};
          CommaPosQ2 &lt;= {(DATA_WIDTH){1'b0}};
          CommaDetQ2 &lt;= 0;
          StateQ &lt;= 0;
  
          CommaPosSaveQ &lt;= {(DATA_WIDTH){1'b0}};
          TtiuPosQ1 &lt;= 0;
          TtiuPosQ2 &lt;= 0;
          TtiuDetQ2 &lt;= 0;
          TtiuDetQ2Save &lt;= 8'h00;
      end
      else begin 
          CommaPosQO &lt;= CommaPosC2;
          CommaDetQO &lt;= CommaDetC2;
          CommaPosQ1 &lt;= CommaPosC;
          CommaPosQ2 &lt;= CommaPosQ1;
          CommaDetQ2 &lt;= (| CommaPosQ1);
          StateQ &lt;= StateC;
          CommaPosSaveQ &lt;= CommaPosSaveC;
          TtiuPosQ1 &lt;= TtiuPosC1;
          TtiuPosQ2 &lt;= TtiuPosC2;
          TtiuDetQ2 &lt;= TtiuDetC2;
          TtiuDetQ2Save &lt;= TtiuDetQ2 ? 8'hFF : {1'b0, TtiuDetQ2Save[7:1]};
      end
  end
  
  endmodule
  </code></pre>
  
  <p>I am probably misunderstanding the ~ operator.  Any suggestions?</p>
  
  <p><strong>update</strong></p>
  
  <p>After using the setDebug() method suggested, I found that the infinite loops prints this:</p>
  
  <pre><code>Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 0(1,1)
  Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -&gt; [['`include'
  , '"InternalInclude.v"']]
  Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
  Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -&gt; ['']
  Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
  Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -&gt; ['']
  Match {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} at loc 31(4,1)
  Matched {Group:({"`include" quotedString using single or double quotes Suppress:(lineEnd)}) | Re:('.*')} -&gt; ['']
  </code></pre>
  
  <p>Is something that I do causing the parse position not to move forward?</p>