haskell - Parsing several Yaml documents in one file using Data.Yaml -


starting code in answer, have working parses list of todo task items in yaml file.

but if ever add second document: data.yaml.decode no longer decodes anything, , returns nothing .

like this:

--- -   name: >         test task     state: finished  -   name: >         second test task     state: todo --- -   name: noname     state: nostate 

so wondering if possible @ use documents feature of yaml, when parsing data.yaml ?

or doing wrong ?

this code:

{-# language overloadedstrings #-} import data.yaml import control.applicative -- <$>, <*> import data.maybe (fromjust)  import qualified data.bytestring.char8 bs  data task = task {    name :: string,                       state :: string }                       deriving (show)  instance fromjson task     parsejson (object v) = task <$>                            v .: "name" <*>                            v .: "state"     -- non-object value of wrong type, fail.     parsejson _ = error "can't parse task yaml/json"  main =          ymldata <- bs.readfile "/tmp/test2.yaml"          let users = data.yaml.decode ymldata :: maybe [task]          -- print it, show          print $ fromjust users 

you need ... separate documents, so:

--- -   name: >         test task     state: finished  -   name: >         second test task     state: todo ... --- -   name: noname     state: nostate 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -