Skip to content

Parse errors when parsing macOS system headers #85

Description

@roboguy13

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions