[LLVMbugs] [Bug 15505] New: YAML IO errors

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Mar 13 12:53:31 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15505

            Bug ID: 15505
           Summary: YAML IO errors
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: rrankene at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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";
  }
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130313/5eef2279/attachment.html>


More information about the llvm-bugs mailing list