Class: Chomsky::Parser::Regexp
- Inherits:
-
Chomsky::Parser
- Object
- Chomsky::Parser
- Chomsky::Parser::Regexp
- Defined in:
- lib/chomsky/parsers/regexp.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call(string) ⇒ Object
-
#initialize(pattern) ⇒ Regexp
constructor
A new instance of Regexp.
Methods inherited from Chomsky::Parser
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 |