How to parse Objective-C code in a Cocoa application

I am writing a desktop application for Mac OS X in which I want to parse Objective-C snippets, such as variable and method declarations, as well as the full title and source files of Objective-C.

It seems to me that I should use Clang for this, but I could do with some pointers and examples how to integrate it as a library in my project and how to call it to parse strings and files.

Can anybody help me?

+4
source share
1 answer

You probably want libclang , view the code at http://llvm.org/svn/llvm-project/cfe/trunk/tools/libclang/ (although you will need to check the entire Clang repository to create it). Unfortunately, there is very little documentation. There is a presentation http://llvm.org/devmtg/2010-11/Gregor-libclang.pdf that can help run things, but basically just hunting through code is the way to go.

Clang is actually more modular than libclang provides (you can only import the components you want). If you are adventurous, there are examples at http://llvm.org/svn/llvm-project/cfe/trunk/examples/ .

+4
source

Source: https://habr.com/ru/post/1395581/


All Articles