]>
git.madduck.net Git - etc/vim.git/blobdiff - blib2to3/pgen2/literals.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
-simple_escapes = {"a": "\a",
- "b": "\b",
- "f": "\f",
- "n": "\n",
- "r": "\r",
- "t": "\t",
- "v": "\v",
- "'": "'",
- '"': '"',
- "\\": "\\"}
-
-def escape(m):
+from typing import Dict, Match, Text
+
+
+simple_escapes: Dict[Text, Text] = {
+ "a": "\a",
+ "b": "\b",
+ "f": "\f",
+ "n": "\n",
+ "r": "\r",
+ "t": "\t",
+ "v": "\v",
+ "'": "'",
+ '"': '"',
+ "\\": "\\",
+}
+
+
+def escape(m: Match[Text]) -> Text:
all, tail = m.group(0, 1)
assert all.startswith("\\")
esc = simple_escapes.get(tail)
all, tail = m.group(0, 1)
assert all.startswith("\\")
esc = simple_escapes.get(tail)
raise ValueError("invalid octal string escape ('\\%s')" % tail) from None
return chr(i)
raise ValueError("invalid octal string escape ('\\%s')" % tail) from None
return chr(i)
+
+def evalString(s: Text) -> Text:
assert s.startswith("'") or s.startswith('"'), repr(s[:1])
q = s[0]
assert s.startswith("'") or s.startswith('"'), repr(s[:1])
q = s[0]
- if s[:3] == q* 3:
- q = q* 3
- assert s.endswith(q), repr(s[-len(q):])
- assert len(s) >= 2* len(q)
- s = s[len(q): -len(q)]
+ if s[:3] == q * 3:
+ q = q * 3
+ assert s.endswith(q), repr(s[-len(q) :])
+ assert len(s) >= 2 * len(q)
+ s = s[len(q) : -len(q)]
return re.sub(r"\\(\'|\"|\\|[abfnrtv]|x.{0,2}|[0-7]{1,3})", escape, s)
return re.sub(r"\\(\'|\"|\\|[abfnrtv]|x.{0,2}|[0-7]{1,3})", escape, s)
for i in range(256):
c = chr(i)
s = repr(c)
for i in range(256):
c = chr(i)
s = repr(c)