From 668892ebbcdcfa92a57a62e737f567a23d707aa0 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 19 Oct 2015 09:10:54 -0400 Subject: parsers: Fix variable shadowing issue. 'parse-either' and 'parse-both' shadowed the 'stream' variable, causing failure cases to sometimes return the wrong stream. That is, a stream that has consumed input characters, not the original stream. * syntax-highlight/parsers.scm (parse-either, parse-both): Use 'remainder' variable for leftover stream variables rather than shadowing 'stream'. --- syntax-highlight/parsers.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'syntax-highlight/parsers.scm') diff --git a/syntax-highlight/parsers.scm b/syntax-highlight/parsers.scm index 5d08e45..41975d6 100644 --- a/syntax-highlight/parsers.scm +++ b/syntax-highlight/parsers.scm @@ -89,20 +89,20 @@ PREDICATE is satisfied with the result." "Create a parser that tries to parse with FIRST or, if that fails, parses SECOND." (lambda (stream) - (let-values (((result stream) (first stream))) + (let-values (((result remaining) (first stream))) (if result - (values result stream) + (values result remaining) (second stream))))) (define (parse-both first second) "Create a parser that returns a pair of the results of the parsers FIRST and SECOND if both are successful." (lambda (stream) - (let-values (((result1 stream) (first stream))) + (let-values (((result1 remaining) (first stream))) (if result1 - (let-values (((result2 stream) (second stream))) + (let-values (((result2 remaining) (second remaining))) (if result2 - (values (cons result1 result2) stream) + (values (cons result1 result2) remaining) (parse-fail stream))) (parse-fail stream))))) -- cgit v1.2.3