compact printing of gf files

This commit is contained in:
aarne
2007-09-20 21:51:54 +00:00
parent 46013f103c
commit 6e4104ffa9
5 changed files with 34 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ module GF.Compile.Compile (compileModule, compileEnvShSt, compileOne,
import GF.Grammar.Grammar import GF.Grammar.Grammar
import GF.Infra.Ident import GF.Infra.Ident
import GF.Infra.Option import GF.Infra.Option
import GF.Infra.CompactPrint
import GF.Grammar.PrGrammar import GF.Grammar.PrGrammar
import GF.Compile.Update import GF.Compile.Update
import GF.Grammar.Lookup import GF.Grammar.Lookup
@@ -331,7 +332,7 @@ generateModuleCode opts path minfo@(name,info) = do
let rminfo = if isCompilable info then minfo let rminfo = if isCompilable info then minfo
else (name, ModMod emptyModule) else (name, ModMod emptyModule)
let (file,out) = (gfrFile pname, prGrammar (MGrammar [rminfo])) 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 () _ -> return ()
(file,out) <- do (file,out) <- do
code <- return $ MkGFC.prCanonModInfo minfo' code <- return $ MkGFC.prCanonModInfo minfo'

View File

@@ -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"]

View File

@@ -107,8 +107,15 @@ trAnyDef (i,info) = let i' = tri i in case info of
CncFun _ ptr ppr -> CncFun _ ptr ppr ->
[P.DefLin [trDef i' nope ptr]] [P.DefLin [trDef i' nope ptr]]
---- P.DefPrintFun [P.PrintDef i' (trt pr)]] ---- 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 :: Ident -> Perh Type -> Perh Term -> P.Def
trDef i pty ptr = case (pty,ptr) of trDef i pty ptr = case (pty,ptr) of
(Nope, Nope) -> P.DDef [mkName i] (P.EMeta) --- (Nope, Nope) -> P.DDef [mkName i] (P.EMeta) ---

View File

@@ -305,6 +305,14 @@ transResDef x = case x of
| (p,pars) <- pardefs'] | (p,pars) <- pardefs']
++ [(f, G.ResValue (yes (M.mkProdSimple co (G.Cn p),Nothing))) | ++ [(f, G.ResValue (yes (M.mkProdSimple co (G.Cn p),Nothing))) |
(p,pars) <- pardefs', (f,co) <- pars] (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 DefOper defs -> do
defs' <- liftM concat $ mapM getDefs defs defs' <- liftM concat $ mapM getDefs defs
returnl $ concatMap mkOverload [(f, G.ResOper pt pe) | (f,(pt,pe)) <- defs'] returnl $ concatMap mkOverload [(f, G.ResOper pt pe) | (f,(pt,pe)) <- defs']

View File

@@ -191,6 +191,11 @@ gfdoc: tools/$(GF_DOC_EXE)
tools/$(GF_DOC_EXE): tools/GFDoc.hs tools/$(GF_DOC_EXE): tools/GFDoc.hs
$(GHMAKE) $(GHCOPTFLAGS) -o $@ $^ $(GHMAKE) $(GHCOPTFLAGS) -o $@ $^
gfc:
$(GHMAKE) $(GHCOPTFLAGS) -o gfc GF/Devel/GFC.hs
strip gfc
mv gfc ../bin/
gfcc: gfcc:
$(GHMAKE) $(GHCOPTFLAGS) -o gfcc GF/Canon/GFCC/Shell.hs $(GHMAKE) $(GHCOPTFLAGS) -o gfcc GF/Canon/GFCC/Shell.hs
strip gfcc strip gfcc