Class: LLIP::Buffer
- Inherits:
-
Object
- Object
- LLIP::Buffer
- Defined in:
- lib/llip/buffer.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#scanner ⇒ Object
Returns the value of attribute scanner.
Instance Method Summary collapse
-
#initialize(scanner) ⇒ Buffer
constructor
A new instance of Buffer.
- #lookahead(n) ⇒ Object
- #next ⇒ Object
- #scan(text) ⇒ Object
Constructor Details
#initialize(scanner) ⇒ Buffer
Returns a new instance of Buffer.
8 9 10 11 12 |
# File 'lib/llip/buffer.rb', line 8 def initialize(scanner) @scanner = scanner @current = nil @buffer = nil end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
6 7 8 |
# File 'lib/llip/buffer.rb', line 6 def current @current end |
#scanner ⇒ Object
Returns the value of attribute scanner.
5 6 7 |
# File 'lib/llip/buffer.rb', line 5 def scanner @scanner end |
Instance Method Details
#lookahead(n) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/llip/buffer.rb', line 27 def lookahead(n) @buffer ||= [] while @buffer.size < n @buffer << @scanner.next end @buffer[n-1] end |
#next ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/llip/buffer.rb', line 19 def next return @current = @scanner.next unless @buffer @current = @buffer.shift @buffer = nil if @buffer.size == 0 @current end |
#scan(text) ⇒ Object
14 15 16 17 |
# File 'lib/llip/buffer.rb', line 14 def scan(text) @scanner.scan(text) self end |