Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created April 11, 2012 16:59
Show Gist options
  • Save jbclements/2360530 to your computer and use it in GitHub Desktop.
Save jbclements/2360530 to your computer and use it in GitHub Desktop.
Kacha
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