class JMESPath::TokenStream

@api private

Attributes

expression[R]

@return [String<JMESPath>]

position[R]

@return [Integer]

token[R]

@return [Token]

Public Class Methods

new(expression, tokens) click to toggle source

@param [String<JMESPath>] expression @param [Array<Token>] tokens

# File lib/jmespath/token_stream.rb, line 7
def initialize(expression, tokens)
  @expression = expression
  @tokens = tokens
  @token = nil
  @position = -1
  self.next
end

Public Instance Methods

inspect() click to toggle source

@api private

# File lib/jmespath/token_stream.rb, line 35
def inspect
  str = []
  @tokens.each do |token|
    str << "%3d  %-15s %s" %
     [token.position, token.type, token.value.inspect]
  end
  str.join("\n")
end
lookahead(count) click to toggle source
# File lib/jmespath/token_stream.rb, line 30
def lookahead(count)
  @tokens[@position + count] || Token::NULL_TOKEN
end
next(options = {}) click to toggle source

@option options [Array<Symbol>] :match Requires the next token to be

one of the given symbols or an error is raised.
# File lib/jmespath/token_stream.rb, line 26
def next(options = {})
  validate_match(_next, options[:match])
end

Private Instance Methods

_next() click to toggle source
# File lib/jmespath/token_stream.rb, line 46
def _next
  @position += 1
  @token = @tokens[@position] || Token::NULL_TOKEN
end
validate_match(token, match) click to toggle source
# File lib/jmespath/token_stream.rb, line 51
def validate_match(token, match)
  if match && !match.include?(token.type)
    raise Errors::SyntaxError, "type missmatch"
  else
    token
  end
end