the grammars are now recognized by extension i.e. .pgf is grammar just like .php is a PHP script

This commit is contained in:
krasimir
2009-01-25 22:06:20 +00:00
parent 7dfc17cd98
commit 92bb971ea3
9 changed files with 78 additions and 67 deletions

View File

@@ -34,19 +34,12 @@ main = do stderrToFile logFile
cgiMain :: Cache PGF -> CGI CGIResult
cgiMain cache =
do path <- pathInfo
jsonp <- serveResource cache $ filter (not . null) $ splitBy (=='/') path
do path <- getVarWithDefault "SCRIPT_FILENAME" ""
pgf <- liftIO $ readCache cache path
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString)) (getInput "command")
jsonp <- pgfMain pgf command
outputJSONP jsonp
serveResource :: Cache PGF -> [String] -> CGI JSValue
serveResource cache resource =
case resource of
[] -> liftIO doListGrammars
[file] -> serveResource cache [file,"grammar"]
[file,command] -> do pgf <- liftIO $ readCache cache $ cleanFilePath file
pgfMain pgf command
_ -> throwCGIError 400 "Unknown resource" ["Unknown resource: " ++ show resource]
pgfMain :: PGF -> String -> CGI JSValue
pgfMain pgf command =
case command of