Class: TheFox::Range::Lexer::Scope
- Inherits:
-
Base
- Object
- Base
- TheFox::Range::Lexer::Scope
show all
- Defined in:
- lib/thefox-ext/range/lexer/scope.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_child, #chain, #children, #dup, generate_nonce, #has_children, #has_parent_item, #instance_id, #instance_id=, #next_item, #next_item=, #nonce, #nonce=, #org_prev_item, #org_prev_item=, #parent_item, #parent_item=, #prev_item, #prev_item=, #symbole
Constructor Details
#initialize(items = nil, parent_scope = nil, level = 0) ⇒ Scope
Returns a new instance of Scope.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 6
def initialize(items = nil, parent_scope = nil, level = 0)
super()
@item_collection = Collection.new(items)
@parent_scope = parent_scope
@level = level
@ref_item = nil
end
|
Class Method Details
.keep_instance_id_on_dup ⇒ Object
259
260
261
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 259
def keep_instance_id_on_dup()
true
end
|
.keep_nonce_on_dup ⇒ Object
256
257
258
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 256
def keep_nonce_on_dup()
true
end
|
Instance Method Details
#curr ⇒ Object
40
41
42
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 40
def curr()
@item_collection.curr
end
|
#inspect ⇒ Object
21
22
23
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 21
def inspect()
'Scope(#%s len=%d)' % [@instance_id, @item_collection.length]
end
|
#items ⇒ Object
36
37
38
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 36
def items()
@item_collection.items
end
|
#name ⇒ Object
18
19
20
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 18
def name()
'Scope(#%s)' % [@instance_id]
end
|
#parent_scope ⇒ Object
48
49
50
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 48
def parent_scope()
@parent_scope
end
|
#parent_scope=(parent_scope) ⇒ Object
51
52
53
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 51
def parent_scope=(parent_scope)
@parent_scope = parent_scope
end
|
#prev ⇒ Object
44
45
46
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 44
def prev()
@item_collection.prev
end
|
#push(item) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 26
def push(item)
@item_collection.push(item)
end
|
#ref_item ⇒ Object
55
56
57
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 55
def ref_item()
@ref_item
end
|
#ref_item=(ref_item) ⇒ Object
58
59
60
61
62
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 58
def ref_item=(ref_item)
ref_item.is_ref_item = true
@ref_item = ref_item
end
|
#resolve ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/thefox-ext/range/lexer/scope.rb', line 64
def resolve()
scopes = Collection.new([Scope.new(nil, self, @level + 1)])
block_stack = Collection.new()
parent_item = nil
@item_collection.items.each do |item|
push_to_scope = false
case item
when Separator
if block_stack.length == 0
scopes.push(Scope.new(nil, self, @level + 1))
else
push_to_scope = true
end
when BlockDown
if block_stack.length == 0
prev_item = scopes.curr.curr
scopes.push(Scope.new(nil, self, @level + 1))
scopes.curr.ref_item = prev_item
else
push_to_scope = true
end
block_stack.push(item)
when BlockUp
block_stack.pop
prev_ref_item = scopes.curr.ref_item
scopes.push(Scope.new(nil, self, @level + 1))
scopes.curr.ref_item = prev_ref_item
else
push_to_scope = true
end
if push_to_scope
scopes.curr.push(item)
scopes.curr.curr.parent_item = self
end
end
if scopes.length > 1
resolved = []
scopes.items.each do |scope|
resolved.push(scope.resolve)
end
resolved
else
item_collection1 = Collection.new
scopes.curr.items.each do |item|
case item
when Number
if item.next_item.is_a?(Range) || item.prev_item.is_a?(Range)
elsif item.prev_item.is_a?(Interval)
elsif item.next_item.is_a?(Operator)
elsif item.has_children
elsif item.is_ref_item
else
item_collection1.push(item)
end
when Range
if item.prev_item.is_a?(Number) && item.next_item.is_a?(Number)
item_collection1.push(item)
item_collection1.curr.left_item = item.prev_item
item_collection1.curr.right_item = item.next_item
interval_item = item.next_item.next_item
if interval_item.is_a?(Interval)
item_collection1.curr.interval = interval_item
item_collection1.curr.interval.number = item.next_item.next_item.next_item
item_collection1.curr.interval.number.parent_item = item_collection1.curr.interval
end
else
raise 'Invalid Range: %s %s' % [
item.prev_item.inspect,
item.next_item.inspect,
]
end
when Interval
when Operator
if item_collection1.curr.is_a?(Range)
if item_collection1.curr.right_item.is_a?(Number)
item_collection1.curr.right_item.inc
end
elsif item.prev_item.is_a?(Number)
item_collection1.push(Range.new(item.symbole))
item_collection1.curr.left_item = item.prev_item
item_collection1.curr.right_item = item.prev_item
item_collection1.curr.right_item.inc
elsif item.prev_item.is_a?(Operator)
if item_collection1.curr.is_a?(Range)
if item_collection1.curr.right_item.is_a?(Number)
item_collection1.curr.right_item.inc
end
end
end
else
item_collection1.push(item)
end end
items2 = []
item_collection1.items.each do |item|
items2.push(item.resolve)
end
items2
end
end
|