diff options
| author | krasimir <krasimir@chalmers.se> | 2009-03-04 13:41:33 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2009-03-04 13:41:33 +0000 |
| commit | 7babfd1da6808f65ae6369aef0dc246857822357 (patch) | |
| tree | 6693dc32ca5cd9fafc2172cb6c010593ca4d6534 /src/GF/Grammar/API.hs | |
| parent | ed6c31f3ef510a8fdc687ec8761aec0e18216096 (diff) | |
qualified/unqualified mode for GF.Grammar.Printer. Used in the "cc" command
Diffstat (limited to 'src/GF/Grammar/API.hs')
| -rw-r--r-- | src/GF/Grammar/API.hs | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/GF/Grammar/API.hs b/src/GF/Grammar/API.hs index 182b5e94e..76508d963 100644 --- a/src/GF/Grammar/API.hs +++ b/src/GF/Grammar/API.hs @@ -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 |
