Sha256: 1da22361f98b53131c912398709bf7e63e9a2e79c89f77094f204746ec0eddfd

Contents?: true

Size: 1.23 KB

Versions: 27

Compression:

Stored size: 1.23 KB

Contents

module JMESPath
  # @api private
  class TokenStream

    # @param [String<JMESPath>] expression
    # @param [Array<Token>] tokens
    def initialize(expression, tokens)
      @expression = expression
      @tokens = tokens
      @token = nil
      @position = -1
      self.next
    end

    # @return [String<JMESPath>]
    attr_reader :expression

    # @return [Token]
    attr_reader :token

    # @return [Integer]
    attr_reader :position

    # @option options [Array<Symbol>] :match Requires the next token to be
    #   one of the given symbols or an error is raised.
    def next(options = {})
      validate_match(_next, options[:match])
    end

    def lookahead(count)
      @tokens[@position + count] || Token::NULL_TOKEN
    end

    # @api private
    def inspect
      str = []
      @tokens.each do |token|
        str << "%3d  %-15s %s" %
         [token.position, token.type, token.value.inspect]
      end
      str.join("\n")
    end

    private

    def _next
      @position += 1
      @token = @tokens[@position] || Token::NULL_TOKEN
    end

    def validate_match(token, match)
      if match && !match.include?(token.type)
        raise Errors::SyntaxError, "type missmatch"
      else
        token
      end
    end

  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
jmespath-1.6.1 lib/jmespath/token_stream.rb
jmespath-1.6.0 lib/jmespath/token_stream.rb
jmespath-1.5.0 lib/jmespath/token_stream.rb
jmespath-1.4.0 lib/jmespath/token_stream.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/jmespath-1.3.1/lib/jmespath/token_stream.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/jmespath-1.3.1/lib/jmespath/token_stream.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/jmespath-1.3.1/lib/jmespath/token_stream.rb
jmespath-1.3.1 lib/jmespath/token_stream.rb
jmespath-1.3.0 lib/jmespath/token_stream.rb
jmespath-1.2.4 lib/jmespath/token_stream.rb
jmespath-1.2.3 lib/jmespath/token_stream.rb
jmespath-1.2.2 lib/jmespath/token_stream.rb
jmespath-1.2.1 lib/jmespath/token_stream.rb
jmespath-1.2 lib/jmespath/token_stream.rb
burtpath-1.1.2 lib/jmespath/token_stream.rb
burtpath-1.1.1 lib/jmespath/token_stream.rb
jmespath-1.1.3 lib/jmespath/token_stream.rb
jmespath-1.1.2 lib/jmespath/token_stream.rb
jmespath-1.1.1 lib/jmespath/token_stream.rb
jmespath-1.1.0 lib/jmespath/token_stream.rb