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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/odin/transform/verb_context.rb', line 29

def initialize
  @source = Types::DynValue.of_null
  @current_item = nil
  @loop_index = 0
  @loop_length = 0
  @loop_vars = {}
  @aliases = {}
  @accumulators = {}
  @tables = {}
  @constants = {}
  @global_output = {}
  @sequences = {}
  @loop_depth = 0
  @field_modifiers = {}
  @errors = []
  @warnings = []
  @source_format = ""
  @on_validation = nil
  @on_missing = nil
  @on_error = nil
  @strict_types = false
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

#aliasesObject

DynValue — current source root



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

def aliases
  @aliases
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

#on_errorObject

DynValue — current source root



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

def on_error
  @on_error
end

#on_missingObject

DynValue — current source root



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

def on_missing
  @on_missing
end

#on_validationObject

DynValue — current source root



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

def on_validation
  @on_validation
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

#strict_typesObject

DynValue — current source root



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

def strict_types
  @strict_types
end

#tablesObject

DynValue — current source root



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

def tables
  @tables
end

#warningsObject

DynValue — current source root



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

def warnings
  @warnings
end

Instance Method Details

#dup_for_loopObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/odin/transform/verb_context.rb', line 83

def dup_for_loop
  ctx = VerbContext.new
  ctx.source = @source
  ctx.loop_vars = @loop_vars.dup
  ctx.aliases = @aliases.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.warnings = @warnings # shared reference
  ctx.source_format = @source_format
  ctx.on_validation = @on_validation
  ctx.on_missing = @on_missing
  ctx.on_error = @on_error
  ctx
end

#get_accumulator(name) ⇒ Object



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

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

#get_constant(name) ⇒ Object



71
72
73
# File 'lib/odin/transform/verb_context.rb', line 71

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

#get_table(name) ⇒ Object



75
76
77
# File 'lib/odin/transform/verb_context.rb', line 75

def get_table(name)
  @tables[name]
end

#in_loop?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/odin/transform/verb_context.rb', line 79

def in_loop?
  !@current_item.nil?
end

#next_sequence(name) ⇒ Object



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

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

#reset_sequence(name) ⇒ Object



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

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

#set_accumulator(name, value) ⇒ Object



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

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