Class: Chomsky::ParserGenerator::Some

Inherits:
Chomsky::ParserGenerator show all
Defined in:
lib/chomsky/parser_generators/some.rb

Instance Method Summary collapse

Methods inherited from Chomsky::ParserGenerator

call, #initialize, #to_pg

Methods included from Combinators

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

Constructor Details

This class inherits a constructor from Chomsky::ParserGenerator

Instance Method Details

#call(string) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/chomsky/parser_generators/some.rb', line 6

def call string
  head, rest = @parser.(string)
  if head
    more = ""
    until more.nil?
      more, rest = @parser.(rest)
      head += more if more
    end
    [head, rest]
  else
    [nil, string]
  end
end