Class: Janeway::AST::CurrentNode

Inherits:
Expression show all
Defined in:
lib/janeway/ast/current_node.rb

Overview

CurrentNode addresses the current node of the filter-selector that is directly enclosing the identifier.

Note: Within nested filter-selectors, there is no syntax to address the current node of any other than the directly enclosing filter-selector (i.e., of filter-selectors enclosing the filter-selector that is directly enclosing the identifier).

It may be followed by another selector which is applied to it. Within the IETF examples, I see @ followed by these selectors:

* name selector (dot notation)
* filter selector (bracketed)
* wildcard selector

Probably best to assume that any selector type could appear here.

It may also not be followed by any selector, and be used directly with a comparison operator.

Construct accepts an optional Selector which will be applied to the “current” node

Examples:

$.a[[email protected] == 'kilo']
$.a[[email protected]]
$[?@.*]
$[?@[[email protected]]]
$.a[?@<2 || @.b == "k"]
$.o[?@>1 && @<4]
$.a[?@ == @]

Instance Attribute Summary collapse

Attributes inherited from Expression

#value

Instance Method Summary collapse

Methods inherited from Expression

#indented, #initialize, #literal?, #type

Constructor Details

This class inherits a constructor from Janeway::AST::Expression

Instance Attribute Details

#nextObject

Subsequent expression that modifies the output of this expression



33
34
35
# File 'lib/janeway/ast/current_node.rb', line 33

def next
  @next
end

Instance Method Details

#empty?Boolean

True if this is a bare current node operator, without a following expression

Returns:



59
60
61
# File 'lib/janeway/ast/current_node.rb', line 59

def empty?
  @next.nil?
end

#singular_query?Boolean

True if this is the root of a singular-query.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/janeway/ast/current_node.rb', line 43

def singular_query?
  return true unless @next # there are no following selectors

  selector_types = []
  selector = @next
  loop do
    selector_types << selector.class
    selector = selector.next
    break unless selector
  end
  allowed = [AST::IndexSelector, AST::NameSelector]
  selector_types.uniq.all? { allowed.include?(_1) }
end

#to_sObject



35
36
37
# File 'lib/janeway/ast/current_node.rb', line 35

def to_s
  "@#{@next}"
end

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


65
66
67
# File 'lib/janeway/ast/current_node.rb', line 65

def tree(level)
  [indented(level, '@'), @next.tree(indent + 1)]
end