]>
git.madduck.net Git - etc/vim.git/blobdiff - blib2to3/pgen2/conv.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:
# Local imports
from pgen2 import grammar, token
# Local imports
from pgen2 import grammar, token
lineno += 1
mo = re.match(r"^#define\s+(\w+)\s+(\d+)$", line)
if not mo and line.strip():
lineno += 1
mo = re.match(r"^#define\s+(\w+)\s+(\d+)$", line)
if not mo and line.strip():
- print("%s(%s): can't parse %s" % (filename, lineno,
- line.strip()))
+ print("%s(%s): can't parse %s" % (filename, lineno, line.strip()))
else:
symbol, number = mo.groups()
number = int(number)
else:
symbol, number = mo.groups()
number = int(number)
lineno = 0
# Expect the two #include lines
lineno = 0
# Expect the two #include lines
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == '#include "pgenheaders.h"\n', (lineno, line)
assert line == '#include "pgenheaders.h"\n', (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == '#include "grammar.h"\n', (lineno, line)
# Parse the state definitions
assert line == '#include "grammar.h"\n', (lineno, line)
# Parse the state definitions
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
allarcs = {}
states = []
while line.startswith("static arc "):
while line.startswith("static arc "):
allarcs = {}
states = []
while line.startswith("static arc "):
while line.startswith("static arc "):
- mo = re.match(r"static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$",
- line)
+ mo = re.match(r"static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$", line)
assert mo, (lineno, line)
n, m, k = list(map(int, mo.groups()))
arcs = []
for _ in range(k):
assert mo, (lineno, line)
n, m, k = list(map(int, mo.groups()))
arcs = []
for _ in range(k):
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"\s+{(\d+), (\d+)},$", line)
assert mo, (lineno, line)
i, j = list(map(int, mo.groups()))
arcs.append((i, j))
mo = re.match(r"\s+{(\d+), (\d+)},$", line)
assert mo, (lineno, line)
i, j = list(map(int, mo.groups()))
arcs.append((i, j))
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "};\n", (lineno, line)
allarcs[(n, m)] = arcs
assert line == "};\n", (lineno, line)
allarcs[(n, m)] = arcs
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"static state states_(\d+)\[(\d+)\] = {$", line)
assert mo, (lineno, line)
s, t = list(map(int, mo.groups()))
assert s == len(states), (lineno, line)
state = []
for _ in range(t):
mo = re.match(r"static state states_(\d+)\[(\d+)\] = {$", line)
assert mo, (lineno, line)
s, t = list(map(int, mo.groups()))
assert s == len(states), (lineno, line)
state = []
for _ in range(t):
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"\s+{(\d+), arcs_(\d+)_(\d+)},$", line)
assert mo, (lineno, line)
k, n, m = list(map(int, mo.groups()))
mo = re.match(r"\s+{(\d+), arcs_(\d+)_(\d+)},$", line)
assert mo, (lineno, line)
k, n, m = list(map(int, mo.groups()))
assert k == len(arcs), (lineno, line)
state.append(arcs)
states.append(state)
assert k == len(arcs), (lineno, line)
state.append(arcs)
states.append(state)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "};\n", (lineno, line)
assert line == "};\n", (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
self.states = states
# Parse the dfas
self.states = states
# Parse the dfas
assert mo, (lineno, line)
ndfas = int(mo.group(1))
for i in range(ndfas):
assert mo, (lineno, line)
ndfas = int(mo.group(1))
for i in range(ndfas):
- lineno, line = lineno+1, next(f)
- mo = re.match(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$',
- line)
+ lineno, line = lineno + 1, next(f)
+ mo = re.match(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$', line)
assert mo, (lineno, line)
symbol = mo.group(2)
number, x, y, z = list(map(int, mo.group(1, 3, 4, 5)))
assert mo, (lineno, line)
symbol = mo.group(2)
number, x, y, z = list(map(int, mo.group(1, 3, 4, 5)))
assert x == 0, (lineno, line)
state = states[z]
assert y == len(state), (lineno, line)
assert x == 0, (lineno, line)
state = states[z]
assert y == len(state), (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r'\s+("(?:\\\d\d\d)*")},$', line)
assert mo, (lineno, line)
first = {}
mo = re.match(r'\s+("(?:\\\d\d\d)*")},$', line)
assert mo, (lineno, line)
first = {}
for i, c in enumerate(rawbitset):
byte = ord(c)
for j in range(8):
for i, c in enumerate(rawbitset):
byte = ord(c)
for j in range(8):
- if byte & (1<< j):
- first[i* 8 + j] = 1
+ if byte & (1 << j):
+ first[i * 8 + j] = 1
dfas[number] = (state, first)
dfas[number] = (state, first)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "};\n", (lineno, line)
self.dfas = dfas
# Parse the labels
labels = []
assert line == "};\n", (lineno, line)
self.dfas = dfas
# Parse the labels
labels = []
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"static label labels\[(\d+)\] = {$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
for i in range(nlabels):
mo = re.match(r"static label labels\[(\d+)\] = {$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
for i in range(nlabels):
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r'\s+{(\d+), (0|"\w+")},$', line)
assert mo, (lineno, line)
x, y = mo.groups()
mo = re.match(r'\s+{(\d+), (0|"\w+")},$', line)
assert mo, (lineno, line)
x, y = mo.groups()
else:
y = eval(y)
labels.append((x, y))
else:
y = eval(y)
labels.append((x, y))
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "};\n", (lineno, line)
self.labels = labels
# Parse the grammar struct
assert line == "};\n", (lineno, line)
self.labels = labels
# Parse the grammar struct
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "grammar _PyParser_Grammar = {\n", (lineno, line)
assert line == "grammar _PyParser_Grammar = {\n", (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"\s+(\d+),$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
assert ndfas == len(self.dfas)
mo = re.match(r"\s+(\d+),$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
assert ndfas == len(self.dfas)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "\tdfas,\n", (lineno, line)
assert line == "\tdfas,\n", (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"\s+{(\d+), labels},$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
assert nlabels == len(self.labels), (lineno, line)
mo = re.match(r"\s+{(\d+), labels},$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
assert nlabels == len(self.labels), (lineno, line)
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
mo = re.match(r"\s+(\d+)$", line)
assert mo, (lineno, line)
start = int(mo.group(1))
assert start in self.number2symbol, (lineno, line)
self.start = start
mo = re.match(r"\s+(\d+)$", line)
assert mo, (lineno, line)
start = int(mo.group(1))
assert start in self.number2symbol, (lineno, line)
self.start = start
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
assert line == "};\n", (lineno, line)
try:
assert line == "};\n", (lineno, line)
try:
- lineno, line = lineno+ 1, next(f)
+ lineno, line = lineno + 1, next(f)
except StopIteration:
pass
else:
except StopIteration:
pass
else:
def finish_off(self):
"""Create additional useful structures. (Internal)."""
def finish_off(self):
"""Create additional useful structures. (Internal)."""
- self.keywords = {} # map from keyword strings to arc labels
- self.tokens = {} # map from numeric token values to arc labels
+ self.keywords = {} # map from keyword strings to arc labels
+ self.tokens = {} # map from numeric token values to arc labels
for ilabel, (type, value) in enumerate(self.labels):
if type == token.NAME and value is not None:
self.keywords[value] = ilabel
for ilabel, (type, value) in enumerate(self.labels):
if type == token.NAME and value is not None:
self.keywords[value] = ilabel