diff options
| author | aarne <unknown> | 2003-11-03 16:27:55 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2003-11-03 16:27:55 +0000 |
| commit | 94326929b144913642121bef8f8ecc98feb992e7 (patch) | |
| tree | 07d59cc33cbef2ac79c6f3f573b9718c51322e7a /src/GF/Text/Text.hs | |
| parent | 2728e6e7ceec92c7f781368b4a523b37e5dee3b9 (diff) | |
Fixed several things, e.g. tokenizer.
Diffstat (limited to 'src/GF/Text/Text.hs')
| -rw-r--r-- | src/GF/Text/Text.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/GF/Text/Text.hs b/src/GF/Text/Text.hs index 08e897a9b..2fbf97fd3 100644 --- a/src/GF/Text/Text.hs +++ b/src/GF/Text/Text.hs @@ -31,15 +31,23 @@ formatAsText = unwords . format . cap . words where para = (=="<p>") formatAsCode :: String -> String -formatAsCode = unwords . format . words where - format ws = case ws of - p : w : ww | parB p -> format ((p ++ w') : ww') where (w':ww') = format (w:ww) - w : p : ww | par p -> format ((w ++ p') : ww') where (p':ww') = format (p:ww) - w : ww -> w : format ww - [] -> [] - parB = flip elem (map singleton "([{") - parE = flip elem (map singleton "}])") - par t = parB t || parE t +formatAsCode = rend 0 . words where + -- render from BNF Converter + rend i ss = case ss of + "[" :ts -> cons "[" $ rend i ts + "(" :ts -> cons "(" $ rend i ts + "{" :ts -> cons "{" $ new (i+1) $ rend (i+1) ts + "}" : ";":ts -> new (i-1) $ space "}" $ cons ";" $ new (i-1) $ rend (i-1) ts + "}" :ts -> new (i-1) $ cons "}" $ new (i-1) $ rend (i-1) ts + ";" :ts -> cons ";" $ new i $ rend i ts + t : "," :ts -> cons t $ space "," $ rend i ts + t : ")" :ts -> cons t $ cons ")" $ rend i ts + t : "]" :ts -> cons t $ cons "]" $ rend i ts + t :ts -> space t $ rend i ts + _ -> "" + cons s t = s ++ t + new i s = '\n' : replicate (2*i) ' ' ++ dropWhile isSpace s + space t s = if null s then t else t ++ " " ++ s performBinds :: String -> String performBinds = unwords . format . words where |
