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([
  Lexer::T_IDENTIFIER,        # foo.bar
  Lexer::T_QUOTED_IDENTIFIER, # foo."bar"
  Lexer::T_STAR,              # foo.*
  Lexer::T_LBRACE,            # foo{a: 0}
  Lexer::T_LBRACKET,          # foo[1]
  Lexer::T_FILTER,            # foo.[?bar==10]
])
NUM_COLON_RBRACKET =

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([
  Lexer::T_NUMBER,
  Lexer::T_COLON,
  Lexer::T_RBRACKET,
])
COLON_RBRACKET =

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([
  Lexer::T_COLON,
  Lexer::T_RBRACKET,
])
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):



30
31
32
33
# File 'lib/jmespath/parser.rb', line 30

def initialize(options = {})
  @lexer = options[:lexer] || Lexer.new
  @disable_visit_errors = options[:disable_visit_errors]
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.



48
49
50
51
52
53
54
# File 'lib/jmespath/parser.rb', line 48

def method_missing(method_name, *args)
  if matches = method_name.to_s.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:



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

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