Class: RLSM::RegExp::Union

Inherits:
Object show all
Defined in:
lib/rlsm_regexp.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, str) ⇒ Union

Returns a new instance of Union.



320
321
322
323
324
325
# File 'lib/rlsm_regexp.rb', line 320

def initialize(parent, str)
  @parent = parent
  @childs = _split(str).map do |substr|
    NodeFactory.new_node(self, substr)
  end
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


376
377
378
# File 'lib/rlsm_regexp.rb', line 376

def empty?
  false
end

#firstObject



331
332
333
334
335
336
337
338
339
340
# File 'lib/rlsm_regexp.rb', line 331

def first
  res = []
  @childs.each do |child|
    child.first.each do |f|
      res << f
    end
  end

  res
end

#followObject



353
354
355
356
357
358
359
360
361
362
# File 'lib/rlsm_regexp.rb', line 353

def follow
  res = []
  @childs.each do |child|
    child.follow.each do |f|
      res << f
    end
  end

  res
end

#lambda?Boolean

Returns:

  • (Boolean)


372
373
374
# File 'lib/rlsm_regexp.rb', line 372

def lambda?
  false
end

#lastObject



342
343
344
345
346
347
348
349
350
351
# File 'lib/rlsm_regexp.rb', line 342

def last
  res = []
  @childs.each do |child|
    child.last.each do |l|
      res << l
    end
  end

  res
end

#null?Boolean

Returns:

  • (Boolean)


327
328
329
# File 'lib/rlsm_regexp.rb', line 327

def null?
  @childs.any? { |child| child.null? }
end

#to_sObject



364
365
366
367
368
369
370
# File 'lib/rlsm_regexp.rb', line 364

def to_s
  if @parent.nil? or @parent.class == Union or @paarent.class == Star
    return @childs.map { |child| child.to_s }.join('|')
  else
    return '(' + @childs.map { |child| child.to_s }.join('|') + ')'
  end
end