Class: Farseer::Regexp

Inherits:
Object
  • Object
show all
Includes:
MapFactory
Defined in:
lib/farseer/regexp.rb

Constant Summary collapse

WS_REGEXP =
/^(?'token'\s*)(?'rest'.*)$/
RegexpError =
Class.new(ArgumentError)
WS =
new(WS_REGEXP)

Instance Method Summary collapse

Methods included from MapFactory

#map

Constructor Details

#initialize(regexp) ⇒ Regexp

Returns a new instance of Regexp.

Raises:



10
11
12
13
14
15
# File 'lib/farseer/regexp.rb', line 10

def initialize(regexp)
  raise RegexpError unless regexp.names == ['token', 'rest']

  @regexp = regexp
  freeze
end

Instance Method Details

#parse(input) ⇒ Object



19
20
21
22
23
# File 'lib/farseer/regexp.rb', line 19

def parse(input)
  match = input.match(@regexp)

  Maybe.return(Result.new(match[:token], match[:rest]))
end