How to use recursion in python to parse method body from java code? -


i have java code , need parse in python.i using regex in python purpose. able find method names , find method body need write regular expression conditions. ex. code parsing?

class abc {  public void main()  {      //some code        if(blabla)       {        }       else       {         }        //some code     } public static int method1(int asd,int bad) {     //body }  } 

i need output [(int,method1,"body"),('void',main,"body")] wrote regular expression r'[public|private|protected]\s+[static]\s+(\w+)\s+(\w+)\(.*\)\n\{' find method name ,but how find body may contain several '{','}'?

you aren't going successful regular expressions. need actual parser.

the parser recommend pyparsing, easy use , understand.

if need more expressive parsing there antlr has grammars java built , outputs python code easily.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -