added function abstractName from the API

This commit is contained in:
krangelov
2021-08-05 19:30:05 +02:00
parent 75e19bbffa
commit 217e0d8cc6
6 changed files with 101 additions and 7 deletions

View File

@@ -14,10 +14,17 @@
-------------------------------------------------
module PGF2 (-- * PGF
PGF,readPGF
PGF,readPGF,
-- * Abstract syntax
AbsName,abstractName,
-- * Concrete syntax
ConcName
) where
import Control.Exception(Exception,throwIO,mask_)
import Control.Exception(Exception,throwIO,mask_,bracket)
import System.IO.Unsafe(unsafePerformIO)
import PGF2.FFI
import Foreign
@@ -27,6 +34,9 @@ import qualified Data.Map as Map
#include <pgf.h>
type AbsName = String -- ^ Name of abstract syntax
type ConcName = String -- ^ Name of concrete syntax
readPGF :: FilePath -> IO PGF
readPGF fpath =
withCString fpath $ \c_fpath ->
@@ -45,6 +55,15 @@ readPGF fpath =
free c_msg
throwIO (PGFError msg)
-- | The abstract language name is the name of the top-level
-- abstract module
abstractName :: PGF -> AbsName
abstractName p =
unsafePerformIO $
withForeignPtr (a_pgf p) $ \c_pgf ->
bracket (pgf_abstract_name c_pgf) free $ \c_text ->
peekText c_text
-----------------------------------------------------------------------
-- Exceptions