Class: Fabulator::Grammar::Expr::CharClass

Inherits:
CharSet
  • Object
show all
Defined in:
lib/fabulator/grammar/expr/char_set.rb

Constant Summary collapse

@@charsets =
{
  'alnum' => [ 0x30 .. 0x39, 0x41 .. 0x5a, 0x61 .. 0x7a ],
  'alpha' => [ 0x41 .. 0x5a, 0x61 .. 0x7a ],
  'ascii' => [ 0x00 .. 0x7f ],
  'blank' => [ 0x0b, 0x20 ], # \t + space
  'cntrl' => [ 0x00 .. 0x1f, 0x7f ],
  'digit' => [ 0x30 .. 0x39 ],
  'graph' => [ 0x21 .. 0x7e ],
  'lower' => [ 0x61 .. 0x7a ],
  'print' => [ 0x20 .. 0x7e ],
  'space' => [ 0x0a, 0x0b, 0x0c, 0x0f, 0x20 ], # \t\r\n\v\f + space
  'upper' => [ 0x41 .. 0x5a ],
  'word'  => [ 0x30 .. 0x39, 0x41 .. 0x5a, 0x61 .. 0x7a, '_'[0] ],
  'xdigit'=> [ 0x30 .. 0x39, 0x41 .. 0x46, 0x61 .. 0x66 ],
  'nl'    => [ 0x0a, 0x0c ]
}

Instance Method Summary collapse

Methods inherited from CharSet

#but_not, #compute_regex, #or, #set, #to_regex, #universal

Constructor Details

#initialize(cs) ⇒ CharClass

Returns a new instance of CharClass.



98
99
100
101
# File 'lib/fabulator/grammar/expr/char_set.rb', line 98

def initialize(cs)
  @set = BitSet.new.on(@@charsets[cs.downcase] || [])
  self.compute_regex
end