Class: RBNF::RepN

Inherits:
Binary show all
Defined in:
lib/rbnf/nodes.rb

Overview

Repetition (n times) node

Constant Summary

Constants included from RBNF

DEFS, VERSION

Instance Attribute Summary

Attributes inherited from Binary

#a, #b

Instance Method Summary collapse

Methods inherited from Binary

#initialize

Methods included from RBNF

#=~, [], #alt, #cat, #comps, def, define, dememoize, #except, #group, method_missing, #opt, #rep, #rep_n

Constructor Details

This class inherits a constructor from RBNF::Binary

Instance Method Details

#match(s) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/rbnf/nodes.rb', line 101

def match(s)
  if b==0
    s.empty?
  elsif Integer===b and b>0
    (2..b).inject(a) {|r| r.cat a}=~s
  else
    raise ArgumentError, "can't repeat #{a} #{b} times"
  end
end

#to_sObject



98
99
100
# File 'lib/rbnf/nodes.rb', line 98

def to_s
  "#{b} * #{a}"
end