title: Antlr Extraneous Input
body: <p>I have a grammar file BoardFile.g4 that has (relevant parts only):</p>
  
  <pre><code>grammar Board;
  
  //Tokens
  GADGET : 'squareBumper' | 'circleBumper' | 'triangleBumper' | 'leftFlipper' | 'rightFlipper' | 'absorber' | 'portal' ;
  NAME : [A-Za-z_][A-Za-z_0-9]* ;
  INT : [0-9]+ ;
  FLOAT : '-'?[0-9]+('.'[0-9]+)? ;
  COMMENT : '#' ~( '\r' | '\n' )*;
  WHITESPACE : [ \t\r\n]+ -&gt; skip ;
  KEY : [a-z] | [0-9] | 'shift' | 'ctrl' | 'alt' | 'meta' | 'space' | 'left' | 'right' | 'up' | 'down' | 'minus' | 'equals' | 'backspace' | 'openbracket' | 'closebracket' | 'backslash' | 'semicolon' | 'quote' | 'enter' | 'comma' | 'period' | 'slash' ;
  KEYPRESS : 'keyup' | 'keydown' ;
  
  //Rules
  file : define+ EOF ;
  define : board | ball | gadget | fire | COMMENT | key ;
  board : 'board' 'name' '=' name ('gravity' '=' gravity)? ('friction1' '=' friction1)? ('friction2' '=' friction2)? ;
  ball : 'ball' 'name' '=' name 'x' '=' xfloat 'y' '=' yfloat 'xVelocity' '=' xvel 'yVelocity' '=' yvel ;
  gadget : gadgettype 'name' '=' name 'x' '=' xint 'y' '=' yint ('width' '=' width 'height' '=' height)? ('orientation' '=' orientation)? ('otherBoard' '=' name 'otherPortal' '=' name)? ;
  fire : 'fire' 'trigger' '=' trigger 'action' '=' action ;
  key : keytype 'key' '=' KEY 'action' '=' name ;
  
  name : NAME ;
  gadgettype : GADGET ;
  keytype : KEYPRESS ;
  gravity : FLOAT ;
  friction1 : FLOAT ;
  friction2 : FLOAT ;
  trigger : NAME ;
  action : NAME ;
  yfloat : FLOAT ;
  xfloat : FLOAT ;
  yint : INT ;
  xint : INT ;
  xvel : FLOAT ;
  yvel : FLOAT ;
  orientation : INT ;
  width : INT ;
  height : INT ;
  </code></pre>
  
  <p>This generates the lexer and parser fine. However, when I use it against  the following file, it gives the following error:</p>
  
  <pre><code>line 12:0 extraneous input 'keyup' expecting {&lt;EOF&gt;, KEYPRESS}
  </code></pre>
  
  <p><strong>File to Parse:</strong></p>
  
  <p>board name=keysBoard gravity=5.0 friction1=0.0 friction2=0.0</p>
  
  <pre><code># define a ball
  ball name=Ball x=0.5 y=0.5 xVelocity=2.5 yVelocity=2.5
  
  # add some flippers
  leftFlipper name=FlipL1 x=16 y=2 orientation=0
  leftFlipper name=FlipL2 x=16 y=9 orientation=0
  
  # add keys. lots of keys.
  keyup key=space action=apple
  keydown key=a action=ball
  keyup key=backslash action=cat
  keydown key=period action=dog
  </code></pre>
  
  <p>I went through other questions about this error in SO but none helped me. I cannot figure out what's going wrong. Why am I getting this error?</p>