title: How to use the ANTLR lexer token value in a conditional rule rewrite
body: <p>I am kind of new to ANTLR and would like to do the following:</p>
  
  <p>Given the grammar snippet below, I have a choice rule *comparison_op* that can match one of many tokens. What I would like to do is write conditional rewrite rules - such as, if token is <em>DOESNOTENDWITH</em> do something, if it is <em>DOESNOTCONTAIN</em> do something etc. </p>
  
  <p>I just can't seem to get this right. Is it even possible to do this? Of course, I can write specific rules for each condition, but that does not seem to be the best way either. </p>
  
  <p>Any suggestions?</p>
  
  <hr>
  
  <pre><code>{... snipped ...}
  
  DOESNOTBEGINWITH        : 'does not begin with';
  DOESNOTENDWITH          : 'does not end with';
  DOESNOTCONTAIN          : 'does not contain';
  
  comparison_op           : DOESNOTBEGINWITH | DOESNOTENDWITH | DOESNOTCONTAIN
  condition_comparison    : (column_name comparison_op v1=valueExpression) 
                          -&gt;  {$comparison_op.text == $DOESNOTBEGINWITH.text}?  
                                      ^(LIKE column_name $v1)
                          -&gt;          ^(comparison_op column_name $v1);
  </code></pre>