<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - YAML IO errors"
   href="http://llvm.org/bugs/show_bug.cgi?id=15505">15505</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>YAML IO errors
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rrankene@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm trying to parse a simple JSON file, and am having problems with using
YAMLIO.
Also note the unit test YAMLIOTest.cpp is disabled with a #if 0.

The JSON file yaml.json contains:
{
  "bool_test": true,
  "directory": ".",
  "suffix": "_test",
  "int_test": 4
}

The test program when run shows:

YAML:5:15: error: invalid number
  "int_test": 4
              ^~             // ^~ points to the 4
bool_test: true
save_directory: .",
  "suffix": "_test",
  "int_test": 4
}

save_suffix: _test",
  "int_test": 4
}

int_test: -627100365
Done

Note the strings are both incorrect - it can't seem to identify the proper
end of each string. And it ends up lost looking at the integer. Adding a ',' to
the end of the 4 allows the 4 to be properly found. The comma should not be
necessary.

The test code is:

#include <iostream>
#include <fstream>
#include "llvm/Support/YAMLTraits.h"

using namespace std;
using llvm::yaml::Input;
using llvm::yaml::MappingTraits;


//===-------------------------
---------------------------------------------===//
//  Test MappingTraits
//===----------------------------------------------------------------------===//

struct FooBar {
  bool boolTest;
  llvm::StringRef directory;
  llvm::StringRef suffix;
  int32_t intTest;
};
typedef std::vector<FooBar> FooBarSequence;

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FooBar> {
    static void mapping(IO &io, FooBar& fb) {
      io.mapRequired("bool_test", fb.boolTest);
      io.mapRequired("directory", fb.directory);
      io.mapRequired("suffix",    fb.suffix);
      io.mapRequired("int_test",  fb.intTest);
struct FooBar {
  bool boolTest;
  llvm::StringRef directory;
  llvm::StringRef suffix;
  int32_t intTest;
};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FooBar> {
    static void mapping(IO &io, FooBar& fb) {
      io.mapRequired("bool_test", fb.boolTest);
      io.mapRequired("directory", fb.directory);
      io.mapRequired("suffix",    fb.suffix);
      io.mapRequired("int_test",  fb.intTest);
    }
  };
}
}

int main()
{
  ifstream jsonFile("yaml.json");

  if (jsonFile.is_open())
  {
    // Read file into a string
    string jsonSource((istreambuf_iterator<char>(jsonFile)),
                       istreambuf_iterator<char>());

    jsonFile.close();

    FooBar doc;
    Input yin(jsonSource.c_str());
    yin >> doc;
    cout << "bool_test: " << (doc.boolTest ? "true" : "false") << endl;
    cout << "directory: " << doc.directory.data() << endl;
    cout << "suffix: "    << doc.suffix.data() << endl;
    cout << "int_test: "  << doc.intTest << endl;
    cout << "Done\n";
  }
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>