Class: SoftLayer::ObjectMaskToken

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_type, token_value = nil) ⇒ ObjectMaskToken

Returns a new instance of ObjectMaskToken.



48
49
50
51
# File 'lib/softlayer/ObjectMaskToken.rb', line 48

def initialize(token_type, token_value = nil)
  @type = token_type
  @value = token_value
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



33
34
35
# File 'lib/softlayer/ObjectMaskToken.rb', line 33

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



34
35
36
# File 'lib/softlayer/ObjectMaskToken.rb', line 34

def value
  @value
end

Class Method Details

.error_for_unexpected_token(token) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/softlayer/ObjectMaskToken.rb', line 81

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

Returns:

  • (Boolean)


65
66
67
# File 'lib/softlayer/ObjectMaskToken.rb', line 65

def end_of_string?
  return @type == :eos
end

#eql?(other_token) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/softlayer/ObjectMaskToken.rb', line 57

def eql?(other_token)
  @type.eql?(other_token.type) && @value.eql?(other_token.value)
end

#inspectObject



53
54
55
# File 'lib/softlayer/ObjectMaskToken.rb', line 53

def inspect
  "<#{@type.inspect}, #{@value.inspect}>"
end

#invalid?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/softlayer/ObjectMaskToken.rb', line 61

def invalid?
  return @type = :invalid_token
end

#mask_root_marker?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/softlayer/ObjectMaskToken.rb', line 69

def mask_root_marker?
  return @type == :identifier && (@value == "mask" || @value == "filterMask")
end

#valid_property_name?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/softlayer/ObjectMaskToken.rb', line 73

def valid_property_name?
  return @type == :identifier && @value.match(/\A[a-z][a-z0-9]*\z/i)
end

#valid_property_type?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/softlayer/ObjectMaskToken.rb', line 77

def valid_property_type?
  return @type == :identifier && @value.match(/\A[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*\z/i)
end