prabodhprakash prabodhprakash - 5 months ago 29
Bash Question

shell script to parse Swift file to extract all methods in them

I have a swift file that I need to read and find out all methods in it. Is there a way I can do so using shell script (or any command line script)

I have tried

swiftc -dum-ast
which dumps the AST of the swift file. I'm working over it, but I do not have correct answer till now.


You can use the -print-ast option of the swiftc compiler to parse the file and dump the functions and variables. Combine that with grep to find just the functions and redirect that to a result file:

swiftc MySwiftFile.swift -print-ast | grep ' func ' > result.txt