mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-13 05:02:50 -06:00
fast word completion for functions names in the shell
This commit is contained in:
@@ -24,7 +24,7 @@ module PGF2 (-- * PGF
|
||||
Cat,categories,categoryContext,categoryProbability,
|
||||
|
||||
-- ** Functions
|
||||
Fun, functions, functionsByCat,
|
||||
Fun, functions, functionsByPrefix, functionsByCat,
|
||||
functionType, functionIsConstructor, functionProbability,
|
||||
|
||||
-- ** Expressions
|
||||
@@ -1094,6 +1094,26 @@ functions p =
|
||||
name <- peekText key
|
||||
writeIORef ref $ (name : names)
|
||||
|
||||
-- | List of all functions whose names start with a given prefix
|
||||
functionsByPrefix :: PGF -> String -> [Fun]
|
||||
functionsByPrefix p prefix =
|
||||
unsafePerformIO $ do
|
||||
ref <- newIORef []
|
||||
(withText prefix $ \c_prefix ->
|
||||
allocaBytes (#size PgfItor) $ \itor ->
|
||||
bracket (wrapItorCallback (getFunctions ref)) freeHaskellFunPtr $ \fptr ->
|
||||
withForeignPtr (a_revision p) $ \c_revision -> do
|
||||
(#poke PgfItor, fn) itor fptr
|
||||
withPgfExn "functions" (pgf_iter_functions_by_prefix (a_db p) c_revision c_prefix itor)
|
||||
fs <- readIORef ref
|
||||
return (reverse fs))
|
||||
where
|
||||
getFunctions :: IORef [String] -> ItorCallback
|
||||
getFunctions ref itor key _ exn = do
|
||||
names <- readIORef ref
|
||||
name <- peekText key
|
||||
writeIORef ref $ (name : names)
|
||||
|
||||
-- | List of all functions defined in the abstract syntax
|
||||
functionsByCat :: PGF -> Cat -> [Fun]
|
||||
functionsByCat p cat =
|
||||
|
||||
@@ -173,6 +173,8 @@ foreign import ccall pgf_category_prob :: Ptr PgfDB -> Ptr PGF -> Ptr PgfText ->
|
||||
|
||||
foreign import ccall pgf_iter_functions :: Ptr PgfDB -> Ptr PGF -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||
|
||||
foreign import ccall pgf_iter_functions_by_prefix :: Ptr PgfDB -> Ptr PGF -> Ptr PgfText -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||
|
||||
foreign import ccall pgf_iter_functions_by_cat :: Ptr PgfDB -> Ptr PGF -> Ptr PgfText -> Ptr PgfItor -> Ptr PgfExn -> IO ()
|
||||
|
||||
foreign import ccall pgf_function_type :: Ptr PgfDB -> Ptr PGF -> Ptr PgfText -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO (StablePtr Type)
|
||||
|
||||
Reference in New Issue
Block a user