1
0
forked from GitHub/gf-core

started source grammar API ; used it for a first implem. of cc command

This commit is contained in:
aarne
2008-05-24 16:13:27 +00:00
parent f1fd6260e0
commit 6d0adbb2cb
3 changed files with 63 additions and 5 deletions

52
src-3.0/GF/Grammar/API.hs Normal file
View File

@@ -0,0 +1,52 @@
module GF.Grammar.API (
Grammar,
emptyGrammar,
pTerm,
prTerm,
checkTerm,
computeTerm
) where
import GF.Source.ParGF
import GF.Source.SourceToGrammar (transExp)
import GF.Grammar.Grammar
import GF.Infra.Ident
import GF.Infra.Modules (greatestResource)
import GF.Compile.GetGrammar
import GF.Grammar.Macros
import GF.Grammar.PrGrammar
import GF.Compile.Rename (renameSourceTerm)
import GF.Compile.CheckGrammar (justCheckLTerm)
import GF.Compile.Compute (computeConcreteRec)
import GF.Data.Operations
import qualified Data.ByteString.Char8 as BS
type Grammar = SourceGrammar
emptyGrammar :: Grammar
emptyGrammar = emptySourceGrammar
pTerm :: String -> Err Term
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
checkTermAny gr mo t
checkTermAny :: Grammar -> Ident -> Term -> Err Term
checkTermAny gr m t = do
t1 <- renameSourceTerm gr m t
justCheckLTerm gr t1
computeTerm :: Grammar -> Term -> Err Term
computeTerm = computeConcreteRec