title: Writing parser rules sensitive to whitespace while skipping WS from the lexer
body: <p>I am having some troubles in handling whitespace. In the following excerpt of a grammar, I set up the lexer so that the parser skips whitespace:</p>
  
  <pre><code>ENTITY_VAR
      : 'user'
      | 'resource'
      ;
  
  INT : DIGIT+ | '-' DIGIT+ ;
  ID : LETTER (LETTER | DIGIT | SPECIAL)* ;
  ENTITY_ID : '__' ENTITY_VAR ('_w_' ID)?;
  
  NEWLINE : '\r'? '\n';
  
  WS : [ \t\r\n]+ -&gt; skip; // skip spaces, tabs, newlines
  
  fragment LETTER : [a-zA-Z];
  fragment DIGIT : [0-9];
  fragment SPECIAL : ('_' | '#' );
  </code></pre>
  
  <p>The problem is, I would like to match against variables names of the form <code>ENTITY_ID</code> such that the matched string does not have any whitespace. It would be sufficient to write it as a lexer rule as I did here, but the thing is that I'd like to do it with a parser rule instead, because I want to have direct access to those two tokens <code>ENTITY_VAR</code> and <code>ID</code> individually from my code, and not squeeze them back together in a whole token <code>ENTITY_ID</code>.</p>
  
  <p>Any ideas, please?
  Basically any solution which let me access directly <code>ENTITY_VAR</code> and <code>ID</code> would suit me, both by leaving <code>ENTITY_ID</code> as a lexer rule or moving it to the parser.</p>