what should be returned if there's no value for a type

2 views
Skip to first unread message

mushishi

unread,
May 25, 2008, 12:03:47 PM5/25/08
to rby...@googlegroups.com
Hi guys,
Is there anyone could give me some suggestion about empty value
parsing?I can't find solution in YAML1.1 specification.

Here are some examples.
RbYAML.load("!!null")
RbYAML.load("!!str")
RbYAML.load("!!map")
RbYAML.load("!!seq")

In my opinion, it should return an empty instance of the certain type.
For the above examples, the results should be as follows.
nil
String.new
Hash.new
Array.new

In Syck, all statements will throw syntax error exceptions.
In jvyamlb,
load("!!null") and load("!!str") will return null.
load("!!map") and load("!!seq") will throw exceptions.

--
Kind Regards
spritesun

Xue Yong Zhi

unread,
May 25, 2008, 3:28:36 PM5/25/08
to rby...@googlegroups.com

I think if YAML1.1 specification does not say anything, it could make sense to follow whatever Syck does. After all, this is what most people use for ruby yaml parsing, and compatibility is a nice thing to have.

-yong

Ola Bini

unread,
May 25, 2008, 3:38:14 PM5/25/08
to rby...@googlegroups.com
Xue Yong Zhi wrote:
>
> I think if YAML1.1 specification does not say anything, it could make
> sense to follow whatever Syck does. After all, this is what most
> people use for ruby yaml parsing, and compatibility is a nice thing to
> have.
>
> -yong
>
>
I agree with Sycks behavior here. You can have an empty str
representation, and that makes sense. So does null. But empty maps and
sequences should be done using the inline style anyway.

Btw, I would assume that the example doesn't use !!null or !!str for
syck, since that doesn't work (it's not 1.0 compatible syntax)

Cheers
> On 5/25/08, *mushishi* <spri...@gmail.com

> <mailto:spri...@gmail.com>> wrote:
>
>
> Hi guys,
> Is there anyone could give me some suggestion about empty value
> parsing?I can't find solution in YAML1.1 specification.
>
> Here are some examples.
> RbYAML.load("!!null")
> RbYAML.load("!!str")
> RbYAML.load("!!map")
> RbYAML.load("!!seq")
>
> In my opinion, it should return an empty instance of the certain type.
> For the above examples, the results should be as follows.
> nil
> String.new
> Hash.new
> Array.new
>
> In Syck, all statements will throw syntax error exceptions.
> In jvyamlb,
> load("!!null") and load("!!str") will return null.
> load("!!map") and load("!!seq") will throw exceptions.
>


--
Ola Bini (http://ola-bini.blogspot.com)
JRuby Core Developer
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

"Yields falsehood when quined" yields falsehood when quined.


mushishi

unread,
May 25, 2008, 10:56:06 PM5/25/08
to rby...@googlegroups.com
Actually in syck, it should be "!null", "!str", "!map", "!seq". (Only
one exclamation mark before tag name.)

So I think the behavior should act as,
load("!!null") => nil
load("!!str") => "" # same as String.new
load("!!map") => throw exception
load("!!seq") => throw exception

Btw, what about load("")?
In syck, it return false,
In jvyamlb, it return null.
I prefer jvyamlb behavior here. It's really weird if return false.

--
Kind Regards
spritesun

Reply all
Reply to author
Forward
0 new messages