summaryrefslogtreecommitdiff
path: root/src/server/PGFService.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-08-23 16:25:00 +0000
committerhallgren <hallgren@chalmers.se>2011-08-23 16:25:00 +0000
commitba03db58a4ae2ad4defa227c0bcf3bc2dd125a88 (patch)
treeb82e9917c8e436f518a2900d0af80c6fcaf8f4c9 /src/server/PGFService.hs
parent0880abdc0453b9d414b2630981a1a2356804a200 (diff)
pgf-service: add Jordis transfer function for OpenMath LaTeX output
Diffstat (limited to 'src/server/PGFService.hs')
-rw-r--r--src/server/PGFService.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index b6b67dd4c..996ba5bd7 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -28,6 +28,7 @@ import System.Process
import System.Exit
import System.IO
import System.Directory(removeFile)
+import Fold(fold) -- transfer function for OpenMath LaTeX
logFile :: FilePath
logFile = "pgf-error.log"
@@ -164,7 +165,7 @@ doTranslate pgf input mcat mfrom mto =
("linearizations",showJSON
[toJSObject [("to", showJSON to),
("text",showJSON output)]
- | (to,output) <- linearizeAndBind pgf mto tree]
+ | (to,output) <- transferLinearizeAndBind pgf mto tree]
)]
| tree <- trees])]
jsonParseOutput (PGF.ParseIncomplete)= []
@@ -496,6 +497,16 @@ linearizeAndBind pgf mto t = [(la, binds s) | (la,s) <- linearize' pgf mto t]
u:ws2 -> u : bs ws2
_ -> []
+-- Apply transfer function OpenMath LaTeX
+transferLinearizeAndBind pgf mto t = [(la, binds s) | (la,s) <- unfolded ++ folded, not (null s)]
+ where unfolded = linearize' pgf mto t
+ folded = linearize' pgf mto (fold t)
+ binds = unwords . bs . words
+ bs ws = case ws of
+ u:"&+":v:ws2 -> bs ((u ++ v):ws2)
+ u:ws2 -> u : bs ws2
+ _ -> []
+
selectLanguage :: PGF -> Maybe (Accept Language) -> PGF.Language
selectLanguage pgf macc = case acceptable of
[] -> case PGF.languages pgf of