1717
1818SUB = re .compile ("sub\(/(.*)/,\s+(.*)\)" )
1919SPLIT = re .compile ("split\((.),\s+(\d+),\s+(\d+|-1)\)" )
20+ STR = re .compile ("str\(\)" )
2021
2122
2223class DefintionInvalid (Exception ):
2324 pass
2425
2526
2627class Sub (This ):
27- """Regex subtituor
28+ """Regex substituor
2829
2930 Concrete syntax is '`sub(/regex/, repl)`'
3031 """
@@ -37,7 +38,6 @@ def __init__(self, method=None):
3738 self .repl = m .group (2 ).strip ()
3839 self .regex = re .compile (self .expr )
3940 self .method = method
40- print ("%r" % self )
4141
4242 def find (self , datum ):
4343 datum = DatumInContext .wrap (datum )
@@ -81,10 +81,37 @@ def find(self, datum):
8181 return [DatumInContext .wrap (value )]
8282
8383 def __eq__ (self , other ):
84- return (isinstance (other , Sub ) and self .method == other .method )
84+ return (isinstance (other , Split ) and self .method == other .method )
8585
8686 def __repr__ (self ):
8787 return '%s(%r)' % (self .__class__ .__name__ , self .method )
8888
8989 def __str__ (self ):
9090 return '`%s`' % self .method
91+
92+
93+ class Str (This ):
94+ """String converter
95+
96+ Concrete syntax is '`str()`'
97+ """
98+
99+ def __init__ (self , method = None ):
100+ m = STR .match (method )
101+ if m is None :
102+ raise DefintionInvalid ("%s is not valid" % method )
103+ self .method = method
104+
105+ def find (self , datum ):
106+ datum = DatumInContext .wrap (datum )
107+ value = str (datum .value )
108+ return [DatumInContext .wrap (value )]
109+
110+ def __eq__ (self , other ):
111+ return (isinstance (other , Str ) and self .method == other .method )
112+
113+ def __repr__ (self ):
114+ return '%s(%r)' % (self .__class__ .__name__ , self .method )
115+
116+ def __str__ (self ):
117+ return '`str()`'
0 commit comments