mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-09 03:02:50 -06:00
A somewhat better solution to the words/UTF-8 problem: do encoding last, but only on what appears to be string literals.
This commit is contained in:
@@ -208,7 +208,7 @@ compileSourceModule opts env@(k,gr,_) mo@(i,mi) = do
|
|||||||
generateModuleCode :: Options -> FilePath -> SourceModule -> IOE SourceModule
|
generateModuleCode :: Options -> FilePath -> SourceModule -> IOE SourceModule
|
||||||
generateModuleCode opts file minfo = do
|
generateModuleCode opts file minfo = do
|
||||||
let minfo1 = subexpModule minfo
|
let minfo1 = subexpModule minfo
|
||||||
out = prGrammar (MGrammar [codeSourceModule encodeUTF8 minfo1])
|
out = codeStringLiterals encodeUTF8 $ prGrammar (MGrammar [minfo1])
|
||||||
putPointE Normal opts (" wrote file" +++ file) $ ioeIO $ writeFile file $ out
|
putPointE Normal opts (" wrote file" +++ file) $ ioeIO $ writeFile file $ out
|
||||||
return minfo1
|
return minfo1
|
||||||
|
|
||||||
|
|||||||
@@ -48,3 +48,13 @@ codeSourceModule co (id,moi) = case moi of
|
|||||||
PSeq p q -> PSeq (codp p) (codp q)
|
PSeq p q -> PSeq (codp p) (codp q)
|
||||||
PAlt p q -> PAlt (codp p) (codp q)
|
PAlt p q -> PAlt (codp p) (codp q)
|
||||||
_ -> p
|
_ -> p
|
||||||
|
|
||||||
|
-- | Run an encoding function on all string literals within the given string.
|
||||||
|
codeStringLiterals :: (String -> String) -> String -> String
|
||||||
|
codeStringLiterals _ [] = []
|
||||||
|
codeStringLiterals co ('"':cs) = '"' : inStringLiteral cs
|
||||||
|
where inStringLiteral [] = error "codeStringLiterals: unterminated string literal"
|
||||||
|
inStringLiteral ('"':ds) = '"' : codeStringLiterals co ds
|
||||||
|
inStringLiteral ('\\':d:ds) = '\\' : co [d] ++ inStringLiteral ds
|
||||||
|
inStringLiteral (d:ds) = co [d] ++ inStringLiteral ds
|
||||||
|
codeStringLiterals co (c:cs) = c : codeStringLiterals co cs
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ compactPrint = compactPrintCustom keywordGF (const False)
|
|||||||
|
|
||||||
compactPrintGFCC = compactPrintCustom (const False) keywordGFCC
|
compactPrintGFCC = compactPrintCustom (const False) keywordGFCC
|
||||||
|
|
||||||
-- FIXME: using words is not safe, since this is run on UTF-8 encoded data.
|
compactPrintCustom pre post = dps . concat . map (spaceIf pre post) . words
|
||||||
compactPrintCustom pre post = id -- dps . concat . map (spaceIf pre post) . words
|
|
||||||
|
|
||||||
dps = dropWhile isSpace
|
dps = dropWhile isSpace
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user