Class: JSONP3::Stream
- Inherits:
-
Object
- Object
- JSONP3::Stream
- Defined in:
- lib/json_p3/parser.rb
Overview
Step through tokens
Instance Method Summary collapse
- #expect(token_type) ⇒ Object
- #expect_not(token_type, message) ⇒ Object
-
#initialize(tokens) ⇒ Stream
constructor
A new instance of Stream.
- #next ⇒ Object
- #peek ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Stream
Returns a new instance of Stream.
17 18 19 20 21 |
# File 'lib/json_p3/parser.rb', line 17 def initialize(tokens) @tokens = tokens @index = 0 @eoi = tokens.last end |
Instance Method Details
#expect(token_type) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/json_p3/parser.rb', line 37 def expect(token_type) return if peek.type == token_type token = self.next raise JSONPathSyntaxError.new("expected #{token_type}, found #{token.type}", token) end |
#expect_not(token_type, message) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/json_p3/parser.rb', line 44 def expect_not(token_type, ) return unless peek.type == token_type token = self.next raise JSONPathSyntaxError.new(, token) end |
#next ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/json_p3/parser.rb', line 23 def next token = @tokens.fetch(@index) @index += 1 token rescue IndexError @eor end |
#peek ⇒ Object
31 32 33 34 35 |
# File 'lib/json_p3/parser.rb', line 31 def peek @tokens.fetch(@index) rescue IndexError @eor end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/json_p3/parser.rb', line 51 def to_s "JSONP3::stream(head=#{peek.inspect})" end |