forked from GitHub/gf-core
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)],
|
||||
|
||||
Reference in New Issue
Block a user