Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added workaround for Syck's unicode limitations.

In Yst.Yaml, we use Syck to parse a bytestring, then do our own
decoding of string values in the nodes.
  • Loading branch information...
commit 54e1442eac39da01e0781c5c9de5d132ebc60c79 1 parent 3bb2144
@jgm authored
Showing with 17 additions and 5 deletions.
  1. +16 −4 Yst/Yaml.hs
  2. +1 −1  yst.cabal
View
20 Yst/Yaml.hs
@@ -20,14 +20,26 @@ module Yst.Yaml (readYamlFile, nodeToYamlNode)
where
import Yst.Types
import Yst.Util
-import Data.Yaml.Syck
+import Data.Yaml.Syck hiding (unpackBuf, packBuf)
+import qualified Data.Yaml.Syck (unpackBuf, packBuf)
import Data.Time
import System.Locale (defaultTimeLocale)
-import Prelude hiding (readFile)
-import System.IO.UTF8
+import Codec.Binary.UTF8.String (encodeString, decodeString)
+import qualified Data.ByteString.Char8 as B (ByteString, readFile)
+
+-- Note: Syck isn't unicode aware, so we use parseYamlBytes and do our
+-- own encoding and decoding.
+
+type Buf = B.ByteString
+
+unpackBuf :: Buf -> String
+unpackBuf = decodeString . Data.Yaml.Syck.unpackBuf
+
+packBuf :: String -> Buf
+packBuf = Data.Yaml.Syck.packBuf . encodeString
readYamlFile :: FilePath -> IO Node
-readYamlFile f = catch (readFile f >>= parseYaml >>= return . yamlNodeToNode)
+readYamlFile f = catch (B.readFile f >>= parseYamlBytes >>= return . yamlNodeToNode)
(\e -> errorExit 11 ("Error parsing " ++ f ++ ": " ++ show e) >> return NNil)
yamlNodeToNode :: YamlNode -> Node
View
2  yst.cabal
@@ -48,6 +48,6 @@ Executable yst
Yst.Render, Yst.Build, Yst.CSV
build-depends: base >=3 && < 5, HStringTemplate >= 0.6.1, HsSyck, csv,
filepath, containers, directory, utf8-string, time,
- old-locale, old-time, parsec, xhtml, pandoc
+ old-locale, old-time, parsec, xhtml, pandoc, bytestring
ghc-options: -Wall -threaded -fno-warn-orphans
ghc-prof-options: -auto-all -caf-all
Please sign in to comment.
Something went wrong with that request. Please try again.