mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 00:22:51 -06:00
implemented readExpr & readType
This commit is contained in:
@@ -25,8 +25,10 @@ module PGF2 (-- * PGF
|
||||
functionType,
|
||||
-- ** Expressions
|
||||
Expr(..), Literal(..),
|
||||
readExpr,
|
||||
-- ** Types
|
||||
Type(..), Hypo, BindType(..),
|
||||
readType,
|
||||
-- * Concrete syntax
|
||||
ConcName
|
||||
) where
|
||||
@@ -200,6 +202,33 @@ functionsByCat p cat =
|
||||
name <- peekText key
|
||||
writeIORef ref $ (name : names)
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Expressions & types
|
||||
|
||||
-- | parses a 'String' as an expression
|
||||
readExpr :: String -> Maybe Expr
|
||||
readExpr str =
|
||||
unsafePerformIO $
|
||||
withText str $ \c_str ->
|
||||
bracket mkUnmarshaller freeUnmarshaller $ \u -> do
|
||||
c_expr <- pgf_read_expr c_str u
|
||||
if c_expr == castPtrToStablePtr nullPtr
|
||||
then return Nothing
|
||||
else do expr <- deRefStablePtr c_expr
|
||||
return (Just expr)
|
||||
|
||||
-- | parses a 'String' as a type
|
||||
readType :: String -> Maybe Type
|
||||
readType str =
|
||||
unsafePerformIO $
|
||||
withText str $ \c_str ->
|
||||
bracket mkUnmarshaller freeUnmarshaller $ \u -> do
|
||||
c_type <- pgf_read_type c_str u
|
||||
if c_type == castPtrToStablePtr nullPtr
|
||||
then return Nothing
|
||||
else do tp <- deRefStablePtr c_type
|
||||
return (Just tp)
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Exceptions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user