From dc1db399f698ec80ca80cf2e0925239527087a01 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 18 Aug 2008 12:34:56 +0000 Subject: [PATCH] When producing PGF, do UTF-8 encoding of the whole file after pretty printing instead of walking through the PGF structure before pretty-printing. The old code was brittle, and only converted strings in the lins and opers, not in printnames and parsers. The old code also double encoded some grammars when using gfc to combine PGF files. --- src/GF/Compile/Export.hs | 3 +-- src/PGF/Data.hs | 27 --------------------------- src/PGF/Raw/Convert.hs | 3 +-- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/GF/Compile/Export.hs b/src/GF/Compile/Export.hs index 21ecb3d15..9e9a99e99 100644 --- a/src/GF/Compile/Export.hs +++ b/src/GF/Compile/Export.hs @@ -58,5 +58,4 @@ outputConcr pgf = case cncnames pgf of cnc:_ -> cnc printPGF :: PGF -> String -printPGF = -- encodeUTF8 . -- fromPGF does UTF8 encoding - printTree . fromPGF +printPGF = encodeUTF8 . printTree . fromPGF diff --git a/src/PGF/Data.hs b/src/PGF/Data.hs index 3f9aaa6ab..761097d7f 100644 --- a/src/PGF/Data.hs +++ b/src/PGF/Data.hs @@ -172,30 +172,3 @@ emptyPGF = PGF { abstract = error "empty grammar, no abstract", concretes = Map.empty } - --- encode idenfifiers and strings in UTF8 - -utf8GFCC :: PGF -> PGF -utf8GFCC pgf = pgf { - concretes = Map.map u8concr (concretes pgf) - } - where - u8concr cnc = cnc { - lins = Map.map u8term (lins cnc), - opers = Map.map u8term (opers cnc) - } - u8term = convertStringsInTerm encodeUTF8 - ----- TODO: convert identifiers and flags - -convertStringsInTerm conv t = case t of - K (KS s) -> K (KS (conv s)) - W s r -> W (conv s) (convs r) - R ts -> R $ map convs ts - S ts -> S $ map convs ts - FV ts -> FV $ map convs ts - P u v -> P (convs u) (convs v) - _ -> t - where - convs = convertStringsInTerm conv - diff --git a/src/PGF/Raw/Convert.hs b/src/PGF/Raw/Convert.hs index af3708eb5..8e429660a 100644 --- a/src/PGF/Raw/Convert.hs +++ b/src/PGF/Raw/Convert.hs @@ -136,7 +136,7 @@ toTerm e = case e of ------------------------------ fromPGF :: PGF -> Grammar -fromPGF pgf0 = Grm [ +fromPGF pgf = Grm [ App "pgf" (AInt pgfMajorVersion:AInt pgfMinorVersion : App (prCId (absname pgf)) [] : map (flip App [] . prCId) (cncnames pgf)), App "flags" [App (prCId f) [AStr v] | (f,v) <- Map.toList (gflags pgf `Map.union` aflags apgf)], @@ -147,7 +147,6 @@ fromPGF pgf0 = Grm [ App "concrete" [App (prCId lang) (fromConcrete c) | (lang,c) <- Map.toList (concretes pgf)] ] where - pgf = utf8GFCC pgf0 apgf = abstract pgf fromConcrete cnc = [ App "flags" [App (prCId f) [AStr v] | (f,v) <- Map.toList (cflags cnc)],