diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-05-24 16:13:27 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-05-24 16:13:27 +0000 |
| commit | 68903bb25155978b6da22b1f6bd7069621c7dc30 (patch) | |
| tree | ff14e9dc5a13add6ae03c82f993ecdc81c6ed79c /src-3.0/GF/Grammar/API.hs | |
| parent | 0db611a9abfb31c76933a455da946cf2194ded7b (diff) | |
started source grammar API ; used it for a first implem. of cc command
Diffstat (limited to 'src-3.0/GF/Grammar/API.hs')
| -rw-r--r-- | src-3.0/GF/Grammar/API.hs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src-3.0/GF/Grammar/API.hs b/src-3.0/GF/Grammar/API.hs new file mode 100644 index 000000000..be8094228 --- /dev/null +++ b/src-3.0/GF/Grammar/API.hs @@ -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 + + |
