Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try a more flexible approach to autogenerating Tree wrapper subclasses
- Loading branch information
1 parent
9b51459
commit a12a44a
Showing
5 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from collections import namedtuple | ||
|
||
class TreeType(namedtuple('TreeType', 'SYM, STRING, TYPE, NARGS')): | ||
def camel_cased_string(self): | ||
return ''.join([word.title() | ||
for word in self.STRING.split('_')]) | ||
|
||
def iter_tree_types(): | ||
import re | ||
f = open('tree-types.txt') | ||
for line in f: | ||
# e.g. | ||
# ERROR_MARK, "error_mark", tcc_exceptional, 0 | ||
m = re.match('(.+), (.+), (.+), (.+)', line) | ||
if m: | ||
yield TreeType(SYM=m.group(1), | ||
STRING=m.group(2)[1:-1], | ||
TYPE=m.group(3), | ||
NARGS=int(m.group(4))) | ||
else: | ||
# print 'UNMATCHED: ', line | ||
assert(line.startswith('#') or line.strip() == '') | ||
f.close() | ||
|
||
for t in iter_tree_types(): | ||
print ( | ||
""" | ||
cdef class %s(Tree): | ||
_STRING = %r | ||
_SYM = %r | ||
_TYPE = %r | ||
_NARGS = %i | ||
""" % (t.camel_cased_string(), | ||
t.STRING, t.SYM, t.TYPE, t.NARGS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ | ||
SYM, STRING, TYPE, NARGS | ||
#define END_OF_BASE_TREE_CODES | ||
#include "all-tree.def" | ||
#undef DEFTREECODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters