Source repository is on github.
If you "cabal unpack language-objc; cd language-objc-0.4.2.0/examples/", there are a number of examples that can get you started. For the truly impatient:
import Language.ObjC
import qualified Data.ByteString.Char8 as B
-- parsing bytestrings
objcTranslUnit = B.pack "int a=0;"
errOrAST = parseC objcTranslUnit nopos
-- parsing from a file
fileAST sourceFile = do
result <- parseCFile (newGCC "gcc") Nothing [] sourceFile
return $ either (error . show) id result
A few things to note:- Input files must be preprocessed. 'parseCFile' will do this for you. Non-preprocessed source can only be parsed in very limited situations (did you know that 'id' is a typedef? And 'id' is also commonly used as an identifier to methods/functions, even in system libraries, so it can't be a keyword?).
- The objective-C extensions have only been lightly tested, but I think most of the core functionality works. I am unaware of a full specification for the language, which makes it difficult to say if it's complete.
- Most of the code in Language.ObjC.Analysis is not yet compatible with Objective-C extensions.
- One difference from language-c is that certain GNU attributes can no longer be parsed due to grammar ambiguities.
- Attempting to compile at -O2 requires a lot of memory due to the giant Happy parser that's produced.
I am most grateful to Benedikt Huber, Manuel Chakravarty, Duncan Coutts, Bertram Felgenhauer, and all contributors to language-c, as they're responsible for most of the code. Bugs are mine. Comments and patches welcome.
Really awesome! I've been wanting to start this myself, but the huge amount of work kept me from doing it. Very impressed!
ReplyDelete