mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
cleaned up and documented PGF API
This commit is contained in:
@@ -2,13 +2,17 @@ module PGF.CId (CId(..), wildCId, mkCId, prCId) where
|
||||
|
||||
import Data.ByteString.Char8 as BS
|
||||
|
||||
-- | An abstract data type that represents
|
||||
-- function identifier in PGF.
|
||||
newtype CId = CId BS.ByteString deriving (Eq,Ord,Show)
|
||||
|
||||
wildCId :: CId
|
||||
wildCId = CId (BS.singleton '_')
|
||||
|
||||
-- | Creates a new identifier from 'String'
|
||||
mkCId :: String -> CId
|
||||
mkCId s = CId (BS.pack s)
|
||||
|
||||
-- | Renders the identifier as 'String'
|
||||
prCId :: CId -> String
|
||||
prCId (CId x) = BS.unpack x
|
||||
|
||||
@@ -10,6 +10,8 @@ import Data.Array
|
||||
|
||||
-- internal datatypes for PGF
|
||||
|
||||
-- | An abstract data type representing multilingual grammar
|
||||
-- in Portable Grammar Format.
|
||||
data PGF = PGF {
|
||||
absname :: CId ,
|
||||
cncnames :: [CId] ,
|
||||
|
||||
@@ -28,16 +28,17 @@ import qualified Data.Map as Map
|
||||
|
||||
-- main parsing function
|
||||
|
||||
parseFCF ::
|
||||
String -> -- ^ parsing strategy
|
||||
ParserInfo -> -- ^ compiled grammar (fcfg)
|
||||
CId -> -- ^ starting category
|
||||
[String] -> -- ^ input tokens
|
||||
Err [Exp] -- ^ resulting GF terms
|
||||
parseFCF :: String -- ^ parsing strategy
|
||||
-> ParserInfo -- ^ compiled grammar (fcfg)
|
||||
-> CId -- ^ starting category
|
||||
-> [String] -- ^ input tokens
|
||||
-> Err [Exp] -- ^ resulting GF terms
|
||||
parseFCF strategy pinfo startCat inString =
|
||||
do let inTokens = input inString
|
||||
startCats <- Map.lookup startCat (startupCats pinfo)
|
||||
fcfParser <- {- trace lctree $ -} parseFCF strategy
|
||||
startCats <- case Map.lookup startCat (startupCats pinfo) of
|
||||
Just cats -> return cats
|
||||
Nothing -> fail $ "Unknown startup category: " ++ prCId startCat
|
||||
fcfParser <- parseFCF strategy
|
||||
let chart = fcfParser pinfo startCats inTokens
|
||||
(i,j) = inputBounds inTokens
|
||||
finalEdges = [makeFinalEdge cat i j | cat <- startCats]
|
||||
@@ -46,6 +47,6 @@ parseFCF strategy pinfo startCat inString =
|
||||
return $ nubsort $ filteredForests >>= forest2exps
|
||||
where
|
||||
parseFCF :: String -> Err (FCFParser)
|
||||
parseFCF "bottomup" = Ok $ parse "b"
|
||||
parseFCF "topdown" = Ok $ parse "t"
|
||||
parseFCF strat = Bad $ "FCFG parsing strategy not defined: " ++ strat
|
||||
parseFCF "bottomup" = return $ parse "b"
|
||||
parseFCF "topdown" = return $ parse "t"
|
||||
parseFCF strat = fail $ "FCFG parsing strategy not defined: " ++ strat
|
||||
|
||||
@@ -181,7 +181,6 @@ fromExp e = case e of
|
||||
EMeta _ -> AMet ----
|
||||
EEq eqs ->
|
||||
App "Eq" [App "E" (map fromExp (v:ps)) | Equ ps v <- eqs]
|
||||
_ -> error $ "exp " ++ show e
|
||||
|
||||
fromTerm :: Term -> RExp
|
||||
fromTerm e = case e of
|
||||
|
||||
Reference in New Issue
Block a user