title: Lex - not detecting token after adding a new line
body: <p>I'm trying to write a program that reads action and its components from a <a href="https://en.wikipedia.org/wiki/Planning_Domain_Definition_Language" rel="nofollow noreferrer">PDDL</a> file. The program should first look for token <code>:action(</code> and then <code>action name</code> etc.</p>
  
  <p>Following is my lex code:</p>
  
  <p>Note: The answer to this question is mostly related to <code>:(action</code> token, <code>action name</code> token and <code>newline</code> token, so you might only look at those. By SC_ACNAME I mean scan action name etc.</p>
  
  <pre><code>%{
  #include "myscanner.h"
  %}
  
  %START SC_ACNAME SC_PARAMETERS SC_PREDICATE SC_BODY
  
  NAME                                [0-9a-zA-Z_\-]+
  TEXT                                [0-9a-zA-Z?_\-( \t]+
  TEXT_PARAM                          [0-9a-zA-Z?_\-( \t\n]+
  TEXTBREAK                           [ \t\n]+
  
      int lb_flag=0;
      int pred_lb_flag = 0;
  
  %%
  
  \(:action                                                               {lb_flag++; BEGIN SC_ACNAME; return ACTION;}
  &lt;SC_ACNAME&gt;{TEXT}                                                       {BEGIN SC_BODY; return ACTION_NAME;}
  &lt;SC_BODY&gt;:parameters                                                    {BEGIN SC_PARAMETERS; return PARAMETER;}
  &lt;SC_PARAMETERS&gt;{TEXT_PARAM}                                             {lb_flag++; BEGIN SC_BODY; return PARAMETERS;}  
  &lt;SC_BODY&gt;:precondition                                                  {BEGIN SC_PREDICATE; return PRECONDITION;}
  &lt;SC_BODY&gt;:effect                                                        {BEGIN SC_PREDICATE; return EFFECT;}
  &lt;SC_PREDICATE&gt;\(and                                                     {pred_lb_flag++; return CONJUNCTION;}
  &lt;SC_PREDICATE&gt;\(not                                                     {pred_lb_flag++; return NEGATION;}
  &lt;SC_PREDICATE&gt;\({NAME}({TEXTBREAK}\?{NAME})+\)                          return PREDICATE;
  &lt;SC_PREDICATE&gt;\)                                                        {if(pred_lb_flag) pred_lb_flag--; if(!pred_lb_flag) BEGIN SC_BODY; return RIGHT_BRACKET;}
  &lt;SC_BODY&gt;\)                                                             {if(lb_flag) lb_flag--; if(!lb_flag) BEGIN 0; return RIGHT_BRACKET;}
  &lt;SC_PREDICATE,SC_BODY,SC_ACNAME&gt;{TEXTBREAK}                             ;   
  
  %%
  
  int yywrap(void)
  {
      return 1;
  }
  </code></pre>
  
  <p>Header File (myscanner.h):</p>
  
  <pre><code>#define ACTION 1
  #define ACTION_NAME 2
  #define PARAMETER 3
  #define PARAMETERS 4
  #define PRECONDITION 5
  #define EFFECT 6
  #define CONJUNCTION 7
  #define NEGATION 8
  #define PREDICATE 9
  #define RIGHT_BRACKET 10
  </code></pre>
  
  <p>Following in my C program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "myscanner.h"
  
  extern int yylex();
  extern int yylineno;
  extern char* yytext;
  
  int main(void)
  {
      int ntoken, vtoken;
  
      ntoken = yylex();
      while(ntoken)
      {
          printf("%d", ntoken);
          print("%s", yytext);
          ntoken = yylex();
      }
      return 0;
  }
  </code></pre>
  
  <p>When I try to tokenise file which contains <code>(:action move</code> it detects <code>:(action</code> and <code>action name</code> as desired and returns ACTION and ACTION_NAME. But when I enter a newline after move (action name), it doesn't detect anything. Why is it not recognising the token <code>(:action</code>?</p>
  
  <p>EDIT: </p>
  
  <p>Pass Test Case: domain.pddl</p>
  
  <pre><code>(:action move
  </code></pre>
  
  <p>Failure Test Case: domain.pddl</p>
  
  <pre><code>(:action move&lt;nl&gt;
  </code></pre>
  
  <p> indicates newline</p>