CodeSmith modules
__init__.py
Entry point for the codesmith package, defines the IPython magic functions.
codesmith(line='', cell=None, local_ns=None)
Defines line and cell magic functions %codesmith and %%codesmith (respectively). local_ns should be set by IPython
Source code in codesmith/__init__.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
reload()
For active development: reloads this module and all submodules
Source code in codesmith/__init__.py
11 12 13 14 15 16 | |
read.py
Provides the parsing functions for codesmith grammars
Grammar
Bases: dict
Stores an entire TSP Language grammar in a dict of Rule's
Source code in codesmith/read.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
__call__(f)
deprecated: for use as a decorator
Source code in codesmith/read.py
125 126 127 128 129 130 131 132 133 | |
__getitem__(name)
Generate a new Rule if it doesn't exist
Source code in codesmith/read.py
114 115 116 117 118 | |
Out
Class to allow special outputs in grammars.
Instatiated once as OUT below, and used like: OUT>>"{}{}" with a
formatted string after a right-shift operator.
Source code in codesmith/read.py
26 27 28 29 30 31 32 | |
Rule
Bases: Forward
A single rule in a (codesmith-style) pyparsing grammar
Source code in codesmith/read.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
__ilshift__(syntax)
The main way to define a rule uses the augmented left-shift operator <<=
Source code in codesmith/read.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
parse(s)
deprecated
Source code in codesmith/read.py
89 90 91 92 93 94 95 96 97 98 | |
read(s, verbose=False)
Applies this rule to string s, returning an AST in the reference language
Source code in codesmith/read.py
100 101 102 103 104 105 106 | |
BlockOf(p)
The codesmith version of pyparsings IndentedBlock
Source code in codesmith/read.py
40 41 42 43 44 45 46 47 48 49 | |
ListOf(p, delim=',', trailer=True, min=None)
The codesmith version of pyparsing's delimited_list
Source code in codesmith/read.py
35 36 37 38 | |
eval.py
Provides a specialized evaluation procedure for TSP languages
RemoveOmega
Bases: NodeTransformer
NodeTransformer to remove ω wrappers in an AST
Source code in codesmith/eval.py
50 51 52 53 54 55 56 | |
argvars(node)
Returns the argument list for a lambda expression
Source code in codesmith/eval.py
74 75 76 77 78 | |
do_eval(node, globals, locals, debug=False, shadowed=[])
Internal function for eval_
Source code in codesmith/eval.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
ensurenode(node)
Parses node into AST if necessary
Source code in codesmith/eval.py
67 68 69 70 71 72 | |
eval_(node, globals=None, locals=None, debug=False)
Returns the value for node if evaluable, or a string with as many parts of node eval'ed as possible otherwise
Source code in codesmith/eval.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
freevars(node)
Returns the free variables in node
Source code in codesmith/eval.py
87 88 89 90 91 92 93 94 95 96 97 | |
get_lambda(node)
Abstraction to allow either Lambda ast nodes themselves or, say,
functions that have an __ast__ attribute to act as lambdas
Source code in codesmith/eval.py
99 100 101 102 103 104 | |
newvar(oldvar, usedvars)
Generates a name for oldvar that is not in usedvars
Source code in codesmith/eval.py
80 81 82 83 84 85 | |
sub(node, subs)
Makes the substitutions in subs to node without variable capture subs maps variables (as strings) to their AST substitutions returns the new AST node
Source code in codesmith/eval.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
unparse(node, remove_omega=False)
Attempts to convert node into python source code, or at least dump the AST; otherwise, returns node
Source code in codesmith/eval.py
58 59 60 61 62 63 64 65 | |
unprintable(x)
True for items not easily printed out in their full form
Source code in codesmith/eval.py
106 107 108 109 110 | |
wrapper.py
The Wrapper class and ω (omega) function for custom objects in a TSP language
Wrapper
Bases: object
Base Class for a wrapped object (the "candy" object in the wrapper)
Source code in codesmith/wrapper.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
candy_class()
classmethod
Get the class object (type) for the candy
Source code in codesmith/wrapper.py
11 12 13 14 15 | |
candy_repr()
Get the repr for the candy class
Source code in codesmith/wrapper.py
18 19 20 21 | |
candy_type()
Get the type of the candy class
Source code in codesmith/wrapper.py
23 24 25 | |
register_candy(*candy)
Generate a new, default Wrapper class for one or more candy class
Source code in codesmith/wrapper.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
register_wrapper(*args)
Decorator to register a defined wrapper for one or more candy classes
Source code in codesmith/wrapper.py
58 59 60 61 62 63 64 65 66 67 68 69 | |
unregister_candy(candy)
Unregister a wrapper for this candy class
Source code in codesmith/wrapper.py
95 96 97 | |
ω(x)
Wrapper factory that checks for defined subclass, or creates one if necessary
Source code in codesmith/wrapper.py
49 50 51 52 53 54 55 | |