Exception: ANTLR3::Error::RecognitionError

Inherits:
StandardError
  • Object
show all
Includes:
Constants
Defined in:
lib/antlr3/error.rb

Overview

The base class of the variety of syntax errors that can occur during the recognition process. These errors all typically concern an expectation built in to the recognizer by the rules of a grammar and an input symbol which failed to fit the expectation.

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

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ RecognitionError

Returns a new instance of RecognitionError.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/antlr3/error.rb', line 109

def initialize( input = nil )
  @index = @line =  @column = nil
  @approximate_line_info = false
  if @input = input
    @index = input.index
    @source_name = @input.source_name rescue nil
    case @input
    when TokenStream
      @token = @symbol = input.look
      @line   = @symbol.line
      @column = @symbol.column
    when CharacterStream
      @token = @symbol = input.peek || EOF
      @line   = @input.line
      @column = @input.column
    when AST::TreeNodeStream
      @symbol = @input.look
      if @symbol.respond_to?( :line ) and @symbol.respond_to?( :column )
        @line, @column = @symbol.line, @symbol.column
      else
        extract_from_node_stream( @input )
      end
    else
      @symbol = @input.look
      if @symbol.respond_to?( :line ) and @symbol.respond_to?( :column )
        @line, @column = @symbol.line, @symbol.column
      elsif @input.respond_to?( :line ) and @input.respond_to?( :column )
        @line, @column = @input.line, @input.column
      end
    end
  end
  super( message )
end

Instance Attribute Details

#columnObject

Returns the value of attribute column


107
108
109
# File 'lib/antlr3/error.rb', line 107

def column
  @column
end

#indexObject

Returns the value of attribute index


107
108
109
# File 'lib/antlr3/error.rb', line 107

def index
  @index
end

#inputObject

Returns the value of attribute input


107
108
109
# File 'lib/antlr3/error.rb', line 107

def input
  @input
end

#lineObject

Returns the value of attribute line


107
108
109
# File 'lib/antlr3/error.rb', line 107

def line
  @line
end

#source_nameObject

Returns the value of attribute source_name


107
108
109
# File 'lib/antlr3/error.rb', line 107

def source_name
  @source_name
end

#symbolObject

Returns the value of attribute symbol


107
108
109
# File 'lib/antlr3/error.rb', line 107

def symbol
  @symbol
end

#tokenObject

Returns the value of attribute token


107
108
109
# File 'lib/antlr3/error.rb', line 107

def token
  @token
end

Instance Method Details

#approximate_line_info?Boolean

Returns:

  • (Boolean)

143
144
145
# File 'lib/antlr3/error.rb', line 143

def approximate_line_info?
  @approximate_line_info
end

#locationObject


159
160
161
162
163
# File 'lib/antlr3/error.rb', line 159

def location
  if @source_name then "in #@source_name @ line #@line:#@column"
  else "line #@line:#@column"
  end
end

#unexpected_typeObject


147
148
149
150
151
152
153
154
155
156
157
# File 'lib/antlr3/error.rb', line 147

def unexpected_type
  case @input
  when TokenStream
    @symbol.type
  when AST::TreeNodeStream
    adaptor = @input.adaptor
    return adaptor.type( @symbol )
  else
    return @symbol
  end
end