forked from GitHub/gf-core
printing options for source GF terms defined in API and used in cc command
This commit is contained in:
@@ -4,7 +4,8 @@ module GF.Grammar.API (
|
|||||||
pTerm,
|
pTerm,
|
||||||
prTerm,
|
prTerm,
|
||||||
checkTerm,
|
checkTerm,
|
||||||
computeTerm
|
computeTerm,
|
||||||
|
showTerm
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Source.ParGF
|
import GF.Source.ParGF
|
||||||
@@ -21,6 +22,8 @@ import GF.Compile.CheckGrammar (justCheckLTerm)
|
|||||||
import GF.Compile.Compute (computeConcrete)
|
import GF.Compile.Compute (computeConcrete)
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
|
import GF.Infra.Option
|
||||||
|
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
|
|
||||||
type Grammar = SourceGrammar
|
type Grammar = SourceGrammar
|
||||||
@@ -49,3 +52,9 @@ checkTermAny gr m t = do
|
|||||||
computeTerm :: Grammar -> Term -> Err Term
|
computeTerm :: Grammar -> Term -> Err Term
|
||||||
computeTerm = computeConcrete
|
computeTerm = computeConcrete
|
||||||
|
|
||||||
|
showTerm :: Options -> Term -> String
|
||||||
|
showTerm opts t
|
||||||
|
| oElem (iOpt "table") opts = unlines [p +++ s | (p,s) <- prTermTabular t]
|
||||||
|
| oElem (iOpt "all") opts = unlines [ s | (p,s) <- prTermTabular t]
|
||||||
|
| oElem (iOpt "unqual") opts = prt_ t
|
||||||
|
| otherwise = prt t
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ module GF.Grammar.PrGrammar (Print(..),
|
|||||||
prConstrs, prConstraints,
|
prConstrs, prConstraints,
|
||||||
prMetaSubst, prEnv, prMSubst,
|
prMetaSubst, prEnv, prMSubst,
|
||||||
prExp, prOperSignature,
|
prExp, prOperSignature,
|
||||||
lookupIdent, lookupIdentInfo
|
lookupIdent, lookupIdentInfo,
|
||||||
|
prTermTabular
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
@@ -89,6 +90,12 @@ instance Print Ident where
|
|||||||
|
|
||||||
instance Print Patt where
|
instance Print Patt where
|
||||||
prt = pprintTree . trp
|
prt = pprintTree . trp
|
||||||
|
prt_ = prt . unqual where
|
||||||
|
unqual p = case p of
|
||||||
|
PP _ c [] -> PV c --- to remove curlies
|
||||||
|
PP _ c ps -> PC c (map unqual ps)
|
||||||
|
PC c ps -> PC c (map unqual ps)
|
||||||
|
_ -> p ---- records
|
||||||
|
|
||||||
instance Print Label where
|
instance Print Label where
|
||||||
prt = pprintTree . trLabel
|
prt = pprintTree . trLabel
|
||||||
@@ -247,3 +254,20 @@ lookupIdent c t = case lookupTree prt c t of
|
|||||||
|
|
||||||
lookupIdentInfo :: Module Ident a -> Ident -> Err a
|
lookupIdentInfo :: Module Ident a -> Ident -> Err a
|
||||||
lookupIdentInfo mo i = lookupIdent i (jments mo)
|
lookupIdentInfo mo i = lookupIdent i (jments mo)
|
||||||
|
|
||||||
|
|
||||||
|
--- printing cc command output AR 26/5/2008
|
||||||
|
|
||||||
|
prTermTabular :: Term -> [(String,String)]
|
||||||
|
prTermTabular = pr where
|
||||||
|
pr t = case t of
|
||||||
|
R rs ->
|
||||||
|
[(prt_ lab +++ "." +++ path, str) | (lab,(_,val)) <- rs, (path,str) <- pr val]
|
||||||
|
T _ cs ->
|
||||||
|
[(prt_ lab +++"=>" +++ path, str) | (lab, val) <- cs, (path,str) <- pr val]
|
||||||
|
_ -> [([],ps t)]
|
||||||
|
ps t = case t of
|
||||||
|
K s -> s
|
||||||
|
C s u -> ps s +++ ps u
|
||||||
|
FV ts -> unwords (intersperse "/" (map ps ts))
|
||||||
|
_ -> prt_ t
|
||||||
|
|||||||
@@ -34,8 +34,9 @@ loop gfenv0 = do
|
|||||||
|
|
||||||
-- special commands, requiring source grammar in env
|
-- special commands, requiring source grammar in env
|
||||||
"cc":ws -> do
|
"cc":ws -> do
|
||||||
let t = pTerm (unwords ws) >>= checkTerm sgr >>= computeTerm sgr
|
let (opts,term) = getOptions "-" ws
|
||||||
err putStrLn (putStrLn . prTerm) t ---- make pipable
|
let t = pTerm (unwords term) >>= checkTerm sgr >>= computeTerm sgr
|
||||||
|
err putStrLn (putStrLn . showTerm opts) t ---- make pipable
|
||||||
loopNewCPU gfenv
|
loopNewCPU gfenv
|
||||||
|
|
||||||
"i":args -> do
|
"i":args -> do
|
||||||
|
|||||||
Reference in New Issue
Block a user