Parse binaries and UTF strings with leading whitespace
[ton] / don / string.py
index 1e930ac..0a324cb 100644 (file)
@@ -106,6 +106,7 @@ def _make_integer_parser(width):
 _BINARY32_MATCHER = re.compile(r'(-?\d+\.\d+)f')
 _BINARY64_MATCHER = re.compile(r'(-?\d+\.\d+)d')
 
+@_consume_leading_whitespace
 def _binary32_parser(s):
     match = _BINARY32_MATCHER.match(s)
 
@@ -119,6 +120,7 @@ def _binary32_parser(s):
 
     return _shared._FAILED_PARSE_RESULT
 
+@_consume_leading_whitespace
 def _binary64_parser(s):
     match = _BINARY64_MATCHER.match(s)
 
@@ -134,6 +136,7 @@ def _binary64_parser(s):
 
 _BINARY_MATCHER = re.compile(r'"([\da-f]*)"b')
 
+@_consume_leading_whitespace
 def _binary_parser(s):
     match = _BINARY_MATCHER.match(s)
 
@@ -149,7 +152,8 @@ def _binary_parser(s):
 def _make_utf_parser(encoding):
     matcher = re.compile(r'"(.*?)"' + encoding)
 
-    def parser(s):
+    @_consume_leading_whitespace
+    def utf_parser(s):
         match = matcher.match(s)
 
         if match:
@@ -161,7 +165,7 @@ def _make_utf_parser(encoding):
 
         return _shared._FAILED_PARSE_RESULT
 
-    return parser
+    return utf_parser
 
 def _prefix_with_comma(parser):
     def wrapped(s):