Class: YTools::Path::Lexer
- Inherits:
-
Object
- Object
- YTools::Path::Lexer
- Defined in:
- lib/ytools/path/lexer.rb
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #has_next? ⇒ Boolean
-
#initialize(path) ⇒ Lexer
constructor
A new instance of Lexer.
- #next ⇒ Object
- #peek(count = nil) ⇒ Object
Constructor Details
#initialize(path) ⇒ Lexer
Returns a new instance of Lexer.
23 24 25 26 27 |
# File 'lib/ytools/path/lexer.rb', line 23 def initialize(path) @path = path @offset = 0 @buffer = [] end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
21 22 23 |
# File 'lib/ytools/path/lexer.rb', line 21 def offset @offset end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/ytools/path/lexer.rb', line 21 def path @path end |
Instance Method Details
#[](index) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ytools/path/lexer.rb', line 29 def [](index) if offset + index >= path.length nil else @path[offset + index] end end |
#has_next? ⇒ Boolean
57 58 59 |
# File 'lib/ytools/path/lexer.rb', line 57 def has_next? !peek.nil? end |
#next ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ytools/path/lexer.rb', line 37 def next if @buffer.length > 0 @buffer.pop else token end end |
#peek(count = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ytools/path/lexer.rb', line 45 def peek(count=nil) count ||= 0 if count >= @buffer.length (@buffer.length - count).downto(0) do @buffer.push(token) end end @buffer[count] end |