kastnermario / yaml-cpp

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

Parser seems to require "..." at the end of each document #18

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using Windows/VS2008, I have tried to parse the following file, which
contains two documents:

---
x: 3
y: 4
z: 5

---
w: 6
q: 7
v: 8

At the occurrence of the second "---", I get a ParserException, with the
message "end of map not found", even though this is ostensibly legal YAML
1.2.  Instead, I expected the parser to parse the two documents contained
in the file.

The same problem occurs on Example 2.28 in the YAML 1.2 spec:

    http://yaml.org/spec/1.2/#id2562339

The problem appears to be caused in the Map::ParseBlock() function,
specifically in this snippet, which, after each key, does not expect a
TT_DOC_START.

    Token token = pScanner->peek();
    if(token.type != TT_KEY && token.type != TT_BLOCK_END)
        throw ParserException(token.line, token.column, ErrorMsg::END_OF_MAP);

    pScanner->pop();
    if(token.type == TT_BLOCK_END)
        break;

I plan to take a stab at fixing this over the next day or so and contribute
a patch, but I wanted also to run it by you, since I'm a YAML and yaml-cpp
noob.  Is there a reason why supporting multiple documents without the
"..." marker at the end of each document is desirable?

Thanks for your time.

Original issue reported on code.google.com by AlexThor...@gmail.com on 25 Jun 2009 at 12:56

GoogleCodeExporter commented 8 years ago
One more thing; I've tried this scenario with both Windows and Unix line 
endings.

Original comment by AlexThor...@gmail.com on 25 Jun 2009 at 12:57

GoogleCodeExporter commented 8 years ago
Thanks for the note! This actually is a bug, and I've committed the fix.

It turned out to be in Scanner::ScanDocStart, we needed to call PopIndentTo(-1) 
(this 
inserts the tokens TT_BLOCK_END appropriately); it was only popping to the 
indent 0, so 
it didn't pop the top-level map block off.

Original comment by jbe...@gmail.com on 25 Jun 2009 at 3:07

GoogleCodeExporter commented 8 years ago
Fantastic.  Thanks very much!

Original comment by AlexThor...@gmail.com on 25 Jun 2009 at 3:48