Created
April 11, 2012 16:59
-
-
Save jbclements/2360530 to your computer and use it in GitHub Desktop.
Kacha
This file contains hidden or 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
from slimit.parser import Parser | |
from slimit.visitors import nodevisitor | |
from slimit import ast | |
from sets import Set | |
# create parser instance | |
parser = Parser() | |
# parse the javascript code | |
#tree = parser.parse('for(var i=0; i<10; i++) {var x=5+i;}') | |
tree = parser.parse('var s = 1; var t = {u:s,v:1}; t.w = t.w;') | |
# create set to store variables | |
variables = set() | |
#iterate through the tree to print the variable names | |
for node in nodevisitor.visit(tree): | |
if isinstance(node, ast.Identifier): | |
variables.add(node.value) | |
# print the variable names | |
for var in variables: | |
print 'Var name: %s' % var | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment