mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
a better implementation for PGF2.categories
This commit is contained in:
@@ -628,8 +628,24 @@ functionsByCat p cat =
|
|||||||
-- The categories are defined in the abstract syntax
|
-- The categories are defined in the abstract syntax
|
||||||
-- with the \'cat\' keyword.
|
-- with the \'cat\' keyword.
|
||||||
categories :: PGF -> [Cat]
|
categories :: PGF -> [Cat]
|
||||||
categories pgf = -- !!! quick hack
|
categories p =
|
||||||
nub [cat | f<-functions pgf, let (_, cat, _) = unType (functionType pgf f)]
|
unsafePerformIO $
|
||||||
|
withGuPool $ \tmpPl ->
|
||||||
|
allocaBytes (#size GuMapItor) $ \itor -> do
|
||||||
|
exn <- gu_new_exn tmpPl
|
||||||
|
ref <- newIORef []
|
||||||
|
fptr <- wrapMapItorCallback (getCategories ref)
|
||||||
|
(#poke GuMapItor, fn) itor fptr
|
||||||
|
pgf_iter_categories (pgf p) itor exn
|
||||||
|
freeHaskellFunPtr fptr
|
||||||
|
cs <- readIORef ref
|
||||||
|
return (reverse cs)
|
||||||
|
where
|
||||||
|
getCategories :: IORef [String] -> MapItorCallback
|
||||||
|
getCategories ref itor key value exn = do
|
||||||
|
names <- readIORef ref
|
||||||
|
name <- peekUtf8CString (castPtr key)
|
||||||
|
writeIORef ref $! (name : names)
|
||||||
|
|
||||||
categoryContext :: PGF -> Cat -> Maybe [Hypo]
|
categoryContext :: PGF -> Cat -> Maybe [Hypo]
|
||||||
categoryContext pgf cat = Nothing -- !!! not implemented yet TODO
|
categoryContext pgf cat = Nothing -- !!! not implemented yet TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user