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.
Constant Summary
Instance Attribute Summary (collapse)
-
- (Array<String,Array<String,...>]) tokens
Once a string is lexed, this contains the tokenized structure.
Instance Method Summary (collapse)
-
- (Lexer) initialize(string)
constructor
A new instance of Lexer.
-
- (Array<String,Array<String,...>]) lex
Tokenize the string that the lexer was initialized with and return the sequence of tokens that were lexed.
Constructor Details
- (Lexer) initialize(string)
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
- (Array<String,Array<String,...>]) lex
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 |