forked from GitHub/gf-core
Switched to doing utf8-conversion after pretty-printing.
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/03/08 15:31:22 $
|
-- > CVS $Date: 2005/03/08 15:49:24 $
|
||||||
-- > CVS $Author: bringert $
|
-- > 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
|
-- 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
|
optPrintGrammar opts = customOrDefault opts grammarPrinter customGrammarPrinter
|
||||||
|
|
||||||
optPrintMultiGrammar :: Options -> CanonGrammar -> String
|
optPrintMultiGrammar :: Options -> CanonGrammar -> String
|
||||||
optPrintMultiGrammar opts = pmg . encodeId . encode
|
optPrintMultiGrammar opts = encodeId . pmg . encode
|
||||||
where
|
where
|
||||||
pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter
|
pmg = customOrDefault opts grammarPrinter customMultiGrammarPrinter
|
||||||
-- if -utf8 was given, convert from language specific codings
|
-- if -utf8 was given, convert from language specific codings
|
||||||
encode = if oElem useUTF8 opts then mapModules moduleToUTF8 else id
|
encode = if oElem useUTF8 opts then mapModules moduleToUTF8 else id
|
||||||
-- if -utf8id was given, convert identifiers to UTF8
|
-- 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 =
|
moduleToUTF8 m =
|
||||||
m{ jments = mapTree (onSnd (mapInfoTerms code)) (jments m),
|
m{ jments = mapTree (onSnd (mapInfoTerms code)) (jments m),
|
||||||
flags = setFlag "coding" "utf8" (flags m) }
|
flags = setFlag "coding" "utf8" (flags m) }
|
||||||
where code = onTokens (anyCodingToUTF8 (moduleOpts m))
|
where code = onTokens (anyCodingToUTF8 (moduleOpts m))
|
||||||
moduleOpts = Opts . okError . mapM CG.redFlag . flags
|
moduleOpts = Opts . okError . mapM CG.redFlag . flags
|
||||||
grammarIdentsToUTF8 mgr
|
-- grammarIdentsToUTF8 mgr
|
||||||
= MGrammar [ (identToUTF8 i, mapIdents identToUTF8 mi) | (i,mi) <- modules mgr]
|
-- = MGrammar [ (identToUTF8 i, mapIdents identToUTF8 mi) | (i,mi) <- modules mgr]
|
||||||
|
|
||||||
optPrintSyntax :: Options -> GF.Grammar -> String
|
optPrintSyntax :: Options -> GF.Grammar -> String
|
||||||
optPrintSyntax opts = customOrDefault opts grammarPrinter customSyntaxPrinter
|
optPrintSyntax opts = customOrDefault opts grammarPrinter customSyntaxPrinter
|
||||||
@@ -370,20 +371,24 @@ anyCodingToUTF8 :: Options -> String -> String
|
|||||||
anyCodingToUTF8 opts =
|
anyCodingToUTF8 opts =
|
||||||
encodeUTF8 . customOrDefault opts uniCoding customUniCoding
|
encodeUTF8 . customOrDefault opts uniCoding customUniCoding
|
||||||
|
|
||||||
{-
|
|
||||||
-- | Convert all text not inside double quotes to UTF8
|
-- | Convert all text not inside double quotes to UTF8
|
||||||
nonLiteralsToUTF8 :: String -> String
|
nonLiteralsToUTF8 :: String -> String
|
||||||
nonLiteralsToUTF8 "" = ""
|
nonLiteralsToUTF8 "" = ""
|
||||||
nonLiteralsToUTF8 ('"':cs) = '"' : l ++ nonLiteralsToUTF8 rs
|
nonLiteralsToUTF8 ('"':cs) = '"' : l ++ nonLiteralsToUTF8 rs
|
||||||
where (l,rs) = takeStringLit cs
|
where
|
||||||
nonLiteralsToUTF8 (c:cs) = encodeUTF8 [c] : nonLiteralsToUTF8 cs
|
(l,rs) = takeStringLit cs
|
||||||
where
|
-- | Split off an initial string ended by double quotes
|
||||||
-- | Split off an initial string ended by double quotes
|
takeStringLit :: String -> (String,String)
|
||||||
takeStringLit :: String -> (String,String)
|
takeStringLit "" = ("","")
|
||||||
takeStringLit "" = ("","")
|
takeStringLit ('"':cs) = (['"'],cs)
|
||||||
takeStringLit
|
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
|
-- | Convert an identifier in unicode to UTF8 encoding
|
||||||
identToUTF8 :: I.Ident -> I.Ident
|
identToUTF8 :: I.Ident -> I.Ident
|
||||||
identToUTF8 i = case i of
|
identToUTF8 i = case i of
|
||||||
@@ -392,3 +397,4 @@ identToUTF8 i = case i of
|
|||||||
I.IV (i,s) -> I.IV (i, encodeUTF8 s)
|
I.IV (i,s) -> I.IV (i, encodeUTF8 s)
|
||||||
I.IA (s,i) -> I.IA (encodeUTF8 s, i)
|
I.IA (s,i) -> I.IA (encodeUTF8 s, i)
|
||||||
I.IAV (s,i1,i2) -> I.IAV (encodeUTF8 s, i2, i2)
|
I.IAV (s,i1,i2) -> I.IAV (encodeUTF8 s, i2, i2)
|
||||||
|
-}
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/03/08 15:31:22 $
|
-- > CVS $Date: 2005/03/08 15:49:24 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: bringert $
|
||||||
-- > CVS $Revision: 1.8 $
|
-- > CVS $Revision: 1.9 $
|
||||||
--
|
--
|
||||||
-- canonical GF. AR 10\/9\/2002 -- 9\/5\/2003 -- 21\/9
|
-- canonical GF. AR 10\/9\/2002 -- 9\/5\/2003 -- 21\/9
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -20,8 +20,8 @@ module GFC (Context,
|
|||||||
Info(..),
|
Info(..),
|
||||||
Printname,
|
Printname,
|
||||||
mapInfoTerms,
|
mapInfoTerms,
|
||||||
setFlag,
|
setFlag
|
||||||
mapIdents
|
-- , mapIdents
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import AbsGFC
|
import AbsGFC
|
||||||
@@ -71,6 +71,7 @@ mapInfoTerms f i = case i of
|
|||||||
setFlag :: String -> String -> [Flag] -> [Flag]
|
setFlag :: String -> String -> [Flag] -> [Flag]
|
||||||
setFlag n v fs = Flg (IC n) (IC v):[f | f@(Flg (IC n') _) <- fs, n' /= n]
|
setFlag n v fs = Flg (IC n) (IC v):[f | f@(Flg (IC n') _) <- fs, n' /= n]
|
||||||
|
|
||||||
|
{-
|
||||||
-- | Apply a function to all identifiers in a module
|
-- | Apply a function to all identifiers in a module
|
||||||
mapIdents :: (Ident -> Ident) -> M.ModInfo Ident Flag Info -> M.ModInfo Ident Flag Info
|
mapIdents :: (Ident -> Ident) -> M.ModInfo Ident Flag Info -> M.ModInfo Ident Flag Info
|
||||||
mapIdents f mi = case mi of
|
mapIdents f mi = case mi of
|
||||||
@@ -156,6 +157,7 @@ mapIdents f mi = case mi of
|
|||||||
fav av = case av of
|
fav av = case av of
|
||||||
A i x -> A (f i) x
|
A i x -> A (f i) x
|
||||||
AB i x y -> AB (f i) x y
|
AB i x y -> AB (f i) x y
|
||||||
|
-}
|
||||||
{-
|
{-
|
||||||
fat :: A.Term -> A.Term
|
fat :: A.Term -> A.Term
|
||||||
fat t = case t of
|
fat t = case t of
|
||||||
|
|||||||
Reference in New Issue
Block a user