diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-10-18 20:53:39 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-10-18 20:53:39 -0400 |
commit | 73698a36131dd58d11becd89a71443100923d717 (patch) | |
tree | a4280ebf883ab6af9a9213cde529b49b7fae6302 /syntax-highlight/parsers.scm | |
parent | 9c9d2802fd191ce4d6684e4b1242b6f5b3f511c2 (diff) |
parsers: Add parse-regexp.
* syntax-highlight/parsers.scm (parse-regexp): New procedure.
Diffstat (limited to 'syntax-highlight/parsers.scm')
-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 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." |