From 94326929b144913642121bef8f8ecc98feb992e7 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 3 Nov 2003 16:27:55 +0000 Subject: Fixed several things, e.g. tokenizer. --- src/GF/Text/Text.hs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/GF/Text') 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 = (=="

") 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 -- cgit v1.2.3