Sha256: 8eb8cc8de2064a807ff1b2e81eade2fd715d498f5e2d6aa6c2fef7bb5644ecb9

Contents?: true

Size: 763 Bytes

Versions: 1

Compression:

Stored size: 763 Bytes

Contents

module Treetop
  class RepeatingParsingExpression < Sequence
    attr_reader :repeated_expression
    
    def initialize(repeated_expression)
      super
      @repeated_expression = repeated_expression
    end

    def parse_at(input, start_index, parser)
      results = []
      next_index = start_index
      
      while true
        result = repeated_expression.parse_at(input, next_index, parser)
        break if result.failure?
        results << result
        next_index = result.interval.end
      end
            
      if enough? results
        interval = start_index...next_index
        return success(input, interval, results, results + [result])
      else
        return failure_at(start_index, results + [result])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
treetop-0.1.0 lib/treetop/grammar/parsing_expressions/repeating_parsing_expression.rb