Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 22, 2011 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swannodette/1161596 to your computer and use it in GitHub Desktop.
Save swannodette/1161596 to your computer and use it in GitHub Desktop.
regex.clj
(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