From 05dcd92d72ef1798e7f2789aa4e629064c3a32ab Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Fri, 29 Nov 2013 23:42:36 +0900 Subject: [PATCH] Adding rx and regexp->sre. --- lib/chibi/regexp.scm | 13 ++++++++++--- lib/chibi/regexp.sld | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/chibi/regexp.scm b/lib/chibi/regexp.scm index 1c3092c1..0a8e1867 100644 --- a/lib/chibi/regexp.scm +++ b/lib/chibi/regexp.scm @@ -5,13 +5,20 @@ ;;; An rx represents a start state and meta-info such as the number ;;; and names of submatches. (define-record-type Rx - (make-rx start-state num-matches num-save-indexes match-rules match-names) + (make-rx start-state num-matches num-save-indexes match-rules match-names sre) regexp? (start-state rx-start-state rx-start-state-set!) (num-matches rx-num-matches rx-num-matches-set!) (num-save-indexes rx-num-save-indexes rx-num-save-indexes-set!) (match-rules rx-rules rx-rules-set!) - (match-names rx-names rx-names-set!)) + (match-names rx-names rx-names-set!) + (sre regexp->sre)) + +;; Syntactic sugar. +(define-syntax rx + (syntax-rules () + ((rx sre ...) + (regexp `(: sre ...))))) ;;; A state is a single nfa state with transition rules. (define-record-type State @@ -819,7 +826,7 @@ sre (let ((start (make-submatch-state sre flags (make-accept-state) 0))) (make-rx start current-match current-index - (list->vector (reverse match-rules)) match-names))))) + (list->vector (reverse match-rules)) match-names sre))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Utilities diff --git a/lib/chibi/regexp.sld b/lib/chibi/regexp.sld index ed1cb7ad..d4838655 100644 --- a/lib/chibi/regexp.sld +++ b/lib/chibi/regexp.sld @@ -1,6 +1,7 @@ (define-library (chibi regexp) - (export regexp regexp? regexp-matches regexp-matches? regexp-search + (export regexp regexp? rx regexp->sre + regexp-matches regexp-matches? regexp-search regexp-replace regexp-replace-all regexp-fold regexp-extract regexp-split regexp-match? regexp-match-num-matches