Class: SoftLayer::ObjectMaskTokenizer
- Inherits:
-
Object
- Object
- SoftLayer::ObjectMaskTokenizer
- Defined in:
- lib/softlayer/ObjectMaskTokenizer.rb
Overview
This class is an implementation detail of the ObjectMaskParser
It takes an Object Mask String and breaks it down into ObjectMaskToken instances.
Constant Summary collapse
- ObjectMask_Token_Specs =
[ [/\[/, :property_set_start], [/\,/, :property_set_separator], [/\]/, :property_set_end], [/\(/, :property_type_start], [/\)/, :property_type_end], [/\./, :property_child_separator], [/[a-z][a-z0-9_]*/i, :identifier] ]
Instance Method Summary collapse
- #current_token ⇒ Object
-
#initialize(mask_string) ⇒ ObjectMaskTokenizer
constructor
A new instance of ObjectMaskTokenizer.
- #more_tokens? ⇒ Boolean
- #next_token ⇒ Object
Constructor Details
#initialize(mask_string) ⇒ ObjectMaskTokenizer
Returns a new instance of ObjectMaskTokenizer.
28 29 30 31 32 |
# File 'lib/softlayer/ObjectMaskTokenizer.rb', line 28 def initialize(mask_string) @mask_string = mask_string.clone @scanner = StringScanner.new(@mask_string) @current_token = nil end |
Instance Method Details
#current_token ⇒ Object
38 39 40 41 |
# File 'lib/softlayer/ObjectMaskTokenizer.rb', line 38 def current_token @current_token = next_token if !@current_token @current_token end |
#more_tokens? ⇒ Boolean
34 35 36 |
# File 'lib/softlayer/ObjectMaskTokenizer.rb', line 34 def more_tokens? return @current_token == nil || !@current_token.end_of_string? end |
#next_token ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/softlayer/ObjectMaskTokenizer.rb', line 43 def next_token # if we're at the end of the string, we keep returning the # EOS token if more_tokens? then if !@scanner.eos? # skip whitespace @scanner.skip(/\s+/) # search through the token specs to find which (if any) matches token_spec = ObjectMask_Token_Specs.find() do |token_spec| @scanner.check(token_spec[0]) end # if a good token spec was found, set the current token to the one found if token_spec @current_token = ObjectMaskToken.new(token_spec.last, @scanner.scan(token_spec[0])) else @current_token = ObjectMaskToken.new(:invalid_token, @scanner.rest) @scanner.terminate end else @current_token = ObjectMaskToken.new(:eos) end end @current_token end |