title: How do I use ANTLR to check for valid variable names?
body: <p>We all know variable names cannot start with a number.  (eg. foo1 is valid, 1foo is not).</p>
  
  <p>I am trying to write a grammar file to allow only valid variable names, and they must be followed by a colon.  (This is part of a much larger grammar - I'm just stuck on this one part)</p>
  
  <p>It seems like it should be simple.  I define a rule <strong>id</strong> that takes in only an alpha value as its first character, followed by any number of alpha-numeric characters.  However what seems like a simple task is failing for me.  Can anyone explain why?</p>
  
  <p>Here is my grammar:</p>
  
  <pre><code>grammar validName;
  
  var_declaration :VAR id COLON;
  VAR: 'var';
  COLON: ':';
  DIGIT: [0-9];
  ALPHA: [a-zA-Z_];
  ALPHANUM: ALPHA | DIGIT;
  
  id: ALPHA ALPHANUM*;
  
  WS: [ \n\t\r]+ -&gt; skip;
  </code></pre>
  
  <p>Here is my test input:</p>
  
  <pre><code>var myId : 
  </code></pre>
  
  <p>And here is the error:</p>
  
  <pre><code>line 1:5 mismatched input 'y' expecting ':'
  </code></pre>
  
  <p>Why is ALPHANUM* not matching anything??</p>