Class: Janeway::Interpreters::Base
- Inherits:
-
Object
- Object
- Janeway::Interpreters::Base
- Defined in:
- lib/janeway/interpreters/base.rb
Overview
Base class for interpreters.
Direct Known Subclasses
ArraySliceSelectorInterpreter, BinaryOperatorInterpreter, ChildSegmentInterpreter, CurrentNodeInterpreter, DescendantSegmentInterpreter, FilterSelectorInterpreter, FunctionInterpreter, IndexSelectorInterpreter, NameSelectorInterpreter, RootNodeInterpreter, UnaryOperatorInterpreter, WildcardSelectorInterpreter
Constant Summary collapse
- NOTHING =
The special result NOTHING represents the absence of a JSON value and is distinct from any JSON value, including null. It represents:
* object keys referred to by name that do not exist in the input * array values referred to by index that are out of range * return value of function calls with an invalid input data type :nothing
Instance Attribute Summary collapse
-
#next ⇒ Interpreters::Base?
Subsequent expression interpreter that filters the output of this one.
- #node ⇒ AST::Expression readonly
Instance Method Summary collapse
-
#as_json ⇒ Hash
Return hash representation of this selector interpreter.
-
#initialize(node) ⇒ Base
constructor
A new instance of Base.
-
#interpret(_input, _root) ⇒ Object
Interpret the input, return result or forward to next node.
-
#selector ⇒ AST::Selector
AST node containing this interpreter’s data.
- #to_s ⇒ String
- #type ⇒ Object
Constructor Details
#initialize(node) ⇒ Base
Returns a new instance of Base.
26 27 28 29 30 31 32 |
# File 'lib/janeway/interpreters/base.rb', line 26 def initialize(node) @node = node return unless node.next @next = TreeConstructor.ast_node_to_interpreter(node.next) end |
Instance Attribute Details
#next ⇒ Interpreters::Base?
Subsequent expression interpreter that filters the output of this one
21 22 23 |
# File 'lib/janeway/interpreters/base.rb', line 21 def next @next end |
#node ⇒ AST::Expression (readonly)
24 25 26 |
# File 'lib/janeway/interpreters/base.rb', line 24 def node @node end |
Instance Method Details
#as_json ⇒ Hash
Return hash representation of this selector interpreter
49 50 51 52 53 54 55 |
# File 'lib/janeway/interpreters/base.rb', line 49 def as_json if node { type: type, value: node&.value, next: @next&.as_json }.compact else { type: type, next: @next&.as_json }.compact end end |
#interpret(_input, _root) ⇒ Object
Interpret the input, return result or forward to next node.
38 39 40 |
# File 'lib/janeway/interpreters/base.rb', line 38 def interpret(_input, _root) raise NotImplementedError, 'subclass must implement #interpret' end |
#selector ⇒ AST::Selector
Returns AST node containing this interpreter’s data.
58 59 60 |
# File 'lib/janeway/interpreters/base.rb', line 58 def selector nil # subclass should implement end |
#to_s ⇒ String
43 44 45 |
# File 'lib/janeway/interpreters/base.rb', line 43 def to_s @node.to_s end |
#type ⇒ Object
62 63 64 |
# File 'lib/janeway/interpreters/base.rb', line 62 def type self.class.to_s.split('::').last # eg. Janeway::AST::FunctionCall => "FunctionCall" end |