From 14f394c9e93669e829b0d015868bd828572df075 Mon Sep 17 00:00:00 2001 From: krangelov Date: Sat, 7 Dec 2019 22:00:39 +0100 Subject: a version of the parser which returns a chart rather than a list of expressions --- src/runtime/haskell-bind/PGF2/FFI.hsc | 21 +++++++++++++++++++++ src/runtime/haskell-bind/PGF2/Internal.hsc | 7 ------- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src/runtime/haskell-bind/PGF2') diff --git a/src/runtime/haskell-bind/PGF2/FFI.hsc b/src/runtime/haskell-bind/PGF2/FFI.hsc index 713adcecc..673c5c877 100644 --- a/src/runtime/haskell-bind/PGF2/FFI.hsc +++ b/src/runtime/haskell-bind/PGF2/FFI.hsc @@ -6,6 +6,7 @@ module PGF2.FFI where #include #include #include +#include import Foreign ( alloca, peek, poke, peekByteOff ) import Foreign.C @@ -237,6 +238,16 @@ newSequence elem_size pokeElem values pool = do pokeElem ptr x pokeElems (ptr `plusPtr` (fromIntegral elem_size)) xs +type FId = Int +data PArg = PArg [FId] {-# UNPACK #-} !FId deriving (Eq,Ord,Show) + +peekFId :: Ptr a -> IO FId +peekFId c_ccat = do + c_fid <- (#peek PgfCCat, fid) c_ccat + return (fromIntegral (c_fid :: CInt)) + +deRef peekValue ptr = peek ptr >>= peekValue + ------------------------------------------------------------------ -- libpgf API @@ -261,6 +272,7 @@ data PgfAbsCat data PgfCCat data PgfCncFun data PgfProductionApply +data PgfParsing foreign import ccall "pgf/pgf.h pgf_read" pgf_read :: CString -> Ptr GuPool -> Ptr GuExn -> IO (Ptr PgfPGF) @@ -361,6 +373,15 @@ foreign import ccall "wrapper" foreign import ccall "pgf/pgf.h pgf_align_words" pgf_align_words :: Ptr PgfConcr -> PgfExpr -> Ptr GuExn -> Ptr GuPool -> IO (Ptr GuSeq) +foreign import ccall "pgf/pgf.h pgf_parse_to_chart" + pgf_parse_to_chart :: Ptr PgfConcr -> PgfType -> CString -> Double -> Ptr PgfCallbacksMap -> CSizeT -> Ptr GuExn -> Ptr GuPool -> Ptr GuPool -> IO (Ptr PgfParsing) + +foreign import ccall "pgf/pgf.h pgf_get_parse_roots" + pgf_get_parse_roots :: Ptr PgfParsing -> Ptr GuPool -> IO (Ptr GuSeq) + +foreign import ccall "pgf/pgf.h pgf_ccat_to_range" + pgf_ccat_to_range :: Ptr PgfParsing -> Ptr PgfCCat -> Ptr GuPool -> IO (Ptr GuSeq) + foreign import ccall "pgf/pgf.h pgf_parse_with_heuristics" pgf_parse_with_heuristics :: Ptr PgfConcr -> PgfType -> CString -> Double -> Ptr PgfCallbacksMap -> Ptr GuExn -> Ptr GuPool -> Ptr GuPool -> IO (Ptr GuEnum) diff --git a/src/runtime/haskell-bind/PGF2/Internal.hsc b/src/runtime/haskell-bind/PGF2/Internal.hsc index 3cb4199d0..ed894a361 100644 --- a/src/runtime/haskell-bind/PGF2/Internal.hsc +++ b/src/runtime/haskell-bind/PGF2/Internal.hsc @@ -53,7 +53,6 @@ data Production = PApply {-# UNPACK #-} !FunId [PArg] | PCoerce {-# UNPACK #-} !FId deriving (Eq,Ord,Show) -data PArg = PArg [FId] {-# UNPACK #-} !FId deriving (Eq,Ord,Show) type FunId = Int type SeqId = Int data Literal = @@ -186,10 +185,6 @@ concrProductions c fid = unsafePerformIO $ do fid <- peekFId c_ccat return (PArg hypos fid) -peekFId c_ccat = do - c_fid <- (#peek PgfCCat, fid) c_ccat - return (fromIntegral (c_fid :: CInt)) - concrTotalFuns :: Concr -> FunId concrTotalFuns c = unsafePerformIO $ do c_cncfuns <- (#peek PgfConcr, cncfuns) (concr c) @@ -271,8 +266,6 @@ concrSequence c seqid = unsafePerformIO $ do forms <- peekForms (len-1) (ptr `plusPtr` (#size PgfAlternative)) return ((form,prefixes):forms) -deRef peekValue ptr = peek ptr >>= peekValue - fidString, fidInt, fidFloat, fidVar, fidStart :: FId fidString = (-1) fidInt = (-2) -- cgit v1.2.3