Make hy-repr support regex match objects
This commit is contained in:
parent
f7ab9a6e7c
commit
3dbe05302e
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
(import
|
(import
|
||||||
[math [isnan]]
|
[math [isnan]]
|
||||||
|
re
|
||||||
[hy._compat [PY3 str-type bytes-type long-type]]
|
[hy._compat [PY3 str-type bytes-type long-type]]
|
||||||
[hy.models [HyObject HyExpression HySymbol HyKeyword HyInteger HyFloat HyComplex HyList HyDict HySet HyString HyBytes]])
|
[hy.models [HyObject HyExpression HySymbol HyKeyword HyInteger HyFloat HyComplex HyList HyDict HySet HyString HyBytes]])
|
||||||
|
|
||||||
@ -101,6 +102,14 @@
|
|||||||
(hy-repr-register fraction (fn [x]
|
(hy-repr-register fraction (fn [x]
|
||||||
(.format "{}/{}" (hy-repr x.numerator) (hy-repr x.denominator))))
|
(.format "{}/{}" (hy-repr x.numerator) (hy-repr x.denominator))))
|
||||||
|
|
||||||
|
(setv matchobject-type (type (re.match "" "")))
|
||||||
|
(hy-repr-register matchobject-type (fn [x]
|
||||||
|
(.format "<{}.{} object; :span {} :match {}>"
|
||||||
|
matchobject-type.__module__
|
||||||
|
matchobject-type.__name__
|
||||||
|
(hy-repr (.span x))
|
||||||
|
(hy-repr (.group x 0)))))
|
||||||
|
|
||||||
(for [[types fmt] (partition [
|
(for [[types fmt] (partition [
|
||||||
list "[...]"
|
list "[...]"
|
||||||
[set HySet] "#{...}"
|
[set HySet] "#{...}"
|
||||||
|
@ -113,6 +113,15 @@
|
|||||||
(+ "{" (.join " " p) "}")
|
(+ "{" (.join " " p) "}")
|
||||||
[p (permutations ["1 2" "3 [4 {...}]" "6 7"])]))))
|
[p (permutations ["1 2" "3 [4 {...}]" "6 7"])]))))
|
||||||
|
|
||||||
|
(defn test-matchobject []
|
||||||
|
(import re)
|
||||||
|
(setv mo (re.search "b+" "aaaabbbccc"))
|
||||||
|
(assert (= (hy-repr mo)
|
||||||
|
(.format
|
||||||
|
#[[<{}.SRE_Match object; :span {} :match "bbb">]]
|
||||||
|
(. (type mo) __module__)
|
||||||
|
(if PY3 "(, 4 7)" "(, (int 4) (int 7))")))))
|
||||||
|
|
||||||
(defn test-hy-repr-custom []
|
(defn test-hy-repr-custom []
|
||||||
|
|
||||||
(defclass C [object])
|
(defclass C [object])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user