class ANTLR3::Error::MissingToken

error

MissingToken

used by

parsers and tree parsers

occurs when

The recognizer expected to match some symbol, but it sees a different symbol. The symbol it sees is actually what the recognizer expected to match next.

Example

grammar:

grammar MissingTokenExample;

options { language = Ruby; }

@members {
  def report_error(e)
    raise e
  end
}

missing: A B C;

A: 'a';
B: 'b';
C: 'c';

in ruby:

require 'MissingTokenExampleLexer'
require 'MissingTokenExampleParser'

lexer = MissingTokenExample::Lexer.new( "ac" )  # <= notice the missing 'b'
tokens = ANTLR3::CommonTokenStream.new( lexer )
parser = MissingTokenExample::Parser.new( tokens )

parser.missing
# raises ANTLR3::Error::MissingToken: at "c"

Attributes

inserted[RW]

Public Class Methods

new( expecting, input, inserted ) click to toggle source
Calls superclass method ANTLR3::Error::MismatchedToken::new
# File lib/antlr3/error.rb, line 292
def initialize( expecting, input, inserted )
  super( expecting, input )
  @inserted = inserted
end

Public Instance Methods

message() click to toggle source
# File lib/antlr3/error.rb, line 301
def message
  if @inserted and @symbol
    "%s: inserted %p at %p" %
      [ self.class, @inserted, @symbol.text ]
  else
    msg = self.class.to_s
    msg << ': at %p' % token.text unless @token.nil?
    return msg
  end
end
missing_type() click to toggle source
# File lib/antlr3/error.rb, line 297
def missing_type
  return @expecting
end