Changeset 19957 for third-party

Show
Ignore:
Timestamp:
02/20/08 17:18:00 (9 months ago)
Author:
gwern
Message:

Update HsSyck? to merge in the Haddock documentation and the Cabal sdist improvements which constituted 0.3 and 0.4. This version also updates hsSyck to work with modern ByteStrings?, bytestring>=0.9.0.1, which is the oldest one packaged with GHC 6.8.x. (You can get this and hsregex on Hackage as well.)

Location:
third-party/HsSyck
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • third-party/HsSyck/Data/Yaml/Syck.hsc

    r16409 r19957  
    2525import qualified Data.HashTable as Hash 
    2626import qualified Data.ByteString.Char8 as Buf 
    27 import Data.ByteString.Char8 (copyCStringLen, useAsCStringLen, useAsCString, copyCString) 
     27import Data.ByteString.Char8 (useAsCStringLen, useAsCString) 
     28import Data.ByteString.Unsafe (unsafePackCString, unsafePackCStringLen) 
    2829 
    2930type Buf        = Buf.ByteString 
     
    6566type SyckBadAnchorHandler = SyckParser -> CString -> IO SyckNodePtr 
    6667type SyckNodePtr = Ptr CString 
    67 type SyckEmitter = Ptr ()   
     68type SyckEmitter = Ptr () 
    6869type SyckEmitterHandler = SyckEmitter -> Ptr () -> IO () 
    6970type SyckOutputHandler = SyckEmitter -> CString -> CLong -> IO () 
     
    7778nilNode = MkNode maxId ENil Nothing ASingleton 
    7879 
     80-- | Convert a ByteString buffer into a regular Haskell string 
     81 
    7982{-# INLINE unpackBuf #-} 
    8083unpackBuf :: Buf -> String 
    8184unpackBuf = Buf.unpack 
     85 
     86-- | Convert a regular Haskell string into a ByteString buffer 
    8287 
    8388{-# INLINE packBuf #-} 
     
    107112type EmitterExtras = Ptr () 
    108113-} 
     114 
     115-- | Dump a YAML node into a ByteString buffer (fast) 
    109116 
    110117emitYamlBytes :: YamlNode -> IO Buf 
     
    114121        out    <- newIORef [] 
    115122        #{poke SyckEmitter, style} emitter scalarFold 
    116         -- #{poke SyckEmitter, sort_keys} emitter (1 :: CInt) 
    117123        #{poke SyckEmitter, anchor_format} emitter (Ptr "%d"## :: CString) 
    118124 
     
    131137        fmap (Buf.concat . reverse) (readIORef out) 
    132138 
     139-- | Given a file name, dump a YAML node into that file 
     140 
    133141emitYamlFile :: FilePath -> YamlNode -> IO () 
    134142emitYamlFile file node = do 
    135143    buf <- emitYamlBytes node 
    136144    Buf.writeFile file buf 
     145 
     146-- | Dump a YAML node into a regular Haskell string 
    137147 
    138148emitYaml :: YamlNode -> IO String 
     
    159169outputCallbackPS :: IORef [Buf] -> SyckEmitter -> CString -> CLong -> IO () 
    160170outputCallbackPS out emitter buf len = do 
    161     str <- copyCStringLen (buf, fromEnum len) 
     171    str <- unsafePackCStringLen (buf, fromEnum len) 
    162172    str `seq` modifyIORef out (str:) 
    163173 
     
    183193emitNode _ e n | EStr s <- n_elem n = do 
    184194    withTag n (Ptr "string"##) $ \tag -> 
    185         useAsCStringLen s $ \(cs, l) ->        
     195        useAsCStringLen s $ \(cs, l) -> 
    186196        syck_emit_scalar e tag scalarFold 0 0 0 cs (toEnum l) 
    187197 
    188198emitNode freeze e n | ESeq sq <- n_elem n = do 
    189199    withTag n (Ptr "array"##) $ \tag -> 
    190         syck_emit_seq e tag seqInline 
    191 --      syck_emit_seq e tag seqNone 
     200--        syck_emit_seq e tag seqInline 
     201      syck_emit_seq e tag seqNone 
    192202    mapM_ (syck_emit_item e) =<< mapM freeze sq 
    193203    syck_emit_end e 
     
    195205emitNode freeze e n | EMap m <- n_elem n = do 
    196206    withTag n (Ptr "map"##) $ \tag -> 
    197         syck_emit_map e tag mapInline 
    198 --      syck_emit_map e tag mapNone 
     207--        syck_emit_map e tag mapInline 
     208      syck_emit_map e tag mapNone 
    199209    flip mapM_ m (\(k,v) -> do 
    200210        syck_emit_item e =<< freeze k 
     
    205215withTag node def f = maybe (f def) (`useAsCString` f) (n_tag node) 
    206216 
     217-- | Parse a regular Haskell string 
     218 
    207219parseYaml :: String -> IO YamlNode 
    208220parseYaml = (`withCString` parseYamlCStr) 
    209221 
     222-- | Given a file name, parse contents of file 
     223 
    210224parseYamlFile :: String -> IO YamlNode 
    211225parseYamlFile file = parseYamlBytes =<< Buf.readFile file 
     226 
     227-- | Parse a ByteString buffer (this is faster) 
    212228 
    213229parseYamlBytes :: Buf -> IO YamlNode 
     
    334350    tag <- #{peek SyckNode, type_id} syckNode 
    335351    if (tag == nullPtr) then (return Nothing) else do 
    336         p <- copyCString tag 
     352        p <- unsafePackCString tag 
    337353        return $! case Buf.elemIndex '/' p of 
    338354            Just n -> let { pre = Buf.take n p; post = Buf.drop (n+1) p } in 
     
    371387    tag   <- syckNodeTag syckNode 
    372388    cstr  <- syck_str_read syckNode 
    373     buf   <- copyCStringLen (cstr, fromEnum len) 
     389    buf   <- unsafePackCStringLen (cstr, fromEnum len) 
    374390    let node = nilNode{ n_elem = EStr buf, n_tag = tag, n_id = nid } 
    375391    if tag == Nothing && Buf.length buf == 1 && Buf.index buf 0 == '~' 
     
    381397        else return node 
    382398 
    383 foreign import ccall "wrapper"   
     399foreign import ccall "wrapper" 
    384400    mkNodeCallback :: SyckNodeHandler -> IO (FunPtr SyckNodeHandler) 
    385401 
    386 foreign import ccall "wrapper"   
     402foreign import ccall "wrapper" 
    387403    mkErrorCallback :: SyckErrorHandler -> IO (FunPtr SyckErrorHandler) 
    388404 
    389 foreign import ccall "wrapper"   
     405foreign import ccall "wrapper" 
    390406    mkBadHandlerCallback :: SyckBadAnchorHandler -> IO (FunPtr SyckBadAnchorHandler) 
    391407 
  • third-party/HsSyck/pugs-HsSyck.cabal

    r16500 r19957  
    11Name:                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 
     2Version:             0.41 
     3Category:            Text 
     4Synopsis:            Fast, lightweight YAML loader and dumper 
     5Description:         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 
     14License:             OtherLicense 
     15License-File:        LICENSE 
    716Author:              Audrey Tang 
    817Maintainer:          audreyt@audreyt.org 
    9 Build-Depends:       base 
     18Copyright:           Audrey Tang, Gaal Yahas, 2005, 2006, 2007 
     19 
    1020Exposed-modules:     Data.Yaml.Syck 
     21 
     22Build-Depends:       base, bytestring>=0.9.0.1 
     23Build-Type:          Simple 
     24Tested-With:         GHC==6.8.2 
     25 
    1126extensions:          ForeignFunctionInterface 
    12 ghc-options:         -fglasgow-exts -O2 -optc-w -funbox-strict-fields -fno-warn-orphans 
     27ghc-options:         -O2 -optc-w -funbox-strict-fields -fglasgow-exts 
     28 
     29data-files:          Changes 
    1330c-sources:           syck/bytecode.c syck/emitter.c syck/gram.c syck/handler.c 
    1431                     syck/implicit.c syck/node.c syck/syck.c syck/syck_st.c syck/token.c 
    15                      syck/yaml2byte.c  
     32                     syck/yaml2byte.c 
    1633extra-source-files:  syck/syck.h syck/syck_st.h syck/gram.h syck/yamlbyte.h 
    1734include-dirs:        syck