summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-09-12 11:05:38 +0000
committerbjorn <bjorn@bringert.net>2008-09-12 11:05:38 +0000
commita7bf88fb32436e3946a0dc68eb70e2b84867aef6 (patch)
tree1bd2448515cb5f8cbe9dcb034ff430f6ce5ecbd0
parent1a320db136a65d1369c473a365cfa5f3cbd031f3 (diff)
Change JSON structures returned by the translation server to always be arrays of objects.
-rw-r--r--src/server/MainFastCGI.hs42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/server/MainFastCGI.hs b/src/server/MainFastCGI.hs
index 59c1c2d68..1f2413211 100644
--- a/src/server/MainFastCGI.hs
+++ b/src/server/MainFastCGI.hs
@@ -76,27 +76,40 @@ cgiMain pgf =
_ -> return mlang
doTranslate :: PGF -> String -> Maybe PGF.Category -> Maybe PGF.Language -> Maybe PGF.Language -> JSValue
-doTranslate pgf input mcat mfrom mto = showJSON $ toJSObject $
- [(from, [toJSObject (linearize' pgf mto tree) | tree <- trees])
- | (from,trees) <- parse' pgf input mcat mfrom]
+doTranslate pgf input mcat mfrom mto = showJSON $ map toJSObject
+ [[("from",from),("to",to),("text",output)]
+ | (from,trees) <- parse' pgf input mcat mfrom,
+ tree <- trees,
+ (to,output) <- linearize' pgf mto tree]
doParse :: PGF -> String -> Maybe PGF.Category -> Maybe PGF.Language -> JSValue
-doParse pgf input mcat mfrom = showJSON $ toJSObject $
- [(from, map PGF.showTree trees) | (from,trees) <- parse' pgf input mcat mfrom]
+doParse pgf input mcat mfrom = showJSON $ map toJSObject
+ [[("from",from),("tree",PGF.showTree tree)]
+ | (from,trees) <- parse' pgf input mcat mfrom,
+ tree <- trees ]
doComplete :: PGF -> String -> Maybe PGF.Category -> Maybe PGF.Language -> Maybe Int -> JSValue
-doComplete pgf input mcat mfrom mlimit = showJSON $ toJSObject $ complete' pgf input mcat mfrom mlimit
+doComplete pgf input mcat mfrom mlimit = showJSON $ map toJSObject $ limit
+ [[("from",from),("text",text)]
+ | (from,compls) <- complete' pgf input mcat mfrom,
+ text <- compls]
+ where
+ limit xs = maybe xs (\n -> take n xs) mlimit
doLinearize :: PGF -> PGF.Tree -> Maybe PGF.Language -> JSValue
-doLinearize pgf tree mto = showJSON $ toJSObject $ linearize' pgf mto tree
+doLinearize pgf tree mto = showJSON $ map toJSObject
+ [[("to",to),("text",text)] | (to,text) <- linearize' pgf mto tree]
doLanguages :: PGF -> JSValue
-doLanguages pgf = showJSON $ toJSObject [(l,toJSObject (info l)) | l <- PGF.languages pgf]
- where info l = [("languageCode", showJSON (fromMaybe "" (PGF.languageCode pgf l))),
- ("canParse", showJSON (PGF.canParse pgf l))]
+doLanguages pgf = showJSON $ map toJSObject
+ [[("lang", showJSON l),
+ ("languageCode", showJSON $ fromMaybe "" (PGF.languageCode pgf l)),
+ ("canParse", showJSON $ PGF.canParse pgf l)]
+ | l <- PGF.languages pgf]
doCategories :: PGF -> JSValue
-doCategories pgf = showJSON (PGF.categories pgf)
+doCategories pgf = showJSON $ map toJSObject
+ [[("cat",cat)] | cat <- PGF.categories pgf]
-- * PGF utilities
@@ -107,12 +120,11 @@ parse' pgf input mcat mfrom =
where froms = maybe (PGF.languages pgf) (:[]) mfrom
cat = fromMaybe (PGF.startCat pgf) mcat
-complete' :: PGF -> String -> Maybe PGF.Category -> Maybe PGF.Language -> Maybe Int -> [(PGF.Language,[String])]
-complete' pgf input mcat mfrom mlimit =
- limit [(from,ss) | from <- froms, PGF.canParse pgf from, let ss = complete pgf from cat input, not (null ss)]
+complete' :: PGF -> String -> Maybe PGF.Category -> Maybe PGF.Language -> [(PGF.Language,[String])]
+complete' pgf input mcat mfrom =
+ [(from,ss) | from <- froms, PGF.canParse pgf from, let ss = complete pgf from cat input, not (null ss)]
where froms = maybe (PGF.languages pgf) (:[]) mfrom
cat = fromMaybe (PGF.startCat pgf) mcat
- limit xs = maybe xs (\n -> take n xs) mlimit
complete :: PGF -> PGF.Language -> PGF.Category -> String -> [String]
complete pgf from cat input =