lib/dolos.rb in dolos-0.1.2 vs lib/dolos.rb in dolos-0.1.3

- old
+ new

@@ -20,11 +20,15 @@ def run(input) run_with_state(ParserState.new(input)) end def run_with_state(state) - parser_proc.call(state) + result = parser_proc.call(state) + if result.success? + state.last_success_position = state.input.offset + end + result end def capture! Parser.new do |state| result = run_with_state(state) @@ -110,10 +114,11 @@ def repeat(n_min:, n_max: Float::INFINITY) Parser.new do |state| values = [] captures = [] count = 0 + state.input.mark_offset while count < n_max result = run_with_state(state.dup) break if result.failure? @@ -123,10 +128,15 @@ state.input.advance(result.length) count += 1 end if count < n_min - Failure.new("Expected parser to match at least #{n_min} times but matched only #{count} times", false) + error_pos = state.input.offset + Failure.new( + "Expected parser to match at least #{n_min} times but matched only #{count} times", + error_pos, + state + ) else Success.new(values, 0, captures) end end end