aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Plex/Traditional.py
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /contrib/tools/cython/Cython/Plex/Traditional.py
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Plex/Traditional.py')
-rw-r--r--contrib/tools/cython/Cython/Plex/Traditional.py72
1 files changed, 36 insertions, 36 deletions
diff --git a/contrib/tools/cython/Cython/Plex/Traditional.py b/contrib/tools/cython/Cython/Plex/Traditional.py
index 5c06cc23b4..ec7252daed 100644
--- a/contrib/tools/cython/Cython/Plex/Traditional.py
+++ b/contrib/tools/cython/Cython/Plex/Traditional.py
@@ -1,42 +1,42 @@
-#=======================================================================
-#
-# Python Lexical Analyser
-#
-# Traditional Regular Expression Syntax
-#
-#=======================================================================
-
-from __future__ import absolute_import
-
-from .Regexps import Alt, Seq, Rep, Rep1, Opt, Any, AnyBut, Bol, Eol, Char
-from .Errors import PlexError
-
-
-class RegexpSyntaxError(PlexError):
+#=======================================================================
+#
+# Python Lexical Analyser
+#
+# Traditional Regular Expression Syntax
+#
+#=======================================================================
+
+from __future__ import absolute_import
+
+from .Regexps import Alt, Seq, Rep, Rep1, Opt, Any, AnyBut, Bol, Eol, Char
+from .Errors import PlexError
+
+
+class RegexpSyntaxError(PlexError):
pass
-
-
-def re(s):
+
+
+def re(s):
"""
Convert traditional string representation of regular expression |s|
into Plex representation.
"""
return REParser(s).parse_re()
-
-
-class REParser(object):
+
+
+class REParser(object):
def __init__(self, s):
self.s = s
self.i = -1
self.end = 0
self.next()
-
+
def parse_re(self):
re = self.parse_alt()
if not self.end:
self.error("Unexpected %s" % repr(self.c))
return re
-
+
def parse_alt(self):
"""Parse a set of alternative regexps."""
re = self.parse_seq()
@@ -47,14 +47,14 @@ class REParser(object):
re_list.append(self.parse_seq())
re = Alt(*re_list)
return re
-
+
def parse_seq(self):
"""Parse a sequence of regexps."""
re_list = []
while not self.end and not self.c in "|)":
re_list.append(self.parse_mod())
return Seq(*re_list)
-
+
def parse_mod(self):
"""Parse a primitive regexp followed by *, +, ? modifiers."""
re = self.parse_prim()
@@ -67,10 +67,10 @@ class REParser(object):
re = Opt(re)
self.next()
return re
-
+
def parse_prim(self):
"""Parse a primitive regexp."""
- c = self.get()
+ c = self.get()
if c == '.':
re = AnyBut("\n")
elif c == '^':
@@ -88,7 +88,7 @@ class REParser(object):
c = self.get()
re = Char(c)
return re
-
+
def parse_charset(self):
"""Parse a charset. Does not include the surrounding []."""
char_list = []
@@ -113,7 +113,7 @@ class REParser(object):
return AnyBut(chars)
else:
return Any(chars)
-
+
def next(self):
"""Advance to the next char."""
s = self.s
@@ -123,14 +123,14 @@ class REParser(object):
else:
self.c = ''
self.end = 1
-
+
def get(self):
if self.end:
self.error("Premature end of string")
c = self.c
self.next()
return c
-
+
def lookahead(self, n):
"""Look ahead n chars."""
j = self.i + n
@@ -138,7 +138,7 @@ class REParser(object):
return self.s[j]
else:
return ''
-
+
def expect(self, c):
"""
Expect to find character |c| at current position.
@@ -148,11 +148,11 @@ class REParser(object):
self.next()
else:
self.error("Missing %s" % repr(c))
-
+
def error(self, mess):
"""Raise exception to signal syntax error in regexp."""
raise RegexpSyntaxError("Syntax error in regexp %s at position %d: %s" % (
repr(self.s), self.i, mess))
-
-
-
+
+
+