From 6de9636ff26aef7ed1cc8b3bc5d93f27a91b861d Mon Sep 17 00:00:00 2001 From: krasimir Date: Wed, 25 Jan 2017 10:44:08 +0000 Subject: [PATCH] add functionsByCat in the Haskell binding --- src/runtime/haskell-bind/PGF2.hsc | 23 ++++++++++++++++++++++- src/runtime/haskell-bind/PGF2/FFI.hs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index 65de76ddf..b9c5412e0 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -28,7 +28,7 @@ module PGF2 (-- * CId -- * Morphology MorphoAnalysis, lookupMorpho, fullFormLexicon, -- * Generation - functions, generateAll, + functions, functionsByCat, generateAll, -- * Exceptions PGFError(..), -- * Grammar specific callbacks @@ -540,6 +540,27 @@ functions p = name <- peekUtf8CString (castPtr key) writeIORef ref $! (name : names) +functionsByCat :: PGF -> Cat -> [Fun] +functionsByCat p cat = + unsafePerformIO $ + withGuPool $ \tmpPl -> + allocaBytes (#size GuMapItor) $ \itor -> do + exn <- gu_new_exn tmpPl + ref <- newIORef [] + fptr <- wrapMapItorCallback (getFunctions ref) + (#poke GuMapItor, fn) itor fptr + ccat <- newUtf8CString cat tmpPl + pgf_iter_functions_by_cat (pgf p) ccat itor exn + freeHaskellFunPtr fptr + fs <- readIORef ref + return (reverse fs) + where + getFunctions :: IORef [String] -> MapItorCallback + getFunctions ref itor key value exn = do + names <- readIORef ref + name <- peekUtf8CString (castPtr key) + writeIORef ref $! (name : names) + categories :: PGF -> [Cat] categories pgf = -- !!! quick hack nub [cat | f<-functions pgf, let DTyp _ cat _=functionType pgf f] diff --git a/src/runtime/haskell-bind/PGF2/FFI.hs b/src/runtime/haskell-bind/PGF2/FFI.hs index bc9622a68..8c4a1f5de 100644 --- a/src/runtime/haskell-bind/PGF2/FFI.hs +++ b/src/runtime/haskell-bind/PGF2/FFI.hs @@ -170,7 +170,7 @@ foreign import ccall "pgf/pgf.h pgf_iter_functions" pgf_iter_functions :: Ptr PgfPGF -> Ptr GuMapItor -> Ptr GuExn -> IO () foreign import ccall "pgf/pgf.h pgf_iter_functions_by_cat" - pgf_iter_functions_by_cat :: Ptr PgfPGF -> Ptr GuMapItor -> Ptr GuExn -> IO () + pgf_iter_functions_by_cat :: Ptr PgfPGF -> CString -> Ptr GuMapItor -> Ptr GuExn -> IO () foreign import ccall "pgf/pgf.h pgf_function_type" pgf_function_type :: Ptr PgfPGF -> CString -> IO (Ptr PgfType)