title: antlr grammar for comments, and plain text between tags
body: <p>Follow-up question to : <a href="https://stackoverflow.com/questions/49365090/getting-plain-text-in-antlr-instead-of-tokens">Getting plain text in antlr instead of tokens</a></p>
  
  <p>1.I used a rule</p>
  
  <p><code>COMMENT : START_1_TAG START_COMMENT END_1_TAG .*? START_2_TAG END_COMMENT END_2_TAG  -&gt; skip;</code></p>
  
  <p>to skip any comments using my lexer.
  But, I get a mismatched input , when I give any space inside the tags. </p>
  
  <p>The part of my relevant part of my Lexer is:</p>
  
  <pre><code>lexer grammar DemoLexer;
  
  START_1_TAG : '&lt;%' -&gt; pushMode(IN_TAG);
  START_2_TAG : '&lt;&lt;' -&gt; pushMode(IN_TAG);
  
  COMMENT : START_1_TAG START_COMMENT END_1_TAG .*? START_2_TAG END_COMMENT END_2_TAG  -&gt; skip;
  
  TEXT        : ( ~[&lt;] | '&lt;' ~[&lt;%] )+;
  
  mode IN_TAG;
  START_COMMENT : 'startcomment' ;
  END_COMMENT : 'endcomment' ;
  ID         : [A-Za-z_][A-Za-z0-9_]*;
  INT_NUMBER : [0-9]+;
  END_1_TAG  : '%&gt;' -&gt; popMode;
  END_2_TAG  : '&gt;&gt;' -&gt; popMode;
  SPACE      : [ \t\r\n] -&gt; channel(HIDDEN);
  </code></pre>
  
  <p>My issue is, <code>&lt;%comment%&gt;hi&lt;%endcomment%&gt;</code> gets parsed correctly. But, while I give my input as, <code>&lt;% comment %&gt;</code> or <code>&lt;% endcomment %&gt;</code>, with spaces in between the tags, it is not recognized by the COMMENT rule.</p>
  
  <p>It gets recognized by the COMMENT rule, when I define the rule as:</p>
  
  <p><code>COMMENT : START_1_TAG SPACE*? 'commentstart' SPACE*? END_1_TAG .*? START_1_TAG SPACE*? 'commentend' SPACE*? END_1_TAG -&gt; skip;</code></p>
  
  <p>with explicit spaces.</p>
  
  <p>Is this the proper method to handle this?</p>
  
  <p>2.I have a rule where I need the raw content inside a tag pair. 
  Eg:</p>
  
  
  
  <p>Here, the tokens need to be &lt;%startraw%>,&lt;%Hi%> and &lt;%endraw%></p>
  
  <p>I tried using the text rule, but it dosen't work because it dosen't include '&lt;%' and '&lt;&lt;'.</p>
  
  <p>I tried:</p>
  
  <p>in my parser,</p>
  
  <pre><code>rawText : RAW_TAG_START RAW_TEXT RAW_TAG_END ;
  </code></pre>
  
  <p>in my lexer,</p>
  
  <pre><code>RAW_TAG_START : '&lt;%' 'startraw' '%&gt;' -&gt; pushMode(RAW_MODE);
  RAW_TAG_END : '&lt;%' 'endraw' '%&gt;' -&gt; popMode; 
  mode RAW_MODE;
    RAW_TEXT : .*? ;
  </code></pre>
  
  <p>For some reason, when I try to parse this with the intellij antlr plugin, it seems to freeze and crash whenever I try to match the rawText rule.</p>