Class: Chomsky::Parser::Regexp

Inherits:
Chomsky::Parser show all
Defined in:
lib/chomsky/parsers/regexp.rb

Direct Known Subclasses

Blank

Instance Method Summary collapse

Methods inherited from Chomsky::Parser

call, #to_pg

Methods included from Chomsky::ParserGenerator::Combinators

#!, #%, #&, #*, #+, #-, #<, #>, #>=, #>>, #[], #_?, #capture, #reference, #|

Constructor Details

#initialize(pattern) ⇒ Regexp

Returns a new instance of Regexp.



6
7
8
# File 'lib/chomsky/parsers/regexp.rb', line 6

def initialize pattern
  @pattern = ::Regexp.new("\\A" + pattern.source)
end

Instance Method Details

#call(string) ⇒ Object



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

def call string
  if mdata = @pattern.match(string)
    [mdata.to_s, string[mdata.to_s.length..-1]]
  else
    [nil, string]
  end
end