Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse errors when parsing macOS system headers #85

Open
roboguy13 opened this issue Oct 5, 2021 · 1 comment
Open

Parse errors when parsing macOS system headers #85

roboguy13 opened this issue Oct 5, 2021 · 1 comment

Comments

@roboguy13
Copy link

roboguy13 commented Oct 5, 2021

I have recently noticed the issues in the title. There seem to be some syntax extensions involved which language-c does not appear to currently support.

A small example:

Contents of test.c:

#include <dirent.h>

Contents of Test.hs:

{-# LANGUAGE LambdaCase #-}

import           Language.C
import           Language.C.System.Preprocess
import           Language.C.System.GCC

main :: IO ()
main = do
  let gcc = newGCC "/usr/bin/gcc"
      fileName = "test.c"

  runPreprocessor gcc (cppFile fileName) >>= \case
    Left err -> putStrLn ("Preprocessor error: " ++ show err)

    Right preprocessed ->
      case parseC preprocessed (initPos fileName) of
        Left err -> putStrLn ("Parse error: " ++ show err)
        Right _ -> putStrLn "Success"

Executing runghc Test.hs in the same directory as test.c produces the following:

Parse error: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/dirent.h:159: (column 10) [ERROR]  >>> Syntax Error !
  Syntax error !
  The symbol `^' does not fit here.

The relevant line, and surrounding lines, in that header are these:

int scandir_b(const char *, struct dirent ***,
    int (^)(const struct dirent *) __scandir_noescape,         //  **** This is line 159  *****
    int (^)(const struct dirent **, const struct dirent **) __scandir_noescape)
    __DARWIN_INODE64(scandir_b) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);

I think this syntax extension is for blocks, but I haven't used that feature before.

@expipiplus1
Copy link
Collaborator

expipiplus1 commented Oct 6, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants