summaryrefslogtreecommitdiff
path: root/src/GF/API.hs
diff options
context:
space:
mode:
authorbringert <unknown>2005-03-08 14:49:24 +0000
committerbringert <unknown>2005-03-08 14:49:24 +0000
commite19f8f8922dc9704c7cc8e6156f2a475b9627439 (patch)
tree7539dc73107668e8d8ed112712db0da112bafe7f /src/GF/API.hs
parent7194efcea85e6a1d16b35fd2ad268dfc675a1b24 (diff)
Switched to doing utf8-conversion after pretty-printing.
Diffstat (limited to 'src/GF/API.hs')
-rw-r--r--src/GF/API.hs36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/GF/API.hs b/src/GF/API.hs
index 2fc562c1c..f8006032d 100644
--- a/src/GF/API.hs
+++ b/src/GF/API.hs
@@ -5,9 +5,9 @@
-- Stability : (stable)
-- Portability : (portable)
--
--- > CVS $Date: 2005/03/08 15:31:22 $
+-- > CVS $Date: 2005/03/08 15:49:24 $
-- > CVS $Author: bringert $
--- > CVS $Revision: 1.28 $
+-- > CVS $Revision: 1.29 $
--
-- Application Programmer's Interface to GF; also used by Shell. AR 10/11/2001
-----------------------------------------------------------------------------
@@ -298,20 +298,21 @@ optPrintGrammar :: Options -> StateGrammar -> String
optPrintGrammar opts = customOrDefault opts grammarPrinter customGrammarPrinter
optPrintMultiGrammar :: Options -> CanonGrammar -> String
-optPrintMultiGrammar opts = pmg . encodeId . encode
+optPrintMultiGrammar opts = encodeId . pmg . encode
where
pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter
-- if -utf8 was given, convert from language specific codings
encode = if oElem useUTF8 opts then mapModules moduleToUTF8 else id
-- if -utf8id was given, convert identifiers to UTF8
- encodeId = if oElem useUTF8id opts then grammarIdentsToUTF8 else id
+-- encodeId = if oElem useUTF8id opts then grammarIdentsToUTF8 else id
+ encodeId = if oElem useUTF8id opts then nonLiteralsToUTF8 else id
moduleToUTF8 m =
m{ jments = mapTree (onSnd (mapInfoTerms code)) (jments m),
flags = setFlag "coding" "utf8" (flags m) }
where code = onTokens (anyCodingToUTF8 (moduleOpts m))
moduleOpts = Opts . okError . mapM CG.redFlag . flags
- grammarIdentsToUTF8 mgr
- = MGrammar [ (identToUTF8 i, mapIdents identToUTF8 mi) | (i,mi) <- modules mgr]
+-- grammarIdentsToUTF8 mgr
+-- = MGrammar [ (identToUTF8 i, mapIdents identToUTF8 mi) | (i,mi) <- modules mgr]
optPrintSyntax :: Options -> GF.Grammar -> String
optPrintSyntax opts = customOrDefault opts grammarPrinter customSyntaxPrinter
@@ -370,20 +371,24 @@ anyCodingToUTF8 :: Options -> String -> String
anyCodingToUTF8 opts =
encodeUTF8 . customOrDefault opts uniCoding customUniCoding
-{-
+
-- | Convert all text not inside double quotes to UTF8
nonLiteralsToUTF8 :: String -> String
nonLiteralsToUTF8 "" = ""
nonLiteralsToUTF8 ('"':cs) = '"' : l ++ nonLiteralsToUTF8 rs
- where (l,rs) = takeStringLit cs
-nonLiteralsToUTF8 (c:cs) = encodeUTF8 [c] : nonLiteralsToUTF8 cs
- where
- -- | Split off an initial string ended by double quotes
- takeStringLit :: String -> (String,String)
- takeStringLit "" = ("","")
- takeStringLit
--}
+ where
+ (l,rs) = takeStringLit cs
+ -- | Split off an initial string ended by double quotes
+ takeStringLit :: String -> (String,String)
+ takeStringLit "" = ("","")
+ takeStringLit ('"':cs) = (['"'],cs)
+ takeStringLit ('\\':'"':cs) = ('\\':'"':xs,ys)
+ where (xs,ys) = takeStringLit cs
+ takeStringLit (c:cs) = (c:xs,ys)
+ where (xs,ys) = takeStringLit cs
+nonLiteralsToUTF8 (c:cs) = encodeUTF8 [c] ++ nonLiteralsToUTF8 cs
+{-
-- | Convert an identifier in unicode to UTF8 encoding
identToUTF8 :: I.Ident -> I.Ident
identToUTF8 i = case i of
@@ -392,3 +397,4 @@ identToUTF8 i = case i of
I.IV (i,s) -> I.IV (i, encodeUTF8 s)
I.IA (s,i) -> I.IA (encodeUTF8 s, i)
I.IAV (s,i1,i2) -> I.IAV (encodeUTF8 s, i2, i2)
+-} \ No newline at end of file