Exception: ANTLR3::Error::MissingToken

Inherits:
MismatchedToken show all
Defined in:
lib/antlr3/error.rb

Overview

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"

Constant Summary

Constants included from Constants

Constants::BUILT_IN_TOKEN_NAMES, Constants::DEFAULT, Constants::DOWN, Constants::EOF, Constants::EOF_TOKEN, Constants::EOR_TOKEN_TYPE, Constants::HIDDEN, Constants::INVALID, Constants::INVALID_TOKEN, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP

Instance Attribute Summary collapse

Attributes inherited from MismatchedToken

#expecting

Attributes inherited from RecognitionError

#column, #index, #input, #line, #source_name, #symbol, #token

Instance Method Summary collapse

Methods inherited from RecognitionError

#approximate_line_info?, #location, #unexpected_type

Constructor Details

#initialize(expecting, input, inserted) ⇒ MissingToken

Returns a new instance of MissingToken.


292
293
294
295
# File 'lib/antlr3/error.rb', line 292

def initialize( expecting, input, inserted )
  super( expecting, input )
  @inserted = inserted
end

Instance Attribute Details

#insertedObject

Returns the value of attribute inserted


291
292
293
# File 'lib/antlr3/error.rb', line 291

def inserted
  @inserted
end

Instance Method Details

#messageObject


301
302
303
304
305
306
307
308
309
310
# 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_typeObject


297
298
299
# File 'lib/antlr3/error.rb', line 297

def missing_type
  return @expecting
end