title: ANTLR4 negative lookahead in lexer
body: <p>I am trying to define lexer rules for PostgreSQL SQL.</p>
  
  <p>The problem is with the operator definition and the line comments conflicting with each other.</p>
  
  <p>for example <code>@---</code> is an operator token <code>@-</code> followed by the <code>--</code> comment and not an operator token <code>@---</code> </p>
  
  <p>In <code>grako</code> it would be possible to define the negative lookahead for the <code>-</code> fragment like:</p>
  
  <pre><code>OP_MINUS: '-' ! ( '-' ) .
  </code></pre>
  
  <p>In ANTLR4 I could not find any way to rollback already consumed fragment.</p>
  
  <p>Any ideas?</p>
  
  <p>Here the original definition what the PostgreSQL operator can be:</p>
  
  <pre><code>The operator name is a sequence of up to NAMEDATALEN-1
  (63 by default) characters from the following list:
  
   + - * / &lt; &gt; = ~ ! @ # % ^ &amp; | ` ?
  
  There are a few restrictions on your choice of name:
  -- and /* cannot appear anywhere in an operator name,
  since they will be taken as the start of a comment.
  
  A multicharacter operator name cannot end in + or -,
  unless the name also contains at least one of these
  characters:
  
  ~ ! @ # % ^ &amp; | ` ?
  
  For example, @- is an allowed operator name, but *- is not.
  This restriction allows PostgreSQL to parse SQL-compliant
  commands without requiring spaces between tokens.
  </code></pre>