Class: Antlr4::Runtime::SemanticContext::OR
Constant Summary
NONE
Instance Attribute Summary collapse
Instance Method Summary
collapse
and, filter_precedence_predicates, or
Constructor Details
#initialize(a, b) ⇒ OR
Returns a new instance of OR.
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 192
def initialize(a, b)
operands = Set.new
if a.is_a? OR
operands.add_all(a.opnds)
else
operands.add(a)
end
if b.is_a? OR
operands.add_all(b.opnds)
else
operands.add(b)
end
precedence_predicates = filter_precedence_predicates(operands)
unless precedence_predicates.empty?
reduced = precedence_predicates.max
operands.add(reduced)
end
@opnds = operands.to_s
end
|
Instance Attribute Details
#opnds ⇒ Object
Returns the value of attribute opnds.
190
191
192
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 190
def opnds
@opnds
end
|
Instance Method Details
#eql?(other) ⇒ Boolean
215
216
217
218
219
220
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 215
def eql?(other)
return true if self == other
return false unless other.is_a? OR
@opnds.eql?(other.opnds)
end
|
#eval(parser, parser_call_stack) ⇒ Object
234
235
236
237
238
239
240
241
242
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 234
def eval(parser, parser_call_stack)
i = 0
while i < @opnds.length
opnd = @opnds[i]
return true if opnd.eval(parser, parser_call_stack)
i += 1
end
false
end
|
#eval_precedence(parser, parser_call_stack) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 244
def eval_precedence(parser, parser_call_stack)
differs = false
operands = []
i = 0
while i < @opnds.length
context = @opnds[i]
evaluated = context.eval_precedence(parser, parser_call_stack)
differs |= (evaluated != context)
if evaluated == NONE
return NONE
elsif evaluated != null
operands.add(evaluated)
end
i += 1
end
return self unless differs
if operands.empty?
return nil
end
result = operands[0]
i = 1
while i < operands.size
result = SemanticContext.or(result, operands.get(i))
i += 1
end
result
end
|
#hash ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 222
def hash
hash_code = MurmurHash.calculate(@opnds, OR.hash)
unless @_hash3.nil?
if hash_code == @_hash3
puts 'Same hash_code for SemanticContext_2'
else
puts 'Different hash_code for SemanticContext_2'
end
end
@_hash3 = hash_code
end
|
#to_s ⇒ Object
278
279
280
|
# File 'lib/antlr4/runtime/semantic_context.rb', line 278
def to_s
@opnds.join('||')
end
|