Exception: ANTLR3::Error::RecognitionError
- Inherits:
-
StandardError
- Object
- StandardError
- ANTLR3::Error::RecognitionError
- 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.
Direct Known Subclasses
EarlyExit, FailedPredicate, MismatchedRange, MismatchedSet, MismatchedToken, MismatchedTreeNode, NoViableAlternative
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_NODE, Constants::INVALID_TOKEN, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#index ⇒ Object
Returns the value of attribute index.
-
#input ⇒ Object
Returns the value of attribute input.
-
#line ⇒ Object
Returns the value of attribute line.
-
#source_name ⇒ Object
Returns the value of attribute source_name.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #approximate_line_info? ⇒ Boolean
-
#initialize(input = nil) ⇒ RecognitionError
constructor
A new instance of RecognitionError.
- #location ⇒ Object
- #unexpected_type ⇒ Object
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( ) end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def column @column end |
#index ⇒ Object
Returns the value of attribute index.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def index @index end |
#input ⇒ Object
Returns the value of attribute input.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def input @input end |
#line ⇒ Object
Returns the value of attribute line.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def line @line end |
#source_name ⇒ Object
Returns the value of attribute source_name.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def source_name @source_name end |
#symbol ⇒ Object
Returns the value of attribute symbol.
107 108 109 |
# File 'lib/antlr3/error.rb', line 107 def symbol @symbol end |
#token ⇒ Object
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
143 144 145 |
# File 'lib/antlr3/error.rb', line 143 def approximate_line_info? @approximate_line_info end |
#location ⇒ Object
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_type ⇒ Object
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 |