summaryrefslogtreecommitdiff
path: root/src/runtime/haskell-bind/PGF2.hsc
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-09-10 14:35:54 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-09-10 14:35:54 +0000
commitb553729f37043b7b1e4d7528ea81d0c8e8e99286 (patch)
treed044a92dd936cf9f6a9616e1269382a308ed6401 /src/runtime/haskell-bind/PGF2.hsc
parent566aeb93f51a9a4aba72c93baaca593589731ce3 (diff)
added loadConcr/unloadConcr to the Haskell binding. This exposes an API for loading grammars compiled with -split-pgf
Diffstat (limited to 'src/runtime/haskell-bind/PGF2.hsc')
-rw-r--r--src/runtime/haskell-bind/PGF2.hsc24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc
index f6bfce25e..35631cd4c 100644
--- a/src/runtime/haskell-bind/PGF2.hsc
+++ b/src/runtime/haskell-bind/PGF2.hsc
@@ -14,6 +14,7 @@
module PGF2 (-- * PGF
PGF,readPGF,abstractName,startCat,
+ loadConcr,unloadConcr,
-- * Concrete syntax
Concr,languages,parse,linearize,
-- * Trees
@@ -102,7 +103,28 @@ abstractName p = unsafePerformIO (peekCString =<< pgf_abstract_name (pgf p))
startCat :: PGF -> String
startCat p = unsafePerformIO (peekCString =<< pgf_start_cat (pgf p))
-
+
+loadConcr :: Concr -> FilePath -> IO ()
+loadConcr c fpath =
+ withCString fpath $ \c_fpath ->
+ withCString "rb" $ \c_mode ->
+ withGuPool $ \tmpPl -> do
+ file <- fopen c_fpath c_mode
+ inp <- gu_file_in file tmpPl
+ exn <- gu_new_exn nullPtr gu_type__type tmpPl
+ pgf_concrete_load (concr c) inp exn
+ failed <- gu_exn_is_raised exn
+ if failed
+ then do ty <- gu_exn_caught exn
+ if ty == gu_type__GuErrno
+ then do perrno <- (#peek GuExn, data.data) exn
+ errno <- peek perrno
+ ioError (errnoToIOError "loadConcr" (Errno errno) Nothing (Just fpath))
+ else do throwIO (PGFError "The language cannot be loaded")
+ else return ()
+
+unloadConcr :: Concr -> IO ()
+unloadConcr c = pgf_concrete_unload (concr c)
-----------------------------------------------------------------------------
-- Expressions