Class: SoftLayer::ObjectMaskToken
- Inherits:
-
Object
- Object
- SoftLayer::ObjectMaskToken
- Defined in:
- lib/softlayer/ObjectMaskToken.rb
Overview
This class is an implementation detail of the Object Mask Parser It represents a single semantic token as parsed out of an Object Mask String
The class also generates error messages that the parser can use when it encounters an unexpected token
Constant Summary collapse
- KnownTokenTypes =
[ :invalid_token, :eos, # end of string :identifier, :property_set_start, :property_set_separator, :property_set_end, :property_type_start, :property_type_end, :property_child_separator, ]
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #end_of_string? ⇒ Boolean
- #eql?(other_token) ⇒ Boolean
-
#initialize(token_type, token_value = nil) ⇒ ObjectMaskToken
constructor
A new instance of ObjectMaskToken.
- #inspect ⇒ Object
- #invalid? ⇒ Boolean
- #mask_root_marker? ⇒ Boolean
- #valid_property_name? ⇒ Boolean
- #valid_property_type? ⇒ Boolean
Constructor Details
#initialize(token_type, token_value = nil) ⇒ ObjectMaskToken
Returns a new instance of ObjectMaskToken.
32 33 34 35 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 32 def initialize(token_type, token_value = nil) @type = token_type @value = token_value end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
17 18 19 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 17 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 18 def value @value end |
Class Method Details
.error_for_unexpected_token(token) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 65 def self.error_for_unexpected_token(token) case token.type when :invalid_token "Unrecognized token '#{token.value}'" when :eos "Unexpected end of string" when :identifier "Unexpected identifier '#{token.value}'" when :property_set_start "Unexpected '['" when :property_set_separator "Unexpected ','" when :property_set_end "Unexpected ']'" when :property_type_start "Unexpected '('" when :property_type_end "Unexpected ')'" when :property_child_separator "Unexpected '.'" else "Unexpected value (invalid token type)" end end |
Instance Method Details
#end_of_string? ⇒ Boolean
49 50 51 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 49 def end_of_string? return @type == :eos end |
#eql?(other_token) ⇒ Boolean
41 42 43 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 41 def eql?(other_token) @type.eql?(other_token.type) && @value.eql?(other_token.value) end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 37 def inspect "<#{@type.inspect}, #{@value.inspect}>" end |
#invalid? ⇒ Boolean
45 46 47 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 45 def invalid? return @type = :invalid_token end |
#mask_root_marker? ⇒ Boolean
53 54 55 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 53 def mask_root_marker? return @type == :identifier && (@value == "mask" || @value == "filterMask") end |
#valid_property_name? ⇒ Boolean
57 58 59 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 57 def valid_property_name? return @type == :identifier && @value.match(/\A[a-z][a-z0-9]*\z/i) end |
#valid_property_type? ⇒ Boolean
61 62 63 |
# File 'lib/softlayer/ObjectMaskToken.rb', line 61 def valid_property_type? return @type == :identifier && @value.match(/\A[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*\z/i) end |