Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / util / parse.cpp
blobd02a76a78db917eed5897864f8fbad33fae1c033
1 #include "yaml-cpp/yaml.h"
2 #include "yaml-cpp/eventhandler.h"
3 #include <fstream>
4 #include <iostream>
5 #include <vector>
7 struct Params {
8 bool hasFile;
9 std::string fileName;
12 Params ParseArgs(int argc, char **argv) {
13 Params p;
15 std::vector<std::string> args(argv + 1, argv + argc);
17 return p;
20 class NullEventHandler: public YAML::EventHandler
22 public:
23 virtual void OnDocumentStart(const YAML::Mark&) {}
24 virtual void OnDocumentEnd() {}
26 virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
27 virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
28 virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
30 virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
31 virtual void OnSequenceEnd() {}
33 virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
34 virtual void OnMapEnd() {}
37 void parse(std::istream& input)
39 try {
40 YAML::Parser parser(input);
41 YAML::Node doc;
42 while(parser.GetNextDocument(doc)) {
43 YAML::Emitter emitter;
44 emitter << doc;
45 std::cout << emitter.c_str() << "\n";
47 } catch(const YAML::Exception& e) {
48 std::cerr << e.what() << "\n";
52 int main(int argc, char **argv)
54 Params p = ParseArgs(argc, argv);
56 if(argc > 1) {
57 std::ifstream fin;
58 fin.open(argv[1]);
59 parse(fin);
60 } else {
61 parse(std::cin);
64 return 0;