class ANTLR3::Error::RecognitionError
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.
Attributes
column[RW]
index[RW]
input[RW]
line[RW]
source_name[RW]
symbol[RW]
token[RW]
Public Class Methods
new( input = nil )
click to toggle source
Calls superclass method
# 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
Public Instance Methods
approximate_line_info?()
click to toggle source
# File lib/antlr3/error.rb, line 143 def approximate_line_info? @approximate_line_info end
location()
click to toggle source
# 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_type()
click to toggle source
# 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
Private Instance Methods
extract_from_node_stream( nodes )
click to toggle source
# File lib/antlr3/error.rb, line 169 def extract_from_node_stream( nodes ) adaptor = nodes.adaptor payload = adaptor.token( @symbol ) if payload @token = payload if payload.line <= 0 i = -1 while prior_node = nodes.look( i ) prior_payload = adaptor.token( prior_node ) if prior_payload and prior_payload.line > 0 @line = prior_payload.line @column = prior_payload.column @approximate_line_info = true break end i -= 1 end else @line = payload.line @column = payload.column end elsif @symbol.is_a?( AST::Tree ) @line = @symbol.line @column = @symbol.column @symbol.is_a?( AST::CommonTree ) and @token = @symbol.token else type = adaptor.type( @symbol ) text = adaptor.text( @symbol ) token_class = @input.token_class rescue CommonToken @token = token_class.new @token.type = type @token.text = text @token end end