majintao0131 / yaml-cpp

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

yaml fail to parse nodes, doesn't give clue why #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. use this yaml, without the ------- and ..... at start and end.

-------------

a:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
d:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
fds:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
fdsa:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
sa:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
jhf:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
ddd:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
dd222d:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
dd4444d:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
d555dd:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
dd777d:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:
ddd99:
    as:
        ad:
            ab:
            dsfdsdas:
            fggww:
            badaba:
            dsdsa:
            fdssd:
            fdssada:
        ad5:
            dada:
            dudu:
                gaga:
                budu:
        ad6:

.........................

2.

use this code:
    YAML::Parser parser(ifstream("test2.yml"));
    //YAML::Parser parser(ifstream("items9.yml"));
    YAML::Node doc;
    if(! parser.GetNextDocument(doc)) exit(0xbadf00d);

    vector<string> string_vector;// = getkeys(doc);
    for(auto it = doc.begin(); it != doc.end(); ++it)
    {
        string s;
        it.first() >> s;
        string_vector.push_back(s);
    }

    for(auto it = string_vector.begin(); it != string_vector.end(); ++it)
        cout << *it << "\n";

3. it doesn't get all nodes, I don't know why, it still is valid yaml

using 0.3.0, windows xp, visual C++ 10

I don't think it's caused by hash key collision, because the data I use in my 
app are common english words, and I have the same issue.

Original issue reported on code.google.com by ezjonas on 26 Mar 2012 at 10:56

GoogleCodeExporter commented 9 years ago
Could you please post the output you get from the code you posted?

Original comment by jbe...@gmail.com on 26 Mar 2012 at 4:33

GoogleCodeExporter commented 9 years ago
http://imgur.com/iTggx

Original comment by ezjonas on 26 Mar 2012 at 4:37

GoogleCodeExporter commented 9 years ago
Can you upload the file "test2.yml" so I can see exactly the bytes you're using?

Original comment by jbe...@gmail.com on 26 Mar 2012 at 5:09

GoogleCodeExporter commented 9 years ago

Original comment by ezjonas on 26 Mar 2012 at 5:25

Attachments:

GoogleCodeExporter commented 9 years ago
The line

YAML::Parser parser(ifstream("test2.yml"));

shouldn't actually compile. There is no constructor for YAML::Parser that takes 
a std::istream by value or reference-to-const; only by reference.

Instead, you should do something like

ifstream fin("test2.yml")
YAML::Parser parser(fin);

My best guess as to what's happening is that in the confusion that follows 
binding a temporary to a non-const reference, it only keeps the file stream 
open long enough to read one chunk of the file into memory, so you're only 
getting the first portion of the file.

Original comment by jbe...@gmail.com on 26 Mar 2012 at 7:19

GoogleCodeExporter commented 9 years ago
Oh, ok, well I'll fix it.

So why does it compile ? Isn't visual C++ not supposed to compiled it ?

Original comment by ezjonas on 26 Mar 2012 at 7:34

GoogleCodeExporter commented 9 years ago
That's right, Visual C++ should issue an error here. See

http://stackoverflow.com/questions/5032756/unforgiving-gcc-c-compiler

for more info.

Original comment by jbe...@gmail.com on 26 Mar 2012 at 8:00

GoogleCodeExporter commented 9 years ago
thanks

Original comment by ezjonas on 26 Mar 2012 at 8:03