Exception: Yay::UnexpectedTokenError

Inherits:
Error
  • Object
show all
Defined in:
lib/yay/errors.rb

Overview

raised when an unexpected token was found by the parser. in otherwords, the rules of the syntax have been broken somehow and the user hasn’t written a valid command

Instance Attribute Summary collapse

Attributes inherited from Error

#position

Instance Method Summary collapse

Methods inherited from Error

#printable_position

Constructor Details

#initialize(type, value, position) ⇒ UnexpectedTokenError

Returns a new instance of UnexpectedTokenError.



164
165
166
167
168
# File 'lib/yay/errors.rb', line 164

def initialize type, value, position
  @type     = type
  @value    = value
  @position = position
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



161
162
163
# File 'lib/yay/errors.rb', line 161

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



162
163
164
# File 'lib/yay/errors.rb', line 162

def value
  @value
end

Instance Method Details

#extra_messageObject

add extra feedback for some tokens. help the user out!



171
172
173
174
175
# File 'lib/yay/errors.rb', line 171

def extra_message
  return "Since #{value} has a special meaning, try enclosing it in quotes or a regex when searching for it" if type == "colour"
  return "Have you finished the line off properly?" if type == "$end"
  return ""
end

#printable_messageObject



177
178
179
180
181
# File 'lib/yay/errors.rb', line 177

def printable_message
  return "Unexpected text \"#{value}\"#{printable_position}\n#{extra_message}" if type == "error"
  return "Unexpected end of line#{printable_position}\n#{extra_message}" if type == "$end"
  return "Unexpected #{type} \"#{value}\"#{printable_position}\n#{extra_message}"
end