Class: Rjq::AST::Pipe

Inherits:
Node
  • Object
show all
Defined in:
lib/rjq/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#source_span

Instance Method Summary collapse

Methods inherited from Node

#assign_value, #invalid_path_message, #take, #with_source_span

Constructor Details

#initialize(left, right) ⇒ Pipe

Returns a new instance of Pipe.



303
304
305
306
# File 'lib/rjq/ast.rb', line 303

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



301
302
303
# File 'lib/rjq/ast.rb', line 301

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



301
302
303
# File 'lib/rjq/ast.rb', line 301

def right
  @right
end

Instance Method Details

#eval(input, context) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
# File 'lib/rjq/ast.rb', line 308

def eval(input, context)
  out = []
  @left.eval(input, context).each do |value|
    out.concat(@right.eval(value, context))
  rescue ErrorValue => e
    raise ErrorValue.new(e.value, outputs: out + (e.outputs || []))
  rescue BreakSignal => e
    raise BreakSignal.new(e.label, e.value, outputs: out + (e.outputs || []))
  end
  out
end

#paths(input, context) ⇒ Object



320
321
322
323
324
325
326
327
# File 'lib/rjq/ast.rb', line 320

def paths(input, context)
  @left.paths(input, context).flat_map do |path|
    value = Path.get(input, path)
    @right.paths(value, context).map { |suffix| path + suffix }
  end
rescue InvalidPathError => e
  raise InvalidPathError.new(@right.invalid_path_message(e.result, input, context), e.result)
end