mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-05 12:16:37 +02:00
Adding rx and regexp->sre.
This commit is contained in:
parent
e1e7508d8d
commit
05dcd92d72
2 changed files with 12 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue