diff options
| author | krasimir <krasimir@chalmers.se> | 2015-06-30 20:42:19 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2015-06-30 20:42:19 +0000 |
| commit | 22773909bf8d0e3e194411e8b9f504a51dae30bf (patch) | |
| tree | 1ae08797d51a0d83858720d6d68d7f53fa96602a /src/runtime | |
| parent | e6ddb7a578a511635cb89a80041c953b950f69c4 (diff) | |
add function 'functions' in the Haskell binding to the C runtime
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/haskell-bind/PGF2.hsc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index 77de6d857..dc3566627 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -26,6 +26,8 @@ module PGF2 (-- * CId graphvizAbstractTree,graphvizParseTree, -- * Morphology MorphoAnalysis, lookupMorpho, fullFormLexicon, + -- * Generation + functions, generateAll, -- * Exceptions PGFError(..), -- * Grammar specific callbacks @@ -524,6 +526,26 @@ alignWords lang e = unsafePerformIO $ (fids :: [CInt]) <- peekArray (fromIntegral (n_fids :: CInt)) (ptr `plusPtr` (#offset PgfAlignmentPhrase, fids)) return (phrase, map fromIntegral fids) +functions :: PGF -> [Fun] +functions p = + unsafePerformIO $ + withGuPool $ \tmpPl -> + allocaBytes (#size GuMapItor) $ \itor -> do + exn <- gu_new_exn tmpPl + ref <- newIORef [] + fptr <- wrapMapItorCallback (getFunctions ref) + (#poke GuMapItor, fn) itor fptr + pgf_iter_functions (pgf p) 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 <- peekCString (castPtr key) + writeIORef ref $! (name : names) + ----------------------------------------------------------------------------- -- Helper functions |
