Class: Odin::Transform::VerbContext

Inherits:
Object
  • Object
show all
Defined in:
lib/odin/transform/verb_context.rb

Constant Summary collapse

MAX_LOOP_DEPTH =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVerbContext

Returns a new instance of VerbContext.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/odin/transform/verb_context.rb', line 23

def initialize
  @source = Types::DynValue.of_null
  @current_item = nil
  @loop_index = 0
  @loop_length = 0
  @loop_vars = {}
  @accumulators = {}
  @tables = {}
  @constants = {}
  @global_output = {}
  @sequences = {}
  @loop_depth = 0
  @field_modifiers = {}
  @errors = []
  @source_format = ""
end

Instance Attribute Details

#accumulatorsObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def accumulators
  @accumulators
end

#constantsObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def constants
  @constants
end

#current_itemObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def current_item
  @current_item
end

#errorsObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def errors
  @errors
end

#field_modifiersObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def field_modifiers
  @field_modifiers
end

#global_outputObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def global_output
  @global_output
end

#loop_depthObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def loop_depth
  @loop_depth
end

#loop_indexObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def loop_index
  @loop_index
end

#loop_lengthObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def loop_length
  @loop_length
end

#loop_varsObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def loop_vars
  @loop_vars
end

#sequencesObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def sequences
  @sequences
end

#sourceObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def source
  @source
end

#source_formatObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def source_format
  @source_format
end

#tablesObject

DynValue — current source root



6
7
8
# File 'lib/odin/transform/verb_context.rb', line 6

def tables
  @tables
end

Instance Method Details

#dup_for_loopObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/odin/transform/verb_context.rb', line 71

def dup_for_loop
  ctx = VerbContext.new
  ctx.source = @source
  ctx.loop_vars = @loop_vars.dup
  ctx.accumulators = @accumulators # shared reference
  ctx.tables = @tables
  ctx.constants = @constants
  ctx.global_output = @global_output # shared reference
  ctx.sequences = @sequences # shared reference
  ctx.loop_depth = @loop_depth + 1
  ctx.field_modifiers = @field_modifiers # shared reference
  ctx.errors = @errors # shared reference
  ctx
end

#get_accumulator(name) ⇒ Object



51
52
53
# File 'lib/odin/transform/verb_context.rb', line 51

def get_accumulator(name)
  @accumulators[name] || Types::DynValue.of_null
end

#get_constant(name) ⇒ Object



59
60
61
# File 'lib/odin/transform/verb_context.rb', line 59

def get_constant(name)
  @constants[name] || Types::DynValue.of_null
end

#get_table(name) ⇒ Object



63
64
65
# File 'lib/odin/transform/verb_context.rb', line 63

def get_table(name)
  @tables[name]
end

#in_loop?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/odin/transform/verb_context.rb', line 67

def in_loop?
  !@current_item.nil?
end

#next_sequence(name) ⇒ Object



40
41
42
43
44
45
# File 'lib/odin/transform/verb_context.rb', line 40

def next_sequence(name)
  @sequences[name] ||= 0
  val = @sequences[name]
  @sequences[name] += 1
  val
end

#reset_sequence(name) ⇒ Object



47
48
49
# File 'lib/odin/transform/verb_context.rb', line 47

def reset_sequence(name)
  @sequences[name] = 0
end

#set_accumulator(name, value) ⇒ Object



55
56
57
# File 'lib/odin/transform/verb_context.rb', line 55

def set_accumulator(name, value)
  @accumulators[name] = value
end