From 121c247d1511a967bd69e569168b87b06cb6b128 Mon Sep 17 00:00:00 2001 From: aarne Date: Thu, 20 Sep 2007 21:51:54 +0000 Subject: [PATCH] compact printing of gf files --- src/GF/Compile/Compile.hs | 3 ++- src/GF/Infra/CompactPrint.hs | 11 +++++++++++ src/GF/Source/GrammarToSource.hs | 9 ++++++++- src/GF/Source/SourceToGrammar.hs | 8 ++++++++ src/Makefile | 5 +++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/GF/Infra/CompactPrint.hs diff --git a/src/GF/Compile/Compile.hs b/src/GF/Compile/Compile.hs index 00b89ec59..d78d49b09 100644 --- a/src/GF/Compile/Compile.hs +++ b/src/GF/Compile/Compile.hs @@ -19,6 +19,7 @@ module GF.Compile.Compile (compileModule, compileEnvShSt, compileOne, import GF.Grammar.Grammar import GF.Infra.Ident import GF.Infra.Option +import GF.Infra.CompactPrint import GF.Grammar.PrGrammar import GF.Compile.Update import GF.Grammar.Lookup @@ -331,7 +332,7 @@ generateModuleCode opts path minfo@(name,info) = do let rminfo = if isCompilable info then minfo else (name, ModMod emptyModule) let (file,out) = (gfrFile pname, prGrammar (MGrammar [rminfo])) - putp (" wrote file" +++ file) $ ioeIO $ writeFile file out + putp (" wrote file" +++ file) $ ioeIO $ writeFile file $ compactPrint out _ -> return () (file,out) <- do code <- return $ MkGFC.prCanonModInfo minfo' diff --git a/src/GF/Infra/CompactPrint.hs b/src/GF/Infra/CompactPrint.hs new file mode 100644 index 000000000..eb8be2292 --- /dev/null +++ b/src/GF/Infra/CompactPrint.hs @@ -0,0 +1,11 @@ +module GF.Infra.CompactPrint where +import Data.Char + +compactPrint = concat . map spaceIf . words + +spaceIf w = case w of + _ | keyword w -> "\n" ++ w + c:cs | isAlpha c || isDigit c -> " " ++ w + _ -> w + +keyword w = elem w ["cat","fun","lin","lincat","oper","param"] diff --git a/src/GF/Source/GrammarToSource.hs b/src/GF/Source/GrammarToSource.hs index 74c98b1bc..21382c7bd 100644 --- a/src/GF/Source/GrammarToSource.hs +++ b/src/GF/Source/GrammarToSource.hs @@ -107,8 +107,15 @@ trAnyDef (i,info) = let i' = tri i in case info of CncFun _ ptr ppr -> [P.DefLin [trDef i' nope ptr]] ---- P.DefPrintFun [P.PrintDef i' (trt pr)]] +{- + ---- encoding of AnyInd without changing syntax. AR 20/9/2007 + AnyInd s b -> + [P.DefOper [P.DDef [mkName i] + (P.EApp (P.EInt (if s then 1 else 0)) (P.EIdent (tri b)))]] +-} _ -> [] + trDef :: Ident -> Perh Type -> Perh Term -> P.Def trDef i pty ptr = case (pty,ptr) of (Nope, Nope) -> P.DDef [mkName i] (P.EMeta) --- @@ -243,4 +250,4 @@ trLabelIdent i = identC $ case i of LVar i -> "v" ++ show i --- should not happen mkName :: Ident -> P.Name -mkName = P.IdentName \ No newline at end of file +mkName = P.IdentName diff --git a/src/GF/Source/SourceToGrammar.hs b/src/GF/Source/SourceToGrammar.hs index 28cb9025b..8435540e4 100644 --- a/src/GF/Source/SourceToGrammar.hs +++ b/src/GF/Source/SourceToGrammar.hs @@ -305,6 +305,14 @@ transResDef x = case x of | (p,pars) <- pardefs'] ++ [(f, G.ResValue (yes (M.mkProdSimple co (G.Cn p),Nothing))) | (p,pars) <- pardefs', (f,co) <- pars] + +{- + ---- encoding of AnyInd without changing syntax. AR 20/9/2007 + DefOper [DDef [c] (EApp (EInt status) (EIdent mo))] -> do + c' <- transName c + mo' <- transIdent mo + return $ Left [(c',G.AnyInd (status==1) mo')] +-} DefOper defs -> do defs' <- liftM concat $ mapM getDefs defs returnl $ concatMap mkOverload [(f, G.ResOper pt pe) | (f,(pt,pe)) <- defs'] diff --git a/src/Makefile b/src/Makefile index 35bd35fae..83b8e9561 100644 --- a/src/Makefile +++ b/src/Makefile @@ -191,6 +191,11 @@ gfdoc: tools/$(GF_DOC_EXE) tools/$(GF_DOC_EXE): tools/GFDoc.hs $(GHMAKE) $(GHCOPTFLAGS) -o $@ $^ +gfc: + $(GHMAKE) $(GHCOPTFLAGS) -o gfc GF/Devel/GFC.hs + strip gfc + mv gfc ../bin/ + gfcc: $(GHMAKE) $(GHCOPTFLAGS) -o gfcc GF/Canon/GFCC/Shell.hs strip gfcc