majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Emitter output is not valid Parser input #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Given a document with this text:

    z: &anchor a,
    a: *anchor

2. Parser.exe outputs:

    ---
    a: *anchor
    z: &anchor a,

3. Feeding the Parser.exe again with the output gives the following output:

    yaml-cpp: error at line 3, column 1: the referenced anchor is not defined

I'm using the 0.2.5 release.

This is probably caused because a std::map is used to store the nodes in a Map 
using operator< to ordem them.

Original issue reported on code.google.com by rsvar...@gmail.com on 25 Oct 2010 at 2:51

GoogleCodeExporter commented 9 years ago
This is actually fixed in the trunk. The current build (r423) emits:

   ---
   a: &1 a
   z: *1

(so it still reorders the map (which is allowed by the YAML spec), but it 
simply changes which is the anchor and which is the alias.)

Original comment by jbe...@gmail.com on 25 Oct 2010 at 3:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Nice!

I must ask, why the anchor is now beeing referenced by the number? Can I still 
get the original anchor name?

Original comment by rsvar...@gmail.com on 25 Oct 2010 at 8:35

GoogleCodeExporter commented 9 years ago
The original anchor name isn't part of the representation, so we get rid of it. 
This is a conscious decision - according to the YAML spec, you shouldn't rely 
on the anchor name for any meaning.

(That said, I do understand how you might want to specify the anchor name when 
emitting, so the general emitter allows you to specify anchor/alias names.)

Original comment by jbe...@gmail.com on 25 Oct 2010 at 9:11