mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 01:25:04 +03:00
Started working on utility for parsing C headers.
This commit is contained in:
parent
f572161985
commit
01d77688ea
@ -64,6 +64,18 @@ executable carp
|
||||
, process
|
||||
default-language: Haskell2010
|
||||
|
||||
executable carp-header-parse
|
||||
hs-source-dirs: headerparse
|
||||
main-is: Main.hs
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends: base
|
||||
, CarpHask
|
||||
, containers
|
||||
, directory
|
||||
, cmdargs
|
||||
, parsec
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite CarpHask-test
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: test
|
||||
@ -77,4 +89,4 @@ test-suite CarpHask-test
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://github.com/eriksvedang/Carp
|
||||
location: https://github.com/carp-lang/Carp
|
||||
|
4
examples/parse_me.h
Normal file
4
examples/parse_me.h
Normal file
@ -0,0 +1,4 @@
|
||||
void boo();
|
||||
char hoo();
|
||||
int foo(int x);
|
||||
float goo(double x, double y);
|
33
headerparse/Main.hs
Normal file
33
headerparse/Main.hs
Normal file
@ -0,0 +1,33 @@
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# OPTIONS_GHC -fno-cse #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import System.Console.CmdArgs
|
||||
import System.IO (readFile)
|
||||
import Text.Parsec ((<|>))
|
||||
import qualified Text.Parsec as Parsec
|
||||
import Util
|
||||
import Types
|
||||
import Obj
|
||||
|
||||
data Args = Args { sourcePath :: String
|
||||
} deriving (Show, Data, Typeable)
|
||||
|
||||
main = do parsedArgs <- cmdArgs (Args { sourcePath = def &= argPos 0 }
|
||||
&= summary "Carp Header Parse 0.0.1")
|
||||
let path = sourcePath parsedArgs
|
||||
if path /= ""
|
||||
then do source <- readFile path
|
||||
putStrLn (joinWith "\n" (map pretty (parseHeaderFile path source)))
|
||||
else print parsedArgs
|
||||
|
||||
parseHeaderFile :: FilePath -> String -> [XObj]
|
||||
parseHeaderFile path src =
|
||||
case Parsec.runParser cSyntax () path src of
|
||||
Left err -> error (show err)
|
||||
Right ok -> ok
|
||||
where
|
||||
cSyntax :: Parsec.Parsec String () [XObj]
|
||||
cSyntax = do _ <- Parsec.many Parsec.anyChar
|
||||
return [(XObj (Sym (SymPath [] "foobar") Symbol) Nothing Nothing)]
|
Loading…
Reference in New Issue
Block a user