-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Vensim translator to make use of parsimonious node visitor.
- Loading branch information
1 parent
a61b974
commit b4a4c6d
Showing
7 changed files
with
461 additions
and
231 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 |
---|---|---|
@@ -1,36 +1,11 @@ | ||
import collections | ||
|
||
def clean_identifier(string): | ||
""" | ||
at the moment, we may have trailing spaces on an identifier that need to be dealt with | ||
in the future, it would be better to improve the parser so that it handles that whitespace properly | ||
""" | ||
string = string.lower() | ||
string = string.strip() | ||
string = string.replace(' ', '_') | ||
return string | ||
|
||
|
||
|
||
def update(d, u): | ||
""" | ||
Facilitates nested dictionary updating. | ||
This is stolen from: | ||
http://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth | ||
""" | ||
for k, v in u.iteritems(): | ||
if isinstance(v, collections.Mapping): | ||
r = update(d.get(k, {}), v) | ||
d[k] = r | ||
else: | ||
d[k] = u[k] | ||
return d | ||
|
||
|
||
|
||
def getChildren(node, name): | ||
""" | ||
Returns the children of node 'node' that are named 'name' | ||
in a list. | ||
""" | ||
return [child for child in node.children if child.expr_name == name] | ||
|
Oops, something went wrong.