summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Canon/GFC.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
commit055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch)
tree0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-3.0/GF/Canon/GFC.hs
parent915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff)
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-3.0/GF/Canon/GFC.hs')
-rw-r--r--src-3.0/GF/Canon/GFC.hs103
1 files changed, 103 insertions, 0 deletions
diff --git a/src-3.0/GF/Canon/GFC.hs b/src-3.0/GF/Canon/GFC.hs
new file mode 100644
index 000000000..ae9097c44
--- /dev/null
+++ b/src-3.0/GF/Canon/GFC.hs
@@ -0,0 +1,103 @@
+----------------------------------------------------------------------
+-- |
+-- Module : GFC
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date: 2005/04/21 16:21:22 $
+-- > CVS $Author: bringert $
+-- > CVS $Revision: 1.12 $
+--
+-- canonical GF. AR 10\/9\/2002 -- 9\/5\/2003 -- 21\/9
+-----------------------------------------------------------------------------
+
+module GF.Canon.GFC (Context,
+ CanonGrammar,
+ CanonModInfo,
+ CanonModule,
+ CanonAbs,
+ Info(..),
+ Printname,
+ prPrintnamesGrammar,
+ mapInfoTerms,
+ setFlag,
+ flagIncomplete,
+ isIncompleteCanon,
+ hasFlagCanon,
+ flagCanon
+ ) where
+
+import GF.Canon.AbsGFC
+import GF.Canon.PrintGFC
+import qualified GF.Grammar.Abstract as A
+
+import GF.Infra.Ident
+import GF.Infra.Option
+import GF.Data.Zipper
+import GF.Data.Operations
+import qualified GF.Infra.Modules as M
+
+import Data.Char
+import Control.Arrow (first)
+
+type Context = [(Ident,Exp)]
+
+type CanonGrammar = M.MGrammar Ident Flag Info
+
+type CanonModInfo = M.ModInfo Ident Flag Info
+
+type CanonModule = (Ident, CanonModInfo)
+
+type CanonAbs = M.Module Ident Option Info
+
+data Info =
+ AbsCat A.Context [A.Fun]
+ | AbsFun A.Type A.Term
+ | AbsTrans A.Term
+
+ | ResPar [ParDef]
+ | ResOper CType Term -- ^ global constant
+ | CncCat CType Term Printname
+ | CncFun CIdent [ArgVar] Term Printname
+ | AnyInd Bool Ident
+ deriving (Show)
+
+type Printname = Term
+
+mapInfoTerms :: (Term -> Term) -> Info -> Info
+mapInfoTerms f i = case i of
+ ResOper x a -> ResOper x (f a)
+ CncCat x a y -> CncCat x (f a) y
+ CncFun x y a z -> CncFun x y (f a) z
+ _ -> i
+
+setFlag :: String -> String -> [Flag] -> [Flag]
+setFlag n v fs = flagCanon n v : [f | f@(Flg (IC n') _) <- fs, n' /= n]
+
+flagIncomplete :: Flag
+flagIncomplete = flagCanon "incomplete" "true"
+
+isIncompleteCanon :: CanonModule -> Bool
+isIncompleteCanon = hasFlagCanon flagIncomplete
+
+hasFlagCanon :: Flag -> CanonModule -> Bool
+hasFlagCanon f (_,M.ModMod mo) = elem f $ M.flags mo
+hasFlagCanon f _ = True ---- safe, useless
+
+flagCanon :: String -> String -> Flag
+flagCanon f v = Flg (identC f) (identC v)
+
+-- for Ha-Jo 20/2/2005
+
+prPrintnamesGrammar :: CanonGrammar -> String
+prPrintnamesGrammar gr = unlines $ filter (not . null) [prPrint j |
+ (_,M.ModMod m) <- M.modules gr,
+ M.isModCnc m,
+ j <- tree2list $ M.jments m
+ ]
+ where
+ prPrint j = case j of
+ (c,CncCat _ _ p) -> "printname cat" +++ A.prt_ c +++ "=" +++ A.prt_ p
+ (c,CncFun _ _ _ p) -> "printname fun" +++ A.prt_ c +++ "=" +++ A.prt_ p
+ _ -> []