Class: Rjq::AST::Comma

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, #with_source_span

Constructor Details

#initialize(left, right) ⇒ Comma

Returns a new instance of Comma.



333
334
335
336
# File 'lib/rjq/ast.rb', line 333

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

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



331
332
333
# File 'lib/rjq/ast.rb', line 331

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



331
332
333
# File 'lib/rjq/ast.rb', line 331

def right
  @right
end

Instance Method Details

#eval(input, context) ⇒ Object



338
339
340
341
342
343
344
345
# File 'lib/rjq/ast.rb', line 338

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

#paths(input, context) ⇒ Object



354
355
356
# File 'lib/rjq/ast.rb', line 354

def paths(input, context)
  @left.paths(input, context) + @right.paths(input, context)
end

#take(input, context, count) ⇒ Object



347
348
349
350
351
352
# File 'lib/rjq/ast.rb', line 347

def take(input, context, count)
  left_values = @left.take(input, context, count)
  return left_values if left_values.length >= count

  left_values + @right.take(input, context, count - left_values.length)
end