mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-13 06:49:31 -06:00
This changes lots of stuff, let me know if it broke anything. Comments: - We use a local hacked version of GetOpt that allows long forms of commands to start with a single dash. This breaks other parts of GetOpt. For example, arguments to short options now require a =, and does not allo pace after the option character. - The new command parsing is currently only used for the program command line, pragmas and the arguments for the 'i' shell command. - I made a quick hack for the options for showTerm, which currently makes it impossible to use the print style flags for cc. This will be replaced by a facility for parsing command-specific options. - The verbosity handling is broken in some places. I will fix that in a later patch.
68 lines
1.6 KiB
Haskell
68 lines
1.6 KiB
Haskell
module GF.Grammar.API (
|
|
Grammar,
|
|
emptyGrammar,
|
|
pTerm,
|
|
prTerm,
|
|
checkTerm,
|
|
computeTerm,
|
|
showTerm,
|
|
TermPrintStyle(..)
|
|
) 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)
|
|
|