summaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2017-01-25 10:44:08 +0000
committerkrasimir <krasimir@chalmers.se>2017-01-25 10:44:08 +0000
commit6de9636ff26aef7ed1cc8b3bc5d93f27a91b861d (patch)
treed1d2a9fcd5539d49d398cb30b01bab09ca4b5f13 /src/runtime
parent8d3464dfb02ac1be6f99f5310e959de5fc28a7f0 (diff)
add functionsByCat in the Haskell binding
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/haskell-bind/PGF2.hsc23
-rw-r--r--src/runtime/haskell-bind/PGF2/FFI.hs2
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)