Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for document streams? #49

Open
ottawadeveloper opened this issue Nov 13, 2015 · 1 comment
Open

Support for document streams? #49

ottawadeveloper opened this issue Nov 13, 2015 · 1 comment

Comments

@ottawadeveloper
Copy link

Hi!

I love using Spyc for YAML parsing, but I have a question - was it intentional not to have multiple document support?

Background: As per http://yaml.org/spec/1.0/#id2489959 YAML streams can have multiple documents. For instance:


---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
  This is an error message
  for the log file

---
Time: 2001-11-23 15:02:31 -5
User: ed
Warning:
  A slightly different error
  message.
...

should result in two different YAML entries. Instead, I end up with:

array(4) {
  ["Time"]=>
  string(22) "2001-11-23 15:02:31 -5"
  ["User"]=>
  string(2) "ed"
  ["Warning"]=>
  array(2) {
    [0]=>
    string(26) "A slightly different error"
    [1]=>
    string(8) "message."
  }
  [0]=>
  string(3) "..."
}

Which is fine if we're never expecting multiple documents in the same stream, but it can cause problems if we are trying to use it in that fashion. Would you be interested in a patch that adds a new method or a flag for the load methods that causes them to become aware of documents?

I'm not sure if syck handles them or not either, but if they do then this would cause two different behaviours depending on whether or not syck is available.

@jackmcdade
Copy link
Collaborator

I think it's more common for YAML to be used for Front Matter these days, in which everything after the 2nd set of --- hyphens becomes Markdown or another form of text/markup. In that scenario, --- becomes an <hr>. Any solution for streams would have to take that into account as a default behavior.

Perhaps Spyc::YAMLLoadStream()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants