Changeset 19957 for third-party
- Timestamp:
- 02/20/08 17:18:00 (9 months ago)
- Location:
- third-party/HsSyck
- Files:
-
- 1 added
- 2 modified
-
Changes (added)
-
Data/Yaml/Syck.hsc (modified) (13 diffs)
-
pugs-HsSyck.cabal (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
third-party/HsSyck/Data/Yaml/Syck.hsc
r16409 r19957 25 25 import qualified Data.HashTable as Hash 26 26 import qualified Data.ByteString.Char8 as Buf 27 import Data.ByteString.Char8 (copyCStringLen, useAsCStringLen, useAsCString, copyCString) 27 import Data.ByteString.Char8 (useAsCStringLen, useAsCString) 28 import Data.ByteString.Unsafe (unsafePackCString, unsafePackCStringLen) 28 29 29 30 type Buf = Buf.ByteString … … 65 66 type SyckBadAnchorHandler = SyckParser -> CString -> IO SyckNodePtr 66 67 type SyckNodePtr = Ptr CString 67 type SyckEmitter = Ptr () 68 type SyckEmitter = Ptr () 68 69 type SyckEmitterHandler = SyckEmitter -> Ptr () -> IO () 69 70 type SyckOutputHandler = SyckEmitter -> CString -> CLong -> IO () … … 77 78 nilNode = MkNode maxId ENil Nothing ASingleton 78 79 80 -- | Convert a ByteString buffer into a regular Haskell string 81 79 82 {-# INLINE unpackBuf #-} 80 83 unpackBuf :: Buf -> String 81 84 unpackBuf = Buf.unpack 85 86 -- | Convert a regular Haskell string into a ByteString buffer 82 87 83 88 {-# INLINE packBuf #-} … … 107 112 type EmitterExtras = Ptr () 108 113 -} 114 115 -- | Dump a YAML node into a ByteString buffer (fast) 109 116 110 117 emitYamlBytes :: YamlNode -> IO Buf … … 114 121 out <- newIORef [] 115 122 #{poke SyckEmitter, style} emitter scalarFold 116 -- #{poke SyckEmitter, sort_keys} emitter (1 :: CInt)117 123 #{poke SyckEmitter, anchor_format} emitter (Ptr "%d"## :: CString) 118 124 … … 131 137 fmap (Buf.concat . reverse) (readIORef out) 132 138 139 -- | Given a file name, dump a YAML node into that file 140 133 141 emitYamlFile :: FilePath -> YamlNode -> IO () 134 142 emitYamlFile file node = do 135 143 buf <- emitYamlBytes node 136 144 Buf.writeFile file buf 145 146 -- | Dump a YAML node into a regular Haskell string 137 147 138 148 emitYaml :: YamlNode -> IO String … … 159 169 outputCallbackPS :: IORef [Buf] -> SyckEmitter -> CString -> CLong -> IO () 160 170 outputCallbackPS out emitter buf len = do 161 str <- copyCStringLen (buf, fromEnum len)171 str <- unsafePackCStringLen (buf, fromEnum len) 162 172 str `seq` modifyIORef out (str:) 163 173 … … 183 193 emitNode _ e n | EStr s <- n_elem n = do 184 194 withTag n (Ptr "string"##) $ \tag -> 185 useAsCStringLen s $ \(cs, l) -> 195 useAsCStringLen s $ \(cs, l) -> 186 196 syck_emit_scalar e tag scalarFold 0 0 0 cs (toEnum l) 187 197 188 198 emitNode freeze e n | ESeq sq <- n_elem n = do 189 199 withTag n (Ptr "array"##) $ \tag -> 190 syck_emit_seq e tag seqInline191 --syck_emit_seq e tag seqNone200 -- syck_emit_seq e tag seqInline 201 syck_emit_seq e tag seqNone 192 202 mapM_ (syck_emit_item e) =<< mapM freeze sq 193 203 syck_emit_end e … … 195 205 emitNode freeze e n | EMap m <- n_elem n = do 196 206 withTag n (Ptr "map"##) $ \tag -> 197 syck_emit_map e tag mapInline198 --syck_emit_map e tag mapNone207 -- syck_emit_map e tag mapInline 208 syck_emit_map e tag mapNone 199 209 flip mapM_ m (\(k,v) -> do 200 210 syck_emit_item e =<< freeze k … … 205 215 withTag node def f = maybe (f def) (`useAsCString` f) (n_tag node) 206 216 217 -- | Parse a regular Haskell string 218 207 219 parseYaml :: String -> IO YamlNode 208 220 parseYaml = (`withCString` parseYamlCStr) 209 221 222 -- | Given a file name, parse contents of file 223 210 224 parseYamlFile :: String -> IO YamlNode 211 225 parseYamlFile file = parseYamlBytes =<< Buf.readFile file 226 227 -- | Parse a ByteString buffer (this is faster) 212 228 213 229 parseYamlBytes :: Buf -> IO YamlNode … … 334 350 tag <- #{peek SyckNode, type_id} syckNode 335 351 if (tag == nullPtr) then (return Nothing) else do 336 p <- copyCString tag352 p <- unsafePackCString tag 337 353 return $! case Buf.elemIndex '/' p of 338 354 Just n -> let { pre = Buf.take n p; post = Buf.drop (n+1) p } in … … 371 387 tag <- syckNodeTag syckNode 372 388 cstr <- syck_str_read syckNode 373 buf <- copyCStringLen (cstr, fromEnum len)389 buf <- unsafePackCStringLen (cstr, fromEnum len) 374 390 let node = nilNode{ n_elem = EStr buf, n_tag = tag, n_id = nid } 375 391 if tag == Nothing && Buf.length buf == 1 && Buf.index buf 0 == '~' … … 381 397 else return node 382 398 383 foreign import ccall "wrapper" 399 foreign import ccall "wrapper" 384 400 mkNodeCallback :: SyckNodeHandler -> IO (FunPtr SyckNodeHandler) 385 401 386 foreign import ccall "wrapper" 402 foreign import ccall "wrapper" 387 403 mkErrorCallback :: SyckErrorHandler -> IO (FunPtr SyckErrorHandler) 388 404 389 foreign import ccall "wrapper" 405 foreign import ccall "wrapper" 390 406 mkBadHandlerCallback :: SyckBadAnchorHandler -> IO (FunPtr SyckBadAnchorHandler) 391 407 -
third-party/HsSyck/pugs-HsSyck.cabal
r16500 r19957 1 1 Name: pugs-HsSyck 2 Version: 0.2 3 Description: Fast, lightweight YAML loader and dumper 4 -- License is really "MIT", but Cabal allows no such field 5 License: BSD3 6 License-file: LICENSE 2 Version: 0.41 3 Category: Text 4 Synopsis: Fast, lightweight YAML loader and dumper 5 Description: This is a simple YAML ('Yet Another Markup Language') processor, 6 used by the Pugs project for handling data serialization; this can be 7 useful for optimization and caching purposes. 8 . 9 This is an interface to the @syck@ C library for parsing and 10 dumping YAML data. It lets you transform textual YAML data into an 11 object of type 'YamlNode', and vice versa, fast. 12 13 -- License is really "MIT", but Cabal doesn't have that constant yet 14 License: OtherLicense 15 License-File: LICENSE 7 16 Author: Audrey Tang 8 17 Maintainer: audreyt@audreyt.org 9 Build-Depends: base 18 Copyright: Audrey Tang, Gaal Yahas, 2005, 2006, 2007 19 10 20 Exposed-modules: Data.Yaml.Syck 21 22 Build-Depends: base, bytestring>=0.9.0.1 23 Build-Type: Simple 24 Tested-With: GHC==6.8.2 25 11 26 extensions: ForeignFunctionInterface 12 ghc-options: -fglasgow-exts -O2 -optc-w -funbox-strict-fields -fno-warn-orphans 27 ghc-options: -O2 -optc-w -funbox-strict-fields -fglasgow-exts 28 29 data-files: Changes 13 30 c-sources: syck/bytecode.c syck/emitter.c syck/gram.c syck/handler.c 14 31 syck/implicit.c syck/node.c syck/syck.c syck/syck_st.c syck/token.c 15 syck/yaml2byte.c 32 syck/yaml2byte.c 16 33 extra-source-files: syck/syck.h syck/syck_st.h syck/gram.h syck/yamlbyte.h 17 34 include-dirs: syck
