summaryrefslogtreecommitdiff
path: root/src/GF/Grammar/API.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-25 16:54:35 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-25 16:54:35 +0000
commite9e80fc389365e24d4300d7d5390c7d833a96c50 (patch)
treef0b58473adaa670bd8fc52ada419d8cad470ee03 /src/GF/Grammar/API.hs
parentb96b36f43de3e2f8b58d5f539daa6f6d47f25870 (diff)
changed names of resource-1.3; added a note on homepage on release
Diffstat (limited to 'src/GF/Grammar/API.hs')
-rw-r--r--src/GF/Grammar/API.hs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/GF/Grammar/API.hs b/src/GF/Grammar/API.hs
new file mode 100644
index 000000000..182b5e94e
--- /dev/null
+++ b/src/GF/Grammar/API.hs
@@ -0,0 +1,75 @@
+module GF.Grammar.API (
+ Grammar,
+ emptyGrammar,
+ pTerm,
+ prTerm,
+ checkTerm,
+ computeTerm,
+ showTerm,
+ TermPrintStyle(..),
+ pTermPrintStyle
+ ) 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 (computeConcrete)
+
+import GF.Data.Operations
+import GF.Infra.Option
+
+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 = 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
+
+