Re: yaml-cpp and YAML 1.2

Andrey Somov <[email protected]> Thu, 3 Mar 2016 23:32:10 +0100
Newsgroups gmane.text.yaml.general
Message-ID <CALbkv0efei-Lb9R1u8wqSp=9-5EnOr7ko_z+xQVuQQ-gsWzMvg@mail.gmail.com>
The spec says:
Should The word *should*, or the adjective *recommended*, mean that there
could be reasons for a YAML processor
<http://www.yaml.org/spec/1.2/spec.html#processor//> to deviate from the
behavior described, but that such deviation could hurt interoperability and
should therefore be advertised with appropriate noticeWhich means that the
yaml-cpp should give the appropriate notice. Otherwise users may come with
wrong expectations (as I do).
(The project should say that the schemas are not supported)

Please do not confuse this with statically-typed language. (Java is also
statically-typed language)
Imagine you want to parse a configuration file. It is just a map<string,
T>. T can be integer, string and boolean. The parser should auto-magically
assign different values for different schemas.

BTW, one of my proposals for YAML 2.0 is to drop these schemas. It should
be strictly application-specific. As you do. It should be driven by the
context which is outside of the YAML document. Users should not expect
auto-magic from the parser.

Andrey

On Thu, Mar 3, 2016 at 10:53 PM, Jesse Beder <[email protected]> wrote:

> Ah, gotcha.
>
> Correct, yaml-cpp doesn't do this; no one has asked for it, and it struck
> me as less useful in a statically-typed language. Note that the spec uses
> the word "should", not "must", for Schemas.
>
> On Thu, Mar 3, 2016 at 3:44 PM, Andrey Somov <[email protected]>
> wrote:
>
>> Sorry, I will be more precise:
>>
>> YAML:Node should be parsed differently for the same document:
>> { a: true, b: 0x55 }
>>
>> Failsafe Schema => { !!str a: !!str true, !!str b: !!str 0x55 }
>>
>> JSON Schema => { !!str a: !!bool true, !!str b: !!str 0x55 }
>>
>> Core Schema => { !!str a: !!bool true, !!str b: !!int 0x55 }
>>
>> As you can see the tags should be different
>>
>> Andrey
>>
>> On Thu, Mar 3, 2016 at 10:35 PM, Jesse Beder <[email protected]> wrote:
>>
>>> yaml-cpp doesn't even get so far as saying definitively what "a" and "b"
>>> are. It parses it as: "a" and "b" are nodes with certain values and tags.
>>> It doesn't assign types to them because that's the job of the application.
>>>
>>> What would it even mean to say that "b" is an integer in C++? The only
>>> way you can get an integer is to write
>>>
>>> int b = ...
>>>
>>> In other words, node["b"] cannot have type "int" or "string" or anything
>>> other than YAML::Node.
>>>
>>> On Thu, Mar 3, 2016 at 3:16 PM, Andrey Somov <[email protected]>
>>> wrote:
>>>
>>>> YAML:Node should be parsed differently for the same document:
>>>> { a: true, b: 0x55 }
>>>>
>>>> Failsafe Schema => a and b are strings
>>>>
>>>> JSON Schema => a is boolean, b is string
>>>>
>>>> Core Schema => a is boolean, b is integer
>>>>
>>>> SnakeYAML implements (almost) everything except schemas.
>>>> That is why SnakeYAML says it only supports YAML 1.1
>>>> If we do not have to respect schemas than many more parsers may become
>>>> YAML 1.2 compliant.
>>>> JS-YAML does support schemas in its API.
>>>>
>>>> Cheers,
>>>> Andrey
>>>>
>>>> On Thu, Mar 3, 2016 at 9:11 PM, Jesse Beder <[email protected]> wrote:
>>>>
>>>>> The examples are here:
>>>>>
>>>>> https://github.com/jbeder/yaml-cpp/blob/master/test/specexamples.h
>>>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jbeder_yaml-2Dcpp_blob_master_test_specexamples.h&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=k0_S7vjNbEK3lfoTpRLHdSo404fP2giwHsXzgwMhUZo&s=iOczRD8wKG6Fb4kwEx5dU84FNAlhNBbAqX0MN-oMMDI&e=>
>>>>>
>>>>> and the tests are here:
>>>>>
>>>>>
>>>>> https://github.com/jbeder/yaml-cpp/blob/master/test/integration/handler_spec_test.cpp
>>>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jbeder_yaml-2Dcpp_blob_master_test_integration_handler-5Fspec-5Ftest.cpp&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=k0_S7vjNbEK3lfoTpRLHdSo404fP2giwHsXzgwMhUZo&s=0lmPGSCYU7BQHiYVVDbjLmJyUsC1aWo8ZDvPV74gpsg&e=>
>>>>>
>>>>> https://github.com/jbeder/yaml-cpp/blob/master/test/integration/node_spec_test.cpp
>>>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jbeder_yaml-2Dcpp_blob_master_test_integration_node-5Fspec-5Ftest.cpp&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=k0_S7vjNbEK3lfoTpRLHdSo404fP2giwHsXzgwMhUZo&s=GrPg-pjZuou6FFwNTNZ98Bi6ffqWgEOtSioD66xs89I&e=>
>>>>>
>>>>> As for parsing with schemas: what does it mean to parse with the JSON
>>>>> schema in C++? If I write
>>>>>
>>>>> X parsed = parseWithJsonSchema(...)
>>>>>
>>>>> what is the type of X? In yaml-cpp, the result of parsing is always
>>>>> YAML::Node, which then can be turned into any type you like statically.
>>>>>
>>>>> On Thu, Mar 3, 2016 at 9:48 AM, Andrey Somov <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Dear Jesse,
>>>>>> I looked in the source but I could not find the tests which take all
>>>>>> the examples form the specifications (as libyaml, PyYAML and SnakeYAML do).
>>>>>> Do you try to parse all the examples from the specification ?
>>>>>>
>>>>>> Cheers,
>>>>>> Andrey
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 2, 2016 at 6:26 PM, Andrey Somov <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> >Happy to answer any questions.
>>>>>>>
>>>>>>> >Because C++ is statically typed and has no initial class, I always
>>>>>>> viewed schema >as an application task. yaml-cpp lets you deserialize to any
>>>>>>> application-specific >type, but you have to ask statically, so automatic
>>>>>>> resolution seems less useful.
>>>>>>>
>>>>>>> Dear Jesse,
>>>>>>> I did not quite catch you. Java is also statically typed, but it is
>>>>>>> unrelated to Recommended Schemas.
>>>>>>> The YAML 1.2 spec requires that the user may select (as an option)
>>>>>>> to parse the very same document with different schemas. JS-yaml does have
>>>>>>> support for that (partially).
>>>>>>>
>>>>>>> If I want to apply JSON schema and use yaml-cpp what should I do ?
>>>>>>>
>>>>>>>
>>>>>>> (other questions follow :-)
>>>>>>> Cheers,
>>>>>>> Andrey
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------------------
>>>>>> Site24x7 APM Insight: Get Deep Visibility into Application Performance
>>>>>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>>>>>> Monitor end-to-end web transactions and take corrective actions now
>>>>>> Troubleshoot faster and improve end-user experience. Signup Now!
>>>>>> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
>>>>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__pubads.g.doubleclick.net_gampad_clk-3Fid-3D272487151-26iu-3D_4140&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=k0_S7vjNbEK3lfoTpRLHdSo404fP2giwHsXzgwMhUZo&s=pKLzAZMELaY6L2GbZMeTfxOJLHOVQMrnTUVwYSEhI0Y&e=>
>>>>>> _______________________________________________
>>>>>> Yaml-core mailing list
>>>>>> [email protected]
>>>>>> https://lists.sourceforge.net/lists/listinfo/yaml-core
>>>>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_yaml-2Dcore&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=k0_S7vjNbEK3lfoTpRLHdSo404fP2giwHsXzgwMhUZo&s=ypqrRfifi5e368iHi12MRjxJw4HZ03n_o1BU4moQGc4&e=>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Site24x7 APM Insight: Get Deep Visibility into Application Performance
>>>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>>>> Monitor end-to-end web transactions and take corrective actions now
>>>> Troubleshoot faster and improve end-user experience. Signup Now!
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
>>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__pubads.g.doubleclick.net_gampad_clk-3Fid-3D272487151-26iu-3D_4140&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=JuyEbKwzrG7rU23zzPIjFKLPan2Z194u9JJgOcZnIU0&s=qEQ-S_aTJ0Dobkb_7NKQ6lPqm30nOkZuAinToqelrKg&e=>
>>>> _______________________________________________
>>>> Yaml-core mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/yaml-core
>>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_yaml-2Dcore&d=BQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MTdCGdNVtXPX6PdqbNc8au-7Xx9X-p2GlN1e0U1iH9A&m=JuyEbKwzrG7rU23zzPIjFKLPan2Z194u9JJgOcZnIU0&s=qdTm_iXboAKu-eVLl6ePCdtfuNdSrf5ZXELm_j8AezE&e=>
>>>>
>>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Site24x7 APM Insight: Get Deep Visibility into Application Performance
>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>> Monitor end-to-end web transactions and take corrective actions now
>> Troubleshoot faster and improve end-user experience. Signup Now!
>> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
>> _______________________________________________
>> Yaml-core mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/yaml-core
>>
>>
>

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core