title: ANTLR: Extraneous input problem
body: <p>I have a grammar file Bookings.g and the file I try to parse with that grammar.</p>
  
  <p>Why am I getting these errors?</p>
  
  <p>line 1:12 extraneous input '"pcc"' expecting String
  line 3:0 mismatched input '}' expecting ScenarioPart1
  line 7:13 mismatched input '"R"' expecting String
  line 9:8 mismatched input '"Doll"' expecting String
  line 15:8 mismatched input '"Train"' expecting String
  line 21:8 mismatched input '"Ball"' expecting String
  line 34:0 missing EOF at '}'</p>
  
  <p><strong>Grammar</strong></p>
  
  <pre><code>grammar Bookings;
  
  @members
  {
      private DefaultBookingsFile bookingsFile;
  
      public DefaultBookingsFile getBookingsFile()
      {
          return this.bookingsFile;
      }
  
  }
  
  @header { 
  
  package at.silverstrike.pcc.impl.tj3bookingsparser.grammar; 
  
  import org.slf4j.Logger;
  
  }
  
  @lexer::header {
  package at.silverstrike.pcc.impl.tj3bookingsparser.grammar;
  }
  
  bookingsFile
    : 
      {
          this.bookingsFile = new DefaultBookingsFile();
      }
    header
    projectIds
    resourceDeclaration
    task+
    (
      suppTask=supplementTask { this.bookingsFile.addSupplementStatement( $suppTask.suppStmt ); }
    )*
    supplementResource*
    EOF
    ;
  
  header
      :
      Project Prj String String DateTimeWithTimeZone Hyphen DateTimeWithTimeZone OpenParen TimeZone Utc 
      ScenarioPart1 OpenParen ScenarioPart2 CloseParen 
      CloseParen
      ;
  
  ScenarioPart1
      :
      'scenario plan "Plan"'
      ;
  
  ScenarioPart2
      :
      'active yes'
      ;
  
  TimeZone
      :
      'timezone'
      ;
  
  Utc
      :
      '"'A+'"'
      ;
  
  projectIds:
      Projectids Prj
      ;
  
  resourceDeclaration
      : Resource Identifier String
      ;
  
  task
      :
      Task Identifier String OpenParen
      (task)* 
      (Start DateTimeWithTimeZone
      End DateTimeWithTimeZone
      Scheduling Asap
      Scheduled)*
      CloseParen
      ;
  
  /* (Complete FloatingPointNumber)* */
  
  supplementTask returns [DefaultSupplementStatement suppStmt]
      :
          {
              suppStmt = new DefaultSupplementStatement();
          }   
      Supplement Task taskId=Identifier {suppStmt.setTaskId($taskId.text); } 
      OpenParen
      (
      bStmt=booking {suppStmt.addBookingStatement( $bStmt.stmt ); }
      )*  
      Priority IntegerNumber
      CloseParen
      ;
  
  supplementResource
      :
      Supplement Resource Identifier OpenParen
      workinghours+
      CloseParen
      ;
  
  workinghours
      :
      Workinghours DayOfWeek (Off|workingIntervals)
      ;
  
  Workinghours
      : 'workinghours'
      ;
  
  workingIntervals
      :
      workingInterval (Comma workingInterval)*
      ; 
  
  workingInterval
      : Time Hyphen Time
      ;
  
  Time
      : IntegerNumber Colon IntegerNumber
      ; 
  
  Colon
      :
      ':'
      ;
  
  Comma
      :
      ','
      ;
  
  DayOfWeek
      : 'mon'
      | 'tue'
      | 'wed'
      | 'thu'
      | 'fri'
      | 'sat'
      | 'sun'
      ;
  
  Off
      :
      'off'
      ;
  
  booking  returns [DefaultBookingStatement stmt]
      :
      {
          stmt = new DefaultBookingStatement();
      }
      Booking resource=Identifier { stmt.setResource($resource.text); }  
      bt1=bookingTime { stmt.addIndBooking($bt1.indBooking); } 
      (Comma 
      bt2=bookingTime  { stmt.addIndBooking($bt2.indBooking); } 
      )*
      (OpenParen 
      overtime 
      CloseParen)
      ;
  
  bookingTime returns [DefaultIndBooking indBooking]
      :
      startTime=DateTimeWithTimeZone 
      Plus 
      bookingDuration=FloatingPointNumberDuration
      {
          $indBooking = new DefaultIndBooking($startTime.text, $bookingDuration.text);
      }
      ;
  
  Booking
      :
      'booking'
      ;
  
  Plus
      :
      '+'
      ;
  
  duration
      :
      FloatingPointNumber 'h'
      ;
  
  overtime
      :
      Overtime IntegerNumber
      ;
  
  Overtime
      :
      'overtime'
      ;
  
  Supplement
      :
      'supplement'
      ;
  
  Priority
      :
      'priority'
      ;
  
  Complete
      :
      'complete'
      ;
  
  Start
      :
      'start'
      ;
  
  End
      :
      'end'
      ;
  
  Scheduling
      :
      'scheduling'
      ;
  
  Asap
      :
      'asap'
      ;
  
  Scheduled
      :
      'scheduled'
      ;
  
  Task
      :
      'task'
      ;
  
  Resource
      :
      'resource'
      ;
  
  Projectids
      :
      'projectids'
      ;
  
  Project
    :  'project'
    ;
  
  Prj
    :  'prj'
    ;
  
  OpenParen
    :  '{'
    ;
  
  CloseParen
    :  '}'
    ;
  
  Hyphen
    :  '-'
    ;
  
  FloatingPointNumber
    : D+'.'D+
    ;
  FloatingPointNumberDuration
    : D+ P D+ H
    ;
  
  IntegerNumber
    : D+
    ;
  
  Identifier
    : (D|A|P)+;
  
  String
    :  '"' ~'"'* '"'
    ;
  
  DateTimeWithTimeZone
    :  D D D D '-' D D '-' D D '-' D D ':' D D '-+' D D D D
    ;  
  
  fragment    
  D
    :  '0'..'9'
    ;
  
  fragment
  A
    : 'A'..'Z'
    | 'a'..'z'
    ;
  
  fragment
  P
    : '.'
    ;
  
  fragment
  H
    : 'h'
    ;
  
  
  Space   
    :  (' ' | '\t' | '\r'? '\n'){$channel=HIDDEN;}
    ;
  </code></pre>
  
  <p><strong>File to parse</strong></p>
  
  <pre><code>project prj "pcc" "1.0" 2011-09-04-00:00-+0000 - 2011-10-04-10:00-+0000 {
    timezone "UTC"
    scenario plan "Plan" {
      active yes
    }
  }
  
  projectids prj
  
  resource R62 "R"
  
  task T1 "Doll" {
    start 2011-09-05-14:00-+0000
    end 2011-09-05-16:00-+0000
    scheduling asap
    scheduled
  }
  task T2 "Train" {
    start 2011-09-05-11:00-+0000
    end 2011-09-05-14:00-+0000
    scheduling asap
    scheduled
  }
  task T4 "Ball" {
    task T3 "Big ball" {
      start 2011-09-05-09:00-+0000
      end 2011-09-05-11:00-+0000
      scheduling asap
      scheduled
    }
    task T5 "Small ball" {
      start 2011-09-05-16:00-+0000
      end 2011-09-05-17:00-+0000
      scheduling asap
      scheduled
    }
  }
  supplement task T1 {
    booking R62 2011-09-05-14:00-+0000 + 2.0h { overtime 2 }
    priority 997
    projectid prj
  }
  supplement task T2 {
    booking R62 2011-09-05-11:00-+0000 + 3.0h { overtime 2 }
    priority 998
    projectid prj
  }
  supplement task T4 {
    priority 0
    projectid prj
  }
  supplement task T4.T3 {
    booking R62 2011-09-05-09:00-+0000 + 2.0h { overtime 2 }
    priority 1000
    projectid prj
  }
  supplement task T4.T5 {
    booking R62 2011-09-05-16:00-+0000 + 1.0h { overtime 2 }
    priority 996
    projectid prj
  }
  supplement resource R62 {
    workinghours sun off
                 workinghours mon 9:00 - 17:00
                 workinghours tue 9:00 - 17:00
                 workinghours wed 9:00 - 17:00
                 workinghours thu 9:00 - 17:00
                 workinghours fri 9:00 - 17:00
                 workinghours sat off
  }
  </code></pre>
  
  <p>UPD, 05.09.2011 00:24 CEST: Here's the corrected grammar file that works.</p>
  
  <pre><code>grammar Bookings;
  
  @members
  {
      private DefaultBookingsFile bookingsFile;
  
      public DefaultBookingsFile getBookingsFile()
      {
          return this.bookingsFile;
      }
  
  }
  
  @header { 
  
  package at.silverstrike.pcc.impl.tj3bookingsparser.grammar; 
  
  import org.slf4j.Logger;
  
  }
  
  @lexer::header {
  package at.silverstrike.pcc.impl.tj3bookingsparser.grammar;
  }
  
  bookingsFile
    : 
      {
          this.bookingsFile = new DefaultBookingsFile();
      }
    header
    projectIds
    resourceDeclaration
    task+
    (
      suppTask=supplementTask { this.bookingsFile.addSupplementStatement( $suppTask.suppStmt ); }
    )*
    supplementResource*
    EOF
    ;
  
  header
      :
      Project Prj String String DateTimeWithTimeZone Hyphen DateTimeWithTimeZone OpenParen TimeZone String 
      ScenarioPart1 OpenParen ScenarioPart2 CloseParen 
      CloseParen
      ;
  
  ScenarioPart1
      :
      'scenario plan "Plan"'
      ;
  
  ScenarioPart2
      :
      'active yes'
      ;
  
  TimeZone
      :
      'timezone'
      ;
  
  projectIds:
      Projectids Prj
      ;
  
  resourceDeclaration
      : Resource Identifier String
      ;
  
  task
      :
      Task Identifier String OpenParen
      (task)* 
      (Start DateTimeWithTimeZone
      End DateTimeWithTimeZone
      Scheduling Asap
      Scheduled)*
      CloseParen
      ;
  
  /* (Complete FloatingPointNumber)* */
  
  supplementTask returns [DefaultSupplementStatement suppStmt]
      :
          {
              suppStmt = new DefaultSupplementStatement();
          }   
      Supplement Task taskId=Identifier {suppStmt.setTaskId($taskId.text); } 
      OpenParen
      (
      bStmt=booking {suppStmt.addBookingStatement( $bStmt.stmt ); }
      )*  
      Priority IntegerNumber
      ProjectIdPrj
      CloseParen
      ;
  
  supplementResource
      :
      Supplement Resource Identifier OpenParen
      workinghours+
      CloseParen
      ;
  
  workinghours
      :
      Workinghours DayOfWeek (Off|workingIntervals)
      ;
  
  Workinghours
      : 'workinghours'
      ;
  
  workingIntervals
      :
      workingInterval (Comma workingInterval)*
      ; 
  
  workingInterval
      : Time Hyphen Time
      ;
  
  Time
      : IntegerNumber Colon IntegerNumber
      ; 
  
  Colon
      :
      ':'
      ;
  
  Comma
      :
      ','
      ;
  
  DayOfWeek
      : 'mon'
      | 'tue'
      | 'wed'
      | 'thu'
      | 'fri'
      | 'sat'
      | 'sun'
      ;
  
  Off
      :
      'off'
      ;
  
  booking  returns [DefaultBookingStatement stmt]
      :
      {
          stmt = new DefaultBookingStatement();
      }
      Booking resource=Identifier { stmt.setResource($resource.text); }  
      bt1=bookingTime { stmt.addIndBooking($bt1.indBooking); } 
      (Comma 
      bt2=bookingTime  { stmt.addIndBooking($bt2.indBooking); } 
      )*
      (OpenParen 
      overtime 
      CloseParen)
      ;
  
  bookingTime returns [DefaultIndBooking indBooking]
      :
      startTime=DateTimeWithTimeZone 
      Plus 
      bookingDuration=FloatingPointNumberDuration
      {
          $indBooking = new DefaultIndBooking($startTime.text, $bookingDuration.text);
      }
      ;
  
  ProjectIdPrj
      :
      'projectid prj'
      ;
  
  Booking
      :
      'booking'
      ;
  
  Plus
      :
      '+'
      ;
  
  duration
      :
      FloatingPointNumber 'h'
      ;
  
  overtime
      :
      Overtime IntegerNumber
      ;
  
  Overtime
      :
      'overtime'
      ;
  
  Supplement
      :
      'supplement'
      ;
  
  Priority
      :
      'priority'
      ;
  
  Complete
      :
      'complete'
      ;
  
  Start
      :
      'start'
      ;
  
  End
      :
      'end'
      ;
  
  Scheduling
      :
      'scheduling'
      ;
  
  Asap
      :
      'asap'
      ;
  
  Scheduled
      :
      'scheduled'
      ;
  
  Task
      :
      'task'
      ;
  
  Resource
      :
      'resource'
      ;
  
  Projectids
      :
      'projectids'
      ;
  
  Project
    :  'project'
    ;
  
  Prj
    :  'prj'
    ;
  
  OpenParen
    :  '{'
    ;
  
  CloseParen
    :  '}'
    ;
  
  Hyphen
    :  '-'
    ;
  
  FloatingPointNumber
    : D+'.'D+
    ;
  FloatingPointNumberDuration
    : D+ P D+ H
    ;
  
  IntegerNumber
    : D+
    ;
  
  Identifier
    : (D|A|P)+;
  
  String
    :  '"' ~'"'* '"'
    ;
  
  DateTimeWithTimeZone
    :  D D D D '-' D D '-' D D '-' D D ':' D D '-+' D D D D
    ;  
  
  fragment    
  D
    :  '0'..'9'
    ;
  
  fragment
  A
    : 'A'..'Z'
    | 'a'..'z'
    ;
  
  fragment
  P
    : '.'
    ;
  
  fragment
  H
    : 'h'
    ;
  
  
  Space   
    :  (' ' | '\t' | '\r'? '\n'){$channel=HIDDEN;}
    ;
  </code></pre>