Class: RandallRegExp::CharClass

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Includes:
CharSets
Defined in:
lib/randall/charclass.rb

Direct Known Subclasses

PerlCharClass, PosixCharClass, SpanCharClass

Instance Method Summary collapse

Methods included from CharSets

#all_chars, #control, #decimal_number, #graph, #letter, #lower_letter, #punctuation, #space, #strseq, #upper_letter, #word, #xchar, #xdigit

Instance Method Details

#charsObject

‘[’ neg:‘^’? comp:(cc_comp / char_class)+ amps:(‘&&’ char_class)? ‘]’



83
84
85
86
87
88
89
90
91
92
# File 'lib/randall/charclass.rb', line 83

def chars
  return @chars if @chars

  # build charset
  @chars = comp.elements.map(&:chars).reduce([], :+).uniq
  @chars &= amps.elements[1].chars unless amps.empty?
  @chars = self.all_chars - @chars unless neg.empty?

  @chars
end

#randObject



94
95
96
97
# File 'lib/randall/charclass.rb', line 94

def rand
  self.chars
	@chars.empty? ? '' : @chars[Kernel.rand(@chars.size)]
end