Class: TRuby::ParserCombinator::Many
- Defined in:
- lib/t_ruby/parser_combinator.rb
Overview
Many: zero or more
Instance Method Summary collapse
-
#initialize(parser) ⇒ Many
constructor
A new instance of Many.
- #parse(input, position = 0) ⇒ Object
Methods inherited from Parser
#<<, #>>, #between, #flat_map, #label, #lookahead, #many, #many1, #map, #not_followed_by, #optional, #sep_by, #sep_by1, #|
Constructor Details
#initialize(parser) ⇒ Many
292 293 294 |
# File 'lib/t_ruby/parser_combinator.rb', line 292 def initialize(parser) @parser = parser end |
Instance Method Details
#parse(input, position = 0) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/t_ruby/parser_combinator.rb', line 296 def parse(input, position = 0) results = [] current_pos = position loop do result = @parser.parse(input, current_pos) break if result.failure? results << result.value break if result.position == current_pos # Prevent infinite loop current_pos = result.position end ParseResult.success(results, input, current_pos) end |