diff options
Diffstat (limited to 'syntax-highlight')
-rw-r--r-- | syntax-highlight/parsers.scm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/syntax-highlight/parsers.scm b/syntax-highlight/parsers.scm index 5349296..bb967db 100644 --- a/syntax-highlight/parsers.scm +++ b/syntax-highlight/parsers.scm @@ -33,6 +33,7 @@ parse-lift parse-never parse-map + parse-filter parse-either parse-both parse-any @@ -77,6 +78,15 @@ "Return a new parser that applies PROC to result of PARSER." (parse-bind (parse-lift proc) parser)) +(define (parse-filter predicate parser) + "Create a new parser that succeeds when PARSER is successful and +PREDICATE is satisfied with the result." + (lambda (stream) + (let-values (((result remaining) (parser stream))) + (if (and result (predicate result)) + (values result remaining) + (parse-fail stream))))) + (define (parse-either first second) "Create a parser that tries to parse with FIRST or, if that fails, parses SECOND." |