diff options
| author | krasimir <krasimir@chalmers.se> | 2009-06-04 16:26:52 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2009-06-04 16:26:52 +0000 |
| commit | f2a968b6d53ac07df67f393bd06c38f368d08c02 (patch) | |
| tree | 6cf785bcb1807de93f10452b11b0dd306157ec70 /src/morpho-server/MorphoServer.hs | |
| parent | 6a263f05aa8d963f7141aca8b7ee0cae0c063515 (diff) | |
the morpho server is now updated and works with the current GF. the sources are moved in directory server
Diffstat (limited to 'src/morpho-server/MorphoServer.hs')
| -rw-r--r-- | src/morpho-server/MorphoServer.hs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/morpho-server/MorphoServer.hs b/src/morpho-server/MorphoServer.hs deleted file mode 100644 index fcaa96197..000000000 --- a/src/morpho-server/MorphoServer.hs +++ /dev/null @@ -1,74 +0,0 @@ -import GF.Compile -import GF.Data.Operations -import GF.Grammar.API -import GF.Grammar.Grammar (Term) -import GF.Grammar.PrGrammar (prTermTabular) -import GF.Infra.Option -import GF.Infra.UseIO -import GF.Text.UTF8 - -import Network.FastCGI -import Text.JSON -import qualified Codec.Binary.UTF8.String as UTF8 (encodeString) - -import Control.Monad -import System.Environment -import System.FilePath - -import FastCGIUtils -import URLEncoding - --- FIXME !!!!!! -grammarFile :: IO FilePath -grammarFile = return "/Users/bringert/Projects/gf/lib/alltenses/ParadigmsFin.gfo" - -grammarPath :: FilePath -grammarPath = "/Users/bringert/Projects/gf/lib/prelude" - -main :: IO () -main = do initFastCGI - r <- newDataRef - loopFastCGI (handleErrors (handleCGIErrors (fcgiMain r))) - -fcgiMain :: DataRef Grammar -> CGI CGIResult -fcgiMain ref = liftIO grammarFile >>= getData readGrammar ref >>= cgiMain - -readGrammar :: FilePath -> CGI Grammar -readGrammar file = - do let opts = concatOptions [modifyFlags $ \fs -> fs { optVerbosity = Quiet }, - modifyModuleFlags $ \fs -> fs { optLibraryPath = [grammarPath] }] - mgr <- liftIO $ appIOE $ batchCompile opts [file] - err (throwCGIError 500 "Grammar loading error" . (:[])) return mgr - -cgiMain :: Grammar -> CGI CGIResult -cgiMain sgr = - do path <- pathInfo - json <- case path of - "/eval" -> do mjson <- return (doEval sgr) `ap` getTerm - err (throwCGIError 400 "Evaluation error" . (:[])) return mjson - _ -> throwCGIError 404 "Not Found" ["Resource not found: " ++ path] - outputJSON json - where - getTerm :: CGI String - getTerm = do mt <- getInput "term" - maybe (throwCGIError 400 "No term given" ["No term given"]) (return . urlDecodeUnicode) mt - -doEval :: Grammar -> String -> Err JSValue -doEval sgr t = liftM termToJSValue $ eval sgr t - --- FIXME -termToJSValue :: Term -> JSValue -termToJSValue = showJSON . toJSObject . prTermTabular - -eval :: Grammar -> String -> Err Term -eval sgr t = pTerm t >>= checkTerm sgr >>= computeTerm sgr - --- * General CGI and JSON stuff - -outputJSON :: JSON a => a -> CGI CGIResult -outputJSON x = do setHeader "Content-Type" "text/json; charset=utf-8" - outputStrict $ UTF8.encodeString $ encode x - -outputStrict :: String -> CGI CGIResult -outputStrict x | x == x = output x - | otherwise = fail "I am the pope." |
