Created
August 22, 2011 03:28
-
-
Save swannodette/1161596 to your computer and use it in GitHub Desktop.
regex.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns match.regex | |
(:use [match.core :only [IPatternCompile match-1 to-source | |
emit-pattern pattern-equals | |
pattern-compare]])) | |
(defrecord RegexPattern [regex] | |
IPatternCompile | |
(to-source [this ocr] | |
`(re-matches ~regex ~ocr))) | |
(defmethod emit-pattern java.util.regex.Pattern | |
[pat] | |
(RegexPattern. pat)) | |
(defmethod pattern-equals [RegexPattern RegexPattern] | |
[a b] (= (:regex a) (:regex b))) | |
(comment | |
(let [s "hello world"] | |
(match-1 s | |
#"hello.+" :a0 | |
#"goodbye.+" :a1 | |
:else :a2)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment