mirror of
https://github.com/boostorg/parser.git
synced 2026-01-22 17:32:35 +00:00
77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
/**
|
|
* Copyright (C) 2010, 2011, 2012 Object Modeling Designs
|
|
* consultomd.com
|
|
* Copyright (C) 2017 Zach Laine
|
|
*
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
*/
|
|
|
|
#include "../yaml/parser/yaml.hpp"
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
#include <boost/spirit/include/classic_position_iterator.hpp>
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Main program
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
int main(int argc, char **argv)
|
|
{
|
|
char const* filename = NULL;
|
|
if (argc > 1)
|
|
{
|
|
filename = argv[1];
|
|
}
|
|
else
|
|
{
|
|
std::cerr << "Error: No input file provided." << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
std::ifstream in(filename, std::ios_base::in);
|
|
|
|
if (!in)
|
|
{
|
|
std::cerr << "Error: Could not open input file: "
|
|
<< filename << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// Ignore the BOM marking the beginning of a UTF-8 file in Windows
|
|
char c = in.peek();
|
|
if (c == '\xef')
|
|
{
|
|
char s[4];
|
|
in >> s[0] >> s[1] >> s[2];
|
|
s[3] = '\0';
|
|
if (s != std::string("\xef\xbb\xbf"))
|
|
{
|
|
std::cerr << "Error: Unexpected characters from input file: "
|
|
<< filename << std::endl;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
using omd::yaml::ast::value_t;
|
|
namespace qi = boost::spirit::qi;
|
|
|
|
value_t result;
|
|
if (omd::yaml::parser::parse_yaml(in, result, filename))
|
|
{
|
|
std::cout << "success: \n";
|
|
|
|
// print the result (2-spaces indent with all aliases expanded)
|
|
omd::yaml::ast::print_yaml<2, true>(std::cout, result);
|
|
std::cout << std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout << "parse error" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|