qualified/unqualified mode for GF.Grammar.Printer. Used in the "cc" command

This commit is contained in:
krasimir
2009-03-04 13:41:33 +00:00
parent ed6c31f3ef
commit 7babfd1da6
5 changed files with 180 additions and 161 deletions
+14 -25
View File
@@ -2,12 +2,11 @@ module GF.Grammar.API (
Grammar,
emptyGrammar,
pTerm,
prTerm,
ppTerm,
checkTerm,
computeTerm,
showTerm,
TermPrintStyle(..),
pTermPrintStyle
TermPrintStyle(..), TermPrintQual(..),
) where
import GF.Source.ParGF
@@ -17,7 +16,7 @@ import GF.Infra.Ident
import GF.Infra.Modules (greatestResource)
import GF.Compile.GetGrammar
import GF.Grammar.Macros
import GF.Grammar.PrGrammar
import GF.Grammar.Printer
import GF.Compile.Rename (renameSourceTerm)
import GF.Compile.CheckGrammar (justCheckLTerm)
@@ -27,6 +26,7 @@ import GF.Data.Operations
import GF.Infra.Option
import qualified Data.ByteString.Char8 as BS
import Text.PrettyPrint
type Grammar = SourceGrammar
@@ -38,9 +38,6 @@ pTerm s = do
e <- pExp $ myLexer (BS.pack s)
transExp e
prTerm :: Term -> String
prTerm = prt
checkTerm :: Grammar -> Term -> Err Term
checkTerm gr t = do
mo <- maybe (Bad "no source grammar in scope") return $ greatestResource gr
@@ -54,22 +51,14 @@ checkTermAny gr m t = do
computeTerm :: Grammar -> Term -> Err Term
computeTerm = computeConcrete
showTerm :: TermPrintStyle -> Term -> String
showTerm style t =
case style of
TermPrintTable -> unlines [p +++ s | (p,s) <- prTermTabular t]
TermPrintAll -> unlines [ s | (p,s) <- prTermTabular t]
TermPrintUnqual -> prt_ t
TermPrintDefault -> prt t
data TermPrintStyle = TermPrintTable | TermPrintAll | TermPrintUnqual | TermPrintDefault
deriving (Show,Eq)
pTermPrintStyle s = case s of
"table" -> TermPrintTable
"all" -> TermPrintAll
"unqual" -> TermPrintUnqual
_ -> TermPrintDefault
showTerm :: TermPrintStyle -> TermPrintQual -> Term -> String
showTerm style q t = render $
case style of
TermPrintTable -> vcat [p <+> s | (p,s) <- ppTermTabular q t]
TermPrintAll -> vcat [ s | (p,s) <- ppTermTabular q t]
TermPrintDefault -> ppTerm q 0 t
data TermPrintStyle
= TermPrintTable
| TermPrintAll
| TermPrintDefault