Skip to content

Commit

Permalink
added stubs for patsubst
Browse files Browse the repository at this point in the history
  • Loading branch information
outergod committed Dec 12, 2010
1 parent 4e4c971 commit f82accc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/m4-builtin.lisp
Expand Up @@ -358,3 +358,5 @@
(progn
(m4-warn "too few arguments to builtin `translit'")
(macro-return string))))

; (defm4macro "patsubst" (string &optional regexp replacement) (:minimum-arguments 1)) ; TODO
16 changes: 16 additions & 0 deletions src/m4-util.lisp
Expand Up @@ -204,3 +204,19 @@ searched additionally passing ARGS."
*m4-quote-start*
(funcall (macro-token-m4macro token) nil :expansion)
*m4-quote-end*))

;; (defmacro with-regex-search-handler (regexp string startpos registers &body body)
;; `(if regexp
;; (handler-case
;; (multiple-value-bind (startpos registers)
;; (regex-search regexp string)
;; ,@body
;; (regex-compilation-failure (condition)
;; (m4-warn (format nil "bad regular expression: `~a': ~a"
;; regexp condition))
;; "0")
;; (regex-internal-error ()
;; (m4-warn (format nil "error matching regular expression `~a'" regexp))
;; "0"))
;; (prog1 "0" (m4-warn "too few arguments to builtin `regexp'")))) ; TODO

27 changes: 27 additions & 0 deletions test/m4-macros.lisp
Expand Up @@ -1505,3 +1505,30 @@ m4
m4eof

:depends (list "translit")))


;; 11.6 Substituting text by regular expression
(deftest gnu-m4-11.6-1 ()
(m4-test
#>m4>
patsubst(`GNUs not Unix', `^', `OBS: ')
patsubst(`GNUs not Unix', `\<', `OBS: ')
patsubst(`GNUs not Unix', `\w*', `(\&)')
patsubst(`GNUs not Unix', `\w+', `(\&)')
patsubst(`GNUs not Unix', `[A-Z][a-z]+')
patsubst(`GNUs not Unix', `not', `NOT\')
m4

#>m4>
OBS: GNUs not Unix
OBS: GNUs OBS: not OBS: Unix
(GNUs)() (not)() (Unix)()
(GNUs) (not) (Unix)
GN not
GNUs NOT Unix
m4

:error #>m4eof>cl-m4:2:15: Warning: trailing \ ignored in replacement
m4eof

:depends (list "patsubst")))

0 comments on commit f82accc

Please sign in to comment.