From 73698a36131dd58d11becd89a71443100923d717 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 18 Oct 2015 20:53:39 -0400 Subject: parsers: Add parse-regexp. * syntax-highlight/parsers.scm (parse-regexp): New procedure. --- syntax-highlight/parsers.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/syntax-highlight/parsers.scm b/syntax-highlight/parsers.scm index bb967db..712f8d5 100644 --- a/syntax-highlight/parsers.scm +++ b/syntax-highlight/parsers.scm @@ -23,6 +23,7 @@ (define-module (syntax-highlight parsers) #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) @@ -43,6 +44,7 @@ parse-char-set parse-whitespace parse-delimited + parse-regexp tagged-parser)) ;;; @@ -203,6 +205,14 @@ Within the sequence, ESCAPE is recognized as the escape character." (loop (stream-cdr stream) (cons (stream-car stream) result))))) (parse-fail stream)))))) +(define (parse-regexp regexp parser) + "Create a parser that succeeds if the result of PARSER is a string +that matches the string REGEXP." + (let ((rx (make-regexp regexp))) + (parse-filter (lambda (result) + (regexp-match? (regexp-exec rx result))) + parser))) + (define (tagged-parser tag parser) "Create a parser that wraps the result of PARSER in a two element list whose first element is TAG." -- cgit v1.2.3