Class: JMESPath::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/jmespath/parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

AFTER_DOT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Set.new([
    :identifier,        # foo.bar
    :quoted_identifier, # foo."bar"
    :star,              # foo.*
    :lbrace,            # foo[1]
    :lbracket,          # foo{a: 0}
    :function,          # foo.*.to_string(@)
    :filter,            # foo.[?bar==10]
])
CURRENT_NODE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Nodes::Current.new

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):



21
22
23
# File 'lib/jmespath/parser.rb', line 21

def initialize(options = {})
  @lexer = options[:lexer] || Lexer.new()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
# File 'lib/jmespath/parser.rb', line 37

def method_missing(method_name, *args)
  if matches = method_name.match(/^(nud_|led_)(.*)/)
    raise Errors::SyntaxError, "unexpected token #{matches[2]}"
  else
    super
  end
end

Instance Method Details

#parse(expression) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



26
27
28
29
30
31
32
33
34
# File 'lib/jmespath/parser.rb', line 26

def parse(expression)
  stream = TokenStream.new(expression, @lexer.tokenize(expression))
  result = expr(stream)
  if stream.token.type != :eof
    raise Errors::SyntaxError, "expected :eof got #{stream.token.type}"
  else
    result
  end
end