summaryrefslogtreecommitdiff
path: root/syntax-highlight
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-10-19 09:10:54 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-10-19 09:10:54 -0400
commit668892ebbcdcfa92a57a62e737f567a23d707aa0 (patch)
treee6fd6dc046ec69988385b98cd6f8328b0a14ccfe /syntax-highlight
parentf9dae95bd0f1434aa56fd8de259325b9742e28e2 (diff)
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'.
Diffstat (limited to 'syntax-highlight')
-rw-r--r--syntax-highlight/parsers.scm10
1 files changed, 5 insertions, 5 deletions
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)))))