FCat is just a plain integer now

This commit is contained in:
kr.angelov
2007-10-12 16:00:37 +00:00
parent 2a382c427c
commit 6bc3dc45b6
6 changed files with 125 additions and 126 deletions

View File

@@ -14,11 +14,9 @@ module GF.Formalism.FCFG
-- * Category
, FPath
, FCat(..)
, FCat
, initialFCat
, fcatString, fcatInt, fcatFloat
, fcat2cid
-- * Symbol
, FIndex
@@ -37,6 +35,7 @@ module GF.Formalism.FCFG
import Control.Monad (liftM)
import Data.List (groupBy)
import Data.Array
import qualified Data.Map as Map
import GF.Formalism.Utilities
import qualified GF.GFCC.AbsGFCC as AbsGFCC
@@ -51,30 +50,18 @@ type FToken = String
------------------------------------------------------------
-- Category
type FPath = [FIndex]
data FCat = FCat {-# UNPACK #-} !Int AbsGFCC.CId [FPath] [(FPath,FIndex)]
initialFCat :: AbsGFCC.CId -> FCat
initialFCat cat = FCat 0 cat [] []
fcatString = FCat (-1) (AbsGFCC.CId "String") [[0]] []
fcatInt = FCat (-2) (AbsGFCC.CId "Int") [[0]] []
fcatFloat = FCat (-3) (AbsGFCC.CId "Float") [[0]] []
fcat2cid :: FCat -> AbsGFCC.CId
fcat2cid (FCat _ c _ _) = c
instance Eq FCat where
(FCat id1 _ _ _) == (FCat id2 _ _ _) = id1 == id2
instance Ord FCat where
compare (FCat id1 _ _ _) (FCat id2 _ _ _) = compare id1 id2
type FCat = Int
fcatString, fcatInt, fcatFloat :: Int
fcatString = (-1)
fcatInt = (-2)
fcatFloat = (-3)
------------------------------------------------------------
-- Symbol
type FIndex = Int
data FSymbol
= FSymCat FCat {-# UNPACK #-} !FIndex {-# UNPACK #-} !Int
= FSymCat {-# UNPACK #-} !FCat {-# UNPACK #-} !FIndex {-# UNPACK #-} !Int
| FSymTok FToken
@@ -89,10 +76,10 @@ isCoercionF _ = False
------------------------------------------------------------
-- Grammar
type FGrammar = [FRule]
type FPointPos = Int
data FRule = FRule FName [FCat] FCat (Array FIndex (Array FPointPos FSymbol))
type FPointPos = Int
type FGrammar = ([FRule], Map.Map AbsGFCC.CId [FCat])
data FRule = FRule FName [FCat] FCat (Array FIndex (Array FPointPos FSymbol))
------------------------------------------------------------
-- pretty-printing
@@ -100,12 +87,6 @@ data FRule = FRule FName [FCat] FCat (Array FIndex (Array FPointPos FSymbol)
instance Print AbsGFCC.CId where
prt (AbsGFCC.CId s) = s
instance Print FCat where
prt (FCat _ (AbsGFCC.CId cat) rcs tcs) = cat ++ "{" ++
prtSep ";" ([prt path | path <- rcs] ++
[prt path ++ "=" ++ prt term | (path,term) <- tcs])
++ "}"
instance Print FSymbol where
prt (FSymCat c l n) = "($" ++ prt n ++ "!" ++ prt l ++ ")"
prt (FSymTok t) = simpleShow (prt t)