HsYAML
HsYAML copied to clipboard
Laziness of parser
If I do
case decode inp of
Right (opt :: Opt : _) -> doSomethingWith opt
Right [] -> oneKindOfError
Left (pos, err) -> anotherKindOfError
and inp
is something like
---
foo: bar
...
baz
then I get an error when it hits baz
, even though it can successfully parse the one YAML document I'm asking for. Is this expected? Could the parser be made lazier, so it returns the result after having parsed the first YAML document in the stream, and doesn't worry about the rest unless I ask for it?
Alternatively, could there be an option telling it to ignore non-YAML content after the first YAML document, if you just use decode1
?
Sorry, my question was ill-posed. I see why it can't be lazy if it's returning an Either value. I guess the real question is whether another function might be made available that lazily returns a list of YAML documents (with no error return values).
@jgm that's definitely possible; we could still report errors with a document granularity. i.e. something like (pseudo-code):
decodeDocsLazy :: ByteString -> YamlDocs
where
data YamlDocs = YamlDoc Doc YamlDocs
| YamlError ErrInfo