[Pyparsing] Question/help with pyparsing
Brought to you by:
ptmcg
From: Vineet J. \(gmail\) <vin...@gm...> - 2007-11-09 21:52:19
|
Problem: I allow the users of my application to write small rules as python code. I use pylint to find errors in code they enter. As part of the user code they are required to enter a list (lista) and a couple of dicts (dict1, dict2) at the module level. I use lista, dict1, dict2 to add variables to the module dynamically at run time. The problem I'm having is that pylint complains of the dynamic variables that are set in lista and dict1 and dict2. So I was thinking of having a multiple stage effort to find syntax errors with the user python code. Step 1: Extract the lista, dict1, and dict2 with some pyparsing code. Step 2: Then convert list1, dict1, dict2 to valid python objects using pyparsing json conversion function Step 3: Run pylint on the python user code. Ignore errors for variables and functions defined in lista, dict1, dict2 Example User Python Code: Lista = ["variable1", "variable2"] RuleDict = { 'rule1':{'name1':'function1name', }, 'rule1':{'name1':'function1name', } } def user_logic(): print variable1 #Not error print variable2 #Not error print function1name #Not error print function1name #Not error asdfasjkdfsdkajflasj; #ERROR asfasdfasdf #ERROR How would I do step1 and step2 with pyparsing? I'm going to sign up for the oreily book and do some more reading on pyparsing this weekend, but any work that I can get from anyone on this list would be very helpful. Thanks, Vineet |