mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-19 01:18:40 +03:00
headerparse: generate bindings for function-like macros
This commit is contained in:
parent
687e5566db
commit
d0057d3338
@ -11,6 +11,8 @@ import Util
|
|||||||
import Types
|
import Types
|
||||||
import Obj
|
import Obj
|
||||||
|
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
data Args = Args { sourcePath :: String
|
data Args = Args { sourcePath :: String
|
||||||
, prefixToRemove :: String
|
, prefixToRemove :: String
|
||||||
, kebabCase :: Bool
|
, kebabCase :: Bool
|
||||||
@ -49,13 +51,30 @@ parseHeaderFile path src prefix kebab =
|
|||||||
Parsec.string "#define"
|
Parsec.string "#define"
|
||||||
Parsec.many spaceOrTab
|
Parsec.many spaceOrTab
|
||||||
name <- Parsec.many1 identifierChar
|
name <- Parsec.many1 identifierChar
|
||||||
|
argList <- Parsec.optionMaybe argList
|
||||||
Parsec.many spaceOrTab
|
Parsec.many spaceOrTab
|
||||||
number <- Parsec.many1 identifierChar
|
number <- Parsec.many1 identifierChar
|
||||||
Parsec.many spaceOrTab
|
Parsec.many spaceOrTab
|
||||||
let tyXObj =
|
-- OBS! Never kebab
|
||||||
--toTypeXObj ("a", 0)
|
case argList of
|
||||||
XObj (Sym (SymPath [] "a") Symbol) Nothing Nothing
|
Nothing ->
|
||||||
return (createRegisterForm name tyXObj prefix False) -- OBS! Never kebab
|
let tyXObj =
|
||||||
|
XObj (Sym (SymPath [] "a") Symbol) Nothing Nothing
|
||||||
|
in return (createRegisterForm name tyXObj prefix False)
|
||||||
|
Just args ->
|
||||||
|
let argsTy = genTypes (length args)
|
||||||
|
tyXObj = toFnTypeXObj argsTy ("a", 0)
|
||||||
|
in return (createRegisterForm name tyXObj prefix False)
|
||||||
|
where argList = do
|
||||||
|
_ <- Parsec.char '('
|
||||||
|
args <- Parsec.sepBy
|
||||||
|
(Parsec.many spaceOrTab >>
|
||||||
|
Parsec.many1 identifierChar)
|
||||||
|
(Parsec.char ',')
|
||||||
|
_ <- Parsec.char ')'
|
||||||
|
return args
|
||||||
|
genTypes 0 = []
|
||||||
|
genTypes n = (("a" ++ show n), 0) : genTypes (n - 1)
|
||||||
|
|
||||||
prefixedFunctionPrototype :: Parsec.Parsec String () [XObj]
|
prefixedFunctionPrototype :: Parsec.Parsec String () [XObj]
|
||||||
prefixedFunctionPrototype = do Parsec.many spaceOrTab
|
prefixedFunctionPrototype = do Parsec.many spaceOrTab
|
||||||
|
Loading…
Reference in New Issue
Block a user