Class: Accessibility::String::Lexer
- Inherits:
-
Object
- Object
- Accessibility::String::Lexer
- Defined in:
- lib/accessibility/string.rb
Overview
Tokenizer for strings. This class will take a string and break it up into chunks for the event generator. The structure generated here is an array that contains strings and recursively other arrays of strings and arrays of strings.
Instance Attribute Summary collapse
-
#tokens ⇒ Array<String,Array<String,...>]
Once a string is lexed, this contains the tokenized structure.
Instance Method Summary collapse
-
#initialize(string) ⇒ Lexer
constructor
A new instance of Lexer.
-
#lex ⇒ Array<String,Array<String,...>]
Tokenize the string that the lexer was initialized with and return the sequence of tokens that were lexed.
Constructor Details
#initialize(string) ⇒ Lexer
Returns a new instance of Lexer.
59 60 61 62 |
# File 'lib/accessibility/string.rb', line 59 def initialize string @chars = string.to_s @tokens = [] end |
Instance Attribute Details
Instance Method Details
#lex ⇒ Array<String,Array<String,...>]
Tokenize the string that the lexer was initialized with and return the sequence of tokens that were lexed.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/accessibility/string.rb', line 69 def lex length = @chars.length @index = 0 while @index < length @tokens << if custom? lex_custom else lex_char end @index += 1 end @tokens end |