From 14133d1954beaf672fc8f11ac5d826cea051a77a Mon Sep 17 00:00:00 2001 From: Zach Laine Date: Thu, 27 Apr 2017 20:34:51 -0500 Subject: [PATCH] Remove old parser cruft, and omd namespace. --- test/CMakeLists.txt | 4 +- test/basic_structures.cpp | 2 +- test/block.cpp | 20 - test/block_style.cpp | 2 +- test/characters.cpp | 2 +- test/flow.cpp | 24 - test/flow_style.cpp | 2 +- test/parse_yaml_round_trip_test.cpp | 12 +- test/parse_yaml_test.cpp | 6 +- test/scalar.cpp | 20 - test/stream.cpp | 2 +- test/yaml.cpp | 19 - yaml/ast.hpp | 11 +- yaml/detail/ast_impl.hpp | 11 +- yaml/detail/parse_impl.hpp | 4 +- yaml/parser/basic_structures.hpp | 4 +- yaml/parser/basic_structures_def.hpp | 4 +- yaml/parser/block.hpp | 165 ------ yaml/parser/block_def.hpp | 740 --------------------------- yaml/parser/block_styles.hpp | 4 +- yaml/parser/block_styles_def.hpp | 4 +- yaml/parser/characters.hpp | 4 +- yaml/parser/characters_def.hpp | 4 +- yaml/parser/error_handler.hpp | 11 +- yaml/parser/flow.hpp | 76 --- yaml/parser/flow_def.hpp | 266 ---------- yaml/parser/flow_styles.hpp | 4 +- yaml/parser/flow_styles_def.hpp | 4 +- yaml/parser/scalar.hpp | 86 ---- yaml/parser/scalar_def.hpp | 436 ---------------- yaml/parser/stream.hpp | 4 +- yaml/parser/stream_def.hpp | 4 +- yaml/parser/yaml.hpp | 71 --- yaml/parser/yaml_def.hpp | 168 ------ 34 files changed, 56 insertions(+), 2144 deletions(-) delete mode 100644 test/block.cpp delete mode 100644 test/flow.cpp delete mode 100644 test/scalar.cpp delete mode 100644 test/yaml.cpp delete mode 100644 yaml/parser/block.hpp delete mode 100644 yaml/parser/block_def.hpp delete mode 100644 yaml/parser/flow.hpp delete mode 100644 yaml/parser/flow_def.hpp delete mode 100644 yaml/parser/scalar.hpp delete mode 100644 yaml/parser/scalar_def.hpp delete mode 100644 yaml/parser/yaml.hpp delete mode 100644 yaml/parser/yaml_def.hpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4fd6ea5b..df44832a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,7 @@ add_executable( ) target_link_libraries(parse_test yaml gtest) target_compile_definitions(parse_test PRIVATE -DYAML_HEADER_ONLY=0) -#target_compile_definitions(parse_test PRIVATE -DBOOST_SPIRIT_DEBUG) # Uncomment to get verbose trace of Spirit parse. +target_compile_definitions(parse_test PRIVATE -DBOOST_SPIRIT_DEBUG) # Uncomment to get verbose trace of Spirit parse. if (clang_on_linux) target_link_libraries(parse_test c++) endif () @@ -37,7 +37,7 @@ add_executable( ) target_link_libraries(parse_round_trip_test yaml gtest) target_compile_definitions(parse_round_trip_test PRIVATE -DYAML_HEADER_ONLY=0) -target_compile_definitions(parse_round_trip_test PRIVATE -DBOOST_SPIRIT_DEBUG) # Uncomment to get verbose trace of Spirit parse. +#target_compile_definitions(parse_round_trip_test PRIVATE -DBOOST_SPIRIT_DEBUG) # Uncomment to get verbose trace of Spirit parse. endif() if (clang_on_linux) diff --git a/test/basic_structures.cpp b/test/basic_structures.cpp index 90fb6a46..4a47e2fa 100644 --- a/test/basic_structures.cpp +++ b/test/basic_structures.cpp @@ -16,4 +16,4 @@ typedef std::string::const_iterator base_iterator_type; typedef boost::spirit::classic::position_iterator iterator_type; -template struct omd::yaml::parser::basic_structures; +template struct yaml::parser::basic_structures; diff --git a/test/block.cpp b/test/block.cpp deleted file mode 100644 index aba2a0c2..00000000 --- a/test/block.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (C) 2011, 2012 Object Modeling Designs - * consultomd.com - * - * 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 -#include -#include -#include - -#include - -typedef std::string::const_iterator base_iterator_type; -typedef boost::spirit::classic::position_iterator - iterator_type; - -template struct omd::yaml::parser::block; diff --git a/test/block_style.cpp b/test/block_style.cpp index 46e8f793..887d37ae 100644 --- a/test/block_style.cpp +++ b/test/block_style.cpp @@ -16,4 +16,4 @@ typedef std::string::const_iterator base_iterator_type; typedef boost::spirit::classic::position_iterator iterator_type; -template struct omd::yaml::parser::block_styles; +template struct yaml::parser::block_styles; diff --git a/test/characters.cpp b/test/characters.cpp index 880fa931..e371d289 100644 --- a/test/characters.cpp +++ b/test/characters.cpp @@ -16,4 +16,4 @@ typedef std::string::const_iterator base_iterator_type; typedef boost::spirit::classic::position_iterator iterator_type; -template struct omd::yaml::parser::characters; +template struct yaml::parser::characters; diff --git a/test/flow.cpp b/test/flow.cpp deleted file mode 100644 index 755524ea..00000000 --- a/test/flow.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (C) 2011, 2012 Object Modeling Designs - * consultomd.com - * - * 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 -#include -#include -#include - -#include -#include - -#include - -typedef std::string::const_iterator base_iterator_type; -typedef boost::spirit::classic::position_iterator - iterator_type; - -template struct omd::yaml::parser::white_space; -template struct omd::yaml::parser::flow; diff --git a/test/flow_style.cpp b/test/flow_style.cpp index f7c05266..79812088 100644 --- a/test/flow_style.cpp +++ b/test/flow_style.cpp @@ -16,4 +16,4 @@ typedef std::string::const_iterator base_iterator_type; typedef boost::spirit::classic::position_iterator iterator_type; -template struct omd::yaml::parser::flow_styles; +template struct yaml::parser::flow_styles; diff --git a/test/parse_yaml_round_trip_test.cpp b/test/parse_yaml_round_trip_test.cpp index b4b5a7bb..4abc979e 100644 --- a/test/parse_yaml_round_trip_test.cpp +++ b/test/parse_yaml_round_trip_test.cpp @@ -25,9 +25,9 @@ TEST(parse, test_parse_yaml) std::ifstream & in = *in_ptr; - using omd::yaml::ast::value_t; - using omd::yaml::parser::parse_yaml; - using omd::yaml::ast::print_yaml; + using yaml::ast::value_t; + using yaml::parser::parse_yaml; + using yaml::ast::print_yaml; std::vector result; ASSERT_TRUE((parse_yaml(in, result, filename))) << "failed initial parse of " << filename; @@ -38,7 +38,7 @@ TEST(parse, test_parse_yaml) { std::stringstream expanded_once; - omd::yaml::ast::print_yaml<3, true>(expanded_once, result[0]); + yaml::ast::print_yaml<3, true>(expanded_once, result[0]); std::vector reparsed_once_result; bool const expanded_once_parse = parse_yaml(expanded_once, reparsed_once_result, filename + std::string("_expanded_once_string")); @@ -46,7 +46,7 @@ TEST(parse, test_parse_yaml) EXPECT_EQ(reparsed_once_result.size(), 1u); if (expanded_once_parse && reparsed_once_result.size() == 1u) { std::stringstream expanded_twice; - omd::yaml::ast::print_yaml<3, true>(expanded_twice, reparsed_once_result[0]); + yaml::ast::print_yaml<3, true>(expanded_twice, reparsed_once_result[0]); std::vector reparsed_twice_result; bool const expanded_twice_parse = parse_yaml(expanded_twice, reparsed_twice_result, filename + std::string("_expanded_twice_string")); @@ -60,7 +60,7 @@ TEST(parse, test_parse_yaml) { std::stringstream unexpanded; - omd::yaml::ast::print_yaml(unexpanded, result[0]); + yaml::ast::print_yaml(unexpanded, result[0]); std::vector reparsed_result; bool const unexpanded_parse = parse_yaml(unexpanded, reparsed_result, filename + std::string("_unexpanded_string")); diff --git a/test/parse_yaml_test.cpp b/test/parse_yaml_test.cpp index 8ad05f67..8f777697 100644 --- a/test/parse_yaml_test.cpp +++ b/test/parse_yaml_test.cpp @@ -25,9 +25,9 @@ TEST(parse, test_parse_yaml) std::ifstream & in = *in_ptr; - using omd::yaml::ast::value_t; - using omd::yaml::parser::parse_yaml; - using omd::yaml::ast::print_yaml; + using yaml::ast::value_t; + using yaml::parser::parse_yaml; + using yaml::ast::print_yaml; std::vector result; ASSERT_TRUE((parse_yaml(in, result, filename))) << "failed initial parse of " << filename; diff --git a/test/scalar.cpp b/test/scalar.cpp deleted file mode 100644 index a54dfd3d..00000000 --- a/test/scalar.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (C) 2011, 2012 Object Modeling Designs - * - * 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 -#include -#include -#include - -#include - -typedef std::string::const_iterator base_iterator_type; -typedef boost::spirit::classic::position_iterator - iterator_type; - -template struct omd::yaml::parser::unicode_string; -template struct omd::yaml::parser::scalar; diff --git a/test/stream.cpp b/test/stream.cpp index f9cac219..fdc3ede4 100644 --- a/test/stream.cpp +++ b/test/stream.cpp @@ -16,4 +16,4 @@ typedef std::string::const_iterator base_iterator_type; typedef boost::spirit::classic::position_iterator iterator_type; -template struct omd::yaml::parser::stream; +template struct yaml::parser::stream; diff --git a/test/yaml.cpp b/test/yaml.cpp deleted file mode 100644 index a7c89a39..00000000 --- a/test/yaml.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - * - * 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 -#include -#include -#include - -#include - -typedef std::string::const_iterator base_iterator_type; -typedef boost::spirit::classic::position_iterator - iterator_type; - -template struct omd::yaml::parser::yaml; diff --git a/yaml/ast.hpp b/yaml/ast.hpp index a40d8816..c8e9bf36 100644 --- a/yaml/ast.hpp +++ b/yaml/ast.hpp @@ -6,8 +6,8 @@ * 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) */ -#ifndef OMD_YAML_AST_VALUE_HPP -#define OMD_YAML_AST_VALUE_HPP +#ifndef YAML_AST_VALUE_HPP +#define YAML_AST_VALUE_HPP #include #include @@ -17,8 +17,8 @@ #include -namespace omd { namespace yaml { namespace ast -{ +namespace yaml { namespace ast { + // ------------------- AST types -------------------- // typedef std::string string_t; @@ -168,7 +168,8 @@ namespace omd { namespace yaml { namespace ast { return print_yaml<2, false>(out, val); } // --------------------------------------------------- -}}} + +} } #include diff --git a/yaml/detail/ast_impl.hpp b/yaml/detail/ast_impl.hpp index f85e6290..9bec4688 100644 --- a/yaml/detail/ast_impl.hpp +++ b/yaml/detail/ast_impl.hpp @@ -6,8 +6,8 @@ * 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) */ -#ifndef OMD_AST_VALUE_IMPL_HPP -#define OMD_AST_VALUE_IMPL_HPP +#ifndef AST_VALUE_IMPL_HPP +#define AST_VALUE_IMPL_HPP #include @@ -20,8 +20,8 @@ #include -namespace omd { namespace yaml { namespace ast -{ +namespace yaml { namespace ast { + namespace detail { struct depth_f @@ -677,6 +677,7 @@ namespace omd { namespace yaml { namespace ast boost::apply_visitor(f, val.get()); return out; } -}}} + +} } #endif diff --git a/yaml/detail/parse_impl.hpp b/yaml/detail/parse_impl.hpp index 9cb20eed..c4505107 100644 --- a/yaml/detail/parse_impl.hpp +++ b/yaml/detail/parse_impl.hpp @@ -11,7 +11,7 @@ #include #define PARSE_YAML_IMPLEMENTATION() \ -namespace omd { namespace yaml { namespace parser { \ +namespace yaml { namespace parser { \ \ bool parse_yaml( \ std::istream & is, \ @@ -43,7 +43,7 @@ namespace omd { namespace yaml { namespace parser { \ return retval; \ } \ \ -} } } +} } #if YAML_HEADER_ONLY PARSE_YAML_IMPLEMENTATION() diff --git a/yaml/parser/basic_structures.hpp b/yaml/parser/basic_structures.hpp index fb849d9c..8d72220a 100644 --- a/yaml/parser/basic_structures.hpp +++ b/yaml/parser/basic_structures.hpp @@ -11,7 +11,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { template struct basic_structures @@ -54,6 +54,6 @@ namespace omd { namespace yaml { namespace parser { qi::rule anchor_name; }; -} } } +} } #endif diff --git a/yaml/parser/basic_structures_def.hpp b/yaml/parser/basic_structures_def.hpp index db893ad8..1b2dfda6 100644 --- a/yaml/parser/basic_structures_def.hpp +++ b/yaml/parser/basic_structures_def.hpp @@ -15,7 +15,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { namespace detail { @@ -257,6 +257,6 @@ namespace omd { namespace yaml { namespace parser { ); } -} } } +} } #endif diff --git a/yaml/parser/block.hpp b/yaml/parser/block.hpp deleted file mode 100644 index b6961486..00000000 --- a/yaml/parser/block.hpp +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - * consultomd.com - * - * 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) - */ - -#if !defined(OMD_PARSER_BLOCK_HPP) -#define OMD_PARSER_BLOCK_HPP - -#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS - -#include -#include -#include - - -namespace omd { namespace yaml { namespace parser { - - enum class chomping_t { - strip, clip, keep - }; - -#ifdef BOOST_SPIRIT_DEBUG - inline std::ostream & operator<< (std::ostream & os, chomping_t c) - { - switch (c) { - case chomping_t::strip: return os << "strip"; - case chomping_t::clip: return os << "clip"; - case chomping_t::keep: return os << "keep"; - } - return os; - } -#endif - - enum class context_t { - block_in, block_out, - flow_in, flow_out, - block_key, flow_key - }; - -#ifdef BOOST_SPIRIT_DEBUG - inline std::ostream & operator<< (std::ostream & os, context_t c) - { - switch (c) { -#define CASE(x) case context_t::x: return os << #x - CASE(block_in); CASE(block_out); - CASE(flow_in); CASE(flow_out); - CASE(block_key); CASE(flow_key); -#undef CASE - } - return os; - } -#endif - - struct block_header_t - { - block_header_t () - : indentation_ (0), chomping_ (chomping_t::clip) - {} - block_header_t (int indentation, chomping_t chomping) - : indentation_ (indentation), chomping_ (chomping) - {} - - int indentation_; - chomping_t chomping_; - -#ifdef BOOST_SPIRIT_DEBUG - inline friend std::ostream & operator<< (std::ostream & os, block_header_t b) - { return os << b.indentation_ << ',' << b.chomping_; } -#endif - }; - - template - struct block : qi::grammar - { - block(std::string const& source_file = ""); - - typedef white_space white_space_t; - typedef flow flow_t; - - qi::symbols anchors; - white_space_t ws; - qi::rule end_of_input; - - qi::rule block_node; - qi::rule anchored_block_node; - qi::rule indented_block; - qi::rule compact_block; - flow_t flow_g; - - qi::rule indent_; - qi::rule skip_indent; - qi::rule skip_indent_child; - qi::rule start; - qi::rule > blocks; - qi::rule > flow_compound; - - qi::rule > block_literal; - qi::rule block_seq; - qi::rule block_seq_entry; - qi::rule implicit_block_map; - qi::rule explicit_block_map; - qi::rule block_map_entry; - qi::rule explicit_block_map_entry; - qi::rule implicit_block_map_entry; - - int current_indent; // our current indent level (spaces) - - qi::rule indent; // indent exactly n spaces - qi::rule indent_lt; // indent <= n spaces - qi::rule indent_le; // indent < n spaces - - qi::rule line_prefix; - qi::rule l_empty; - qi::rule b_l_folded; - - qi::rule< - Iterator, - block_header_t(), - qi::locals - > block_header; - - qi::rule indentation_indicator; - qi::rule chomping_indicator; - qi::rule chomped_empty; - qi::rule strip_empty; - qi::rule keep_empty; - qi::rule trail_comments; - - qi::rule< - Iterator, - std::string(int), - qi::locals - > literal; - - qi::rule l_nb_literal_text; - qi::rule b_nb_literal_text; - qi::rule literal_content; - - qi::rule< - Iterator, - std::string(int), - qi::locals - > folded; - - qi::rule folded_text; - qi::rule folded_lines; - qi::rule spaced_text; - qi::rule spaced; - qi::rule spaced_lines; - qi::rule same_lines; - qi::rule diff_lines; - qi::rule folded_content; - - int n_; // our current indent level (spaces) - - typedef omd::yaml::parser::error_handler error_handler_t; - boost::phoenix::function const error_handler; - }; - -} } } - -#endif diff --git a/yaml/parser/block_def.hpp b/yaml/parser/block_def.hpp deleted file mode 100644 index 52248c25..00000000 --- a/yaml/parser/block_def.hpp +++ /dev/null @@ -1,740 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - * 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) - */ - -#if !defined(OMD_PARSER_BLOCK_DEF_HPP) -#define OMD_PARSER_BLOCK_DEF_HPP - -#include - -#include -#include -#include -#include -#include - -#include - - -// For debugging: -#if defined(BOOST_SPIRIT_DEBUG) -#define PRINT_INDENT \ -[ std::cerr << phx::val("\n============================") << get_indent << std::endl ] -#else -#define PRINT_INDENT -#endif - -namespace omd { namespace yaml { namespace parser { - - namespace detail { - - struct update_indent - { - template - struct result { typedef void type; }; - - template - void operator()( - Range const& rng, // <-- where we are now - int& current_indent, // <-- the current indent position - Pass& pass // <-- set to false to fail parsing - ) const - { - int pos = rng.begin().get_position().column; - if (pos >= current_indent) - current_indent = pos; - else - pass = false; - } - }; - - struct check_indent - { - template - struct result { typedef void type; }; - - template - void operator()( - Range const& rng, // <-- where we are now - int const& current_indent, // <-- the current indent position - Pass& pass // <-- set to false to fail parsing - ) const - { - int pos = rng.begin().get_position().column; - if (pos < current_indent) - pass = false; - } - }; - - struct fold_line - { - template - struct result { typedef void type; }; - - template - void operator()( - String& result_, - Range const& rng, - char indicator, - bool different_indentation - ) const - { - if (rng.empty()) - return; - - typedef typename std::iterator_traits::difference_type distance_t; - - distance_t n = std::distance(rng.begin(), rng.end()); - - // Don't fold the previous lines if the next line has a different indentation - if ((indicator == '>') && different_indentation) - { - for (distance_t i = 0; i != n; ++i) - result_ += '\n'; - return; - } - - if ((indicator == '>') && (n == 1)) - result_ += ' '; - else - result_ += '\n'; - } - }; - - struct chomp_string - { - template - struct result { typedef void type; }; - - template - void operator()(String& result_, char indicator) const - { - if (indicator == '-' || indicator == 0) - { - std::size_t pos = result_.size(); - for (; pos != 0; --pos) - { - if (result_[pos-1] != '\n') - break; - } - if (pos < result_.size()) - { - if (indicator == '-') - result_.erase(pos); - else - result_.erase(pos+1); - } - } - } - }; - - struct chomping - { - template - struct result { typedef chomping_t type; }; - - chomping_t operator() (block_header_t block_header) const - { return block_header.chomping_; } - }; - - struct indentation - { - template - struct result { typedef int type; }; - - int operator() (block_header_t block_header) const - { return block_header.indentation_; } - }; - - struct seq_spaces - { - template - struct result { typedef int type; }; - - int operator() (int n, context_t c) const - { return c == context_t::block_out ? n - 1 : n; } - }; - - } - - template - block::block(std::string const& source_file) - : block::base_type(start), - flow_g(current_indent, anchors), - current_indent(-1), - n_(-1), - error_handler(error_handler_t(source_file)) - { - namespace phx = boost::phoenix; - using boost::spirit::qi::copy; - phx::function update_indent; - phx::function check_indent; - phx::function fold_line; - phx::function chomp_string; - phx::function::adder> add_anchor(anchors.add); - - phx::function chomping; - phx::function indentation; - phx::function seq_spaces; // [201] - using phx::ref; - - using phx::construct; - - qi::skip_type skip; - auto space = ws.start.alias(); - - qi::_val_type _val; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_b_type _b; - qi::_c_type _c; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::char_type char_; - qi::lit_type lit; - - qi::repeat_type repeat; - qi::omit_type omit; - qi::_pass_type _pass; - qi::eps_type eps; - qi::attr_type attr; - qi::raw_type raw; - - qi::eol_type eol; - qi::eoi_type eoi_; - qi::blank_type blank; - qi::digit_type digit; - - auto comment = copy('#' >> *(char_ - eol) >> eol); // comments - auto blank_eol = copy(*blank >> (comment | eol)); // empty until eol - - auto & nb_char = flow_g.scalar_value.string_value.nb_char; - auto & ns_char = flow_g.scalar_value.string_value.ns_char; - auto & separate = flow_g.scalar_value.string_value.separate; - - auto map_key = copy( - skip(space)[flow_g.scalar_value.map_key] - ); - - // no-skip version without strings - auto flow_scalar_ns = - flow_g.scalar_value.scalar_value_no_strings.alias() - ; - - // Only for strings - auto& flow_string_ns = - flow_g.scalar_value.string_value - ; - - auto get_indent = - ref(current_indent) - ; - - auto save_indent = copy( - eps[_a = get_indent] PRINT_INDENT - ); - - auto zero_indent = copy( - eps[_a = get_indent, get_indent = 0] PRINT_INDENT - ); - - auto increase_indent = copy( - eps[get_indent += 1] PRINT_INDENT - ); - - auto decrease_indent = copy( - eps[get_indent -= 1] PRINT_INDENT - ); - - auto restore_indent = copy( - eps[get_indent = _a] PRINT_INDENT - ); - - indent_ = - *blank >> raw[eps] [update_indent(_1, get_indent, _pass)] - ; - - skip_indent = - *blank >> raw[eps] [check_indent(_1, get_indent, _pass)] - ; - - auto skip_exact_indent = copy( - repeat(get_indent-1)[blank] // note: indent is one based! - ); - - skip_indent_child = - *blank >> raw[eps] [check_indent(_1, get_indent + 1, _pass)] - ; - - end_of_input = - omit[ - -('#' >> *(char_ - eoi_)) // allow comments at the very end - >> eoi_ - ]; - - // Allow newlines before scalars as long as they are properly indented. - // Make sure that the scalar doesn't span multiple lines by requiring - // the next line to be a higher level node (with lower indentation). - // We'll deal with strings and potentially multi-line strings separately. - - auto scalar_in_block = copy( - omit[-(+blank_eol >> skip_indent_child)] - >> flow_scalar_ns - >> !(+blank_eol >> skip_indent_child) - ); - - // Allow newlines before strings as long as they are properly indented - auto string_in_block = copy( - omit[-(+blank_eol >> skip_indent_child)] - >> flow_string_ns - ); - - // flow compound (arrays and maps) need no indentations. Set indent to - // zero while parsing. - flow_compound %= - zero_indent - >> (skip(space)[flow_g.flow_node] | !restore_indent) - >> restore_indent - ; - - block_node = - compact_block - | indented_block - | flow_compound - | scalar_in_block - | string_in_block - | (omit[blank_eol | end_of_input] // If all else fails, then null_t - >> attr(ast::null_t())) - ; - - anchored_block_node %= - '&' - >> (+~char_(" \n\r\t,{}[]")) [ add_anchor(_1) ] - >> omit[blank | &eol] - >> block_node - ; - - auto block_node_main = copy( - anchored_block_node - | block_node - ); - - indented_block %= - increase_indent - >> (blocks | !decrease_indent) - >> decrease_indent - ; - - compact_block = - !blank_eol - >> blocks - ; - - auto block_main = copy( - block_literal - | block_seq - | explicit_block_map - | implicit_block_map - ); - - blocks %= - omit[*blank_eol] - >> save_indent - >> (block_main | !restore_indent) - >> restore_indent - ; - - start %= - blocks - - // YAML allows bare top-level scalars. Allow this, but set - // the indent to 1 to require unquoted strings to be indented, - // otherwise, unquoted strings will gobble up too much in - // its path. - | eps[get_indent = 1] >> skip(space)[flow_g.scalar_value] - ; - - auto start_indent = copy( - omit[indent_] PRINT_INDENT - ); - - auto block_literal_first_line = copy( - raw[*eol] [ fold_line(_val, _1, _a, false) ] - >> start_indent // Get first line indent - >> +(char_ - eol) [ _val += _1 ] // Get the line - ); - - // This rule checks for blank lines and sets local _c to true or false - // depending on whether the succeeding line has a different indentation or not - auto block_literal_blank_lines = copy( - raw[(*eol) - >> &-(skip_exact_indent >> blank) [ _c = true ] - >> -(!skip_exact_indent) [ _c = true ] - ][ fold_line(_val, _1, _a, _c) ] - ); - - // This rule checks if the current line is indented or not and - // sets local _c accordingly - auto block_literal_indented_line = copy( - &(blank[ _c = true ] | eps[ _c = false ]) - ); - - auto block_literal_line = copy( - block_literal_blank_lines - >> skip_exact_indent // Indent get_indent spaces - >> block_literal_indented_line - >> +(char_ - eol) [ _val += _1 ] // Get the line - ); - - block_literal = - (*blank) [ _c = false, _b = 0 ] // initialize locals - >> char_("|>") [ _a = _1 ] // get indicator in local _a - >> -char_("+-") [ _b = _1 ] // get the (optional) chomping indicator - >> *blank >> blank_eol - >> block_literal_first_line - >> *block_literal_line - >> eps [ chomp_string(_val, _b) ] - ; - - auto block_seq_indicator = copy( // Lookahead and see if we have a - &(start_indent >> '-' >> (blank | eol)) // sequence indicator. - ); - - block_seq = - omit[block_seq_indicator] - >> +block_seq_entry // Get the entries - ; - - block_seq_entry = - omit[*blank_eol] // Ignore blank lines - >> omit[skip_indent] // Indent get_indent spaces - >> omit['-' >> (blank | &eol)] // Get the sequence indicator '-' - >> block_node_main // Get the entry - ; - - auto implicit_block_map_indicator = copy( // Lookahead and see if we have an - &( start_indent // implicit map indicator. - >> map_key - >> skip(space)[':'] - )); - - implicit_block_map = - omit[implicit_block_map_indicator] - >> +block_map_entry // Get the entries - ; - - auto explicit_block_map_indicator = copy( // Lookahead and see if we have an - &(start_indent >> '?' >> (blank | eol)) // explicit map indicator. - ); - - explicit_block_map = - omit[explicit_block_map_indicator] - >> +block_map_entry // Get the entries - ; - - block_map_entry = - explicit_block_map_entry - | implicit_block_map_entry - ; - - implicit_block_map_entry = - omit[*blank_eol] // Ignore blank lines - >> omit[skip_indent] // Indent get_indent spaces - >> map_key // Get the key - >> omit[skip(space)[':']] // Get the map indicator ':' - >> omit[*blank] // Ignore blank spaces - >> block_node_main // Get the value - ; - - explicit_block_map_entry = - omit[*blank_eol] // Ignore blank lines - >> omit[skip_indent] // Indent get_indent spaces - >> omit['?' >> (blank | &eol)] // Get the map-key indicator '?' - >> map_key // Get the key - - >> omit[*blank_eol] // Ignore blank lines - >> omit[skip_indent] // Indent get_indent spaces - >> omit[':' >> (blank | &eol)] // Get the map-value indicator ':' - >> block_node_main // Get the value - ; - - // [63] - indent = - repeat(_r1)[lit(' ')] - ; - - // [64] - indent_lt = - repeat(0, _r1 - 1)[lit(' ')] - ; - - // [65] - indent_le = - repeat(0, _r1)[lit(' ')] - ; - - // [67] - line_prefix = - indent(_r1) - >> eps(_r2 == context_t::flow_in || _r2 == context_t::flow_out) >> -separate - ; - - // [70] - l_empty = - (line_prefix(_r1, _r2) | indent_lt(_r1)) - >> eol - ; - - b_l_folded = - eol >> +l_empty(_r1, _r2) // b-l-trimmed [71] - | eol - ; - - // 8.1 Block Scalar Styles - - // [162] - block_header = ( - indentation_indicator[_a = _1] >> +blank >> chomping_indicator[_b = _1] - | chomping_indicator[_b = _1] >> +blank >> indentation_indicator[_a = _1] - ) - >> blank_eol - [_val = construct(_a, _b)] - ; - - // [163] - // TODO: For round-tripping, a number like this must sometimes be - // placed in the output (as in, when a scalar has leading spaces) - indentation_indicator = - digit[_val = _1 - 0x30] - | eps[_val = 0] - ; - - // [164] - chomping_indicator = - lit('-')[_val = chomping_t::strip] - | lit('+')[_val = chomping_t::keep] - | eps[_val = chomping_t::clip] - ; - - // [166] - chomped_empty = - eps(_r2 == chomping_t::keep) >> keep_empty(_r1) - | strip_empty(_r1) - ; - - // [167] - strip_empty = - *(indent_le(_r1) >> eol) - >> -trail_comments(_r1) - ; - - // [168] - keep_empty = - *l_empty(_r1, context_t::block_in) - >> -trail_comments(_r1) - ; - - // [169] - trail_comments = - indent_lt(_r1) - >> '#' >> *nb_char >> eol - >> *blank_eol - ; - - // 8.1.2. Literal Style - - // [170] TODO: Get rid of these Phoenix functions -- just use - // block_header _1 and _2! - literal = - '|' - >> block_header[_a = _r1 + indentation(_1), _b = chomping(_1)] - >> literal_content(_a, _b)[_val = _1] - ; - - // [171] - l_nb_literal_text = - *l_empty(_r1, context_t::block_in) >> indent(_r1) >> +nb_char - ; - - // [172] - b_nb_literal_text = - eol >> l_nb_literal_text(_r1) - ; - - // [173] - literal_content = - -(l_nb_literal_text(_r1) >> *b_nb_literal_text(_r1) >> eol) - >> chomped_empty(_r1, _r2) - ; - - // 8.1.3. Folded Style - - // [174] - folded = - '>' - >> block_header[_a = _r1 + indentation(_1), _b = chomping(_1)] - >> folded_content(_a, _b)[_val = _1] - ; - - // [175] - folded_text = - indent(_r1) >> ns_char >> *nb_char - ; - - // [176] - folded_lines = - folded_text(_r1) >> *(b_l_folded(_r1, context_t::block_in) >> folded_text(_r1)) - ; - - // [177] - spaced_text = - indent(_r1) >> blank >> *nb_char - ; - - // [178] - spaced = - eol >> *l_empty(_r1, context_t::block_in) - ; - - // [179] - spaced_lines = - spaced_text(_r1) >> *(spaced(_r1) >> spaced_text(_r1)) - ; - - // [180] - same_lines = - *l_empty(_r1, context_t::block_in) - >> (folded_lines(_r1) | spaced_lines(_r1)) - ; - - // [181] - diff_lines = - same_lines(_r1) >> *(eol >> same_lines(_r1)) - ; - - // [182] - folded_content = - -(diff_lines(_r1) >> eol) - >> chomped_empty(_r1, _r2) - ; - -#if 0 - // 8.2.1. Block Sequences - - auto_detect_indent = - eps[_val = 0] >> &(*lit(' ')[++_val]) - ; - - // [183] - block_sequence = - auto_detect_indent[_a = _1] - >> +(indent(_a) >> block_seq_entry(_a)) - ; - - // [184] - block_seq_entry = - '-' >> !ns_char - >> block_indented(_r1, context_t::block_in) - ; - - // [185] - block_indented = - indent - ; -#endif - -#if 0 - // 8.2.3. Block Nodes - - // [196] - block_node = - block_in_block(_r1, _r2) | flow_in_block(_r1) - ; - - // [197] - flow_in_block = - separate(_r1 + 1, context_t::flow_out) - >> flow_node/*TODO (_r1 + 1, context_t::flow_out)*/ - >> s_l_comments - ; - - // [198] - block_in_block = - block_scalar(_r1, _r2) | block_collection(_r1, _r2) - ; - - // [199] - block_scalar = - separate(_r1 + 1, _r2) - >> -(properties(_r1 + 1, _r2) >> separate(_r1 + 1, _r2)) - >> (literal(_r1) | folded(_r1)) - ; - - // [200] - block_collection = - -(separate(_r1 + 1, _r2) >> properties(_r1 + 1, _r2)) - >> s_l_comments - >> (block_sequence(seq_spaces(_r1, _r2)) | block_mapping(_r1)) - ; -#endif - - BOOST_SPIRIT_DEBUG_NODES( - (indent) - (indent_lt) - (indent_le) - (line_prefix) - (l_empty) - (b_l_folded) - (block_header) - (indentation_indicator) - (chomping_indicator) - (chomped_empty) - (strip_empty) - (keep_empty) - (trail_comments) - (literal) - (l_nb_literal_text) - (b_nb_literal_text) - (literal_content) - (folded) - (folded_text) - (folded_lines) - (spaced_text) - (spaced) - (spaced_lines) - (same_lines) - (diff_lines) - (folded_content) - ); - - BOOST_SPIRIT_DEBUG_NODES( - (end_of_input) - (block_node) - (anchored_block_node) - (indented_block) - (compact_block) - (blocks) - (block_literal) - (block_seq) - (block_seq_entry) - (implicit_block_map) - (implicit_block_map_entry) - (block_map_entry) - (explicit_block_map) - (explicit_block_map_entry) - (indent) - ); - - qi::on_error(blocks, error_handler(_1, _2, _3, _4)); - } - -} } } - -#endif diff --git a/yaml/parser/block_styles.hpp b/yaml/parser/block_styles.hpp index 29d074b1..62022d2b 100644 --- a/yaml/parser/block_styles.hpp +++ b/yaml/parser/block_styles.hpp @@ -11,7 +11,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { enum class chomping_t { strip, clip, keep @@ -115,6 +115,6 @@ namespace omd { namespace yaml { namespace parser { qi::rule block_collection; }; -} } } +} } #endif diff --git a/yaml/parser/block_styles_def.hpp b/yaml/parser/block_styles_def.hpp index 10f75eb1..4ce7bacf 100644 --- a/yaml/parser/block_styles_def.hpp +++ b/yaml/parser/block_styles_def.hpp @@ -17,7 +17,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { namespace detail { @@ -382,6 +382,6 @@ namespace omd { namespace yaml { namespace parser { ); } -} } } +} } #endif diff --git a/yaml/parser/characters.hpp b/yaml/parser/characters.hpp index c3699302..360936e6 100644 --- a/yaml/parser/characters.hpp +++ b/yaml/parser/characters.hpp @@ -20,7 +20,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; @@ -85,6 +85,6 @@ namespace omd { namespace yaml { namespace parser { qi::rule esc_char; }; -} } } +} } #endif diff --git a/yaml/parser/characters_def.hpp b/yaml/parser/characters_def.hpp index 85d7171d..65b12f44 100644 --- a/yaml/parser/characters_def.hpp +++ b/yaml/parser/characters_def.hpp @@ -17,7 +17,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { namespace detail { @@ -169,6 +169,6 @@ namespace omd { namespace yaml { namespace parser { ); } -} } } +} } #endif diff --git a/yaml/parser/error_handler.hpp b/yaml/parser/error_handler.hpp index 1421ba48..1b0f2838 100644 --- a/yaml/parser/error_handler.hpp +++ b/yaml/parser/error_handler.hpp @@ -6,8 +6,8 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#if !defined(OMD_COMMON_ERROR_HANDLER_HPP) -#define OMD_COMMON_ERROR_HANDLER_HPP +#ifndef COMMON_ERROR_HANDLER_HPP +#define COMMON_ERROR_HANDLER_HPP #include #include @@ -15,8 +15,8 @@ #include #include -namespace omd { namespace yaml { namespace parser -{ +namespace yaml { namespace parser { + template struct error_handler { @@ -70,6 +70,7 @@ namespace omd { namespace yaml { namespace parser std::cerr << "^_" << std::endl; } }; -}}} + +} } #endif diff --git a/yaml/parser/flow.hpp b/yaml/parser/flow.hpp deleted file mode 100644 index abc1f30c..00000000 --- a/yaml/parser/flow.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2010, 2011, 2012 Object Modeling Designs - * consultomd.com - * - * 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) - */ - -#if !defined(OMD_PARSER_FLOW_HPP) -#define OMD_PARSER_FLOW_HPP - -#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS - -#include -#include - -namespace omd { namespace yaml { namespace parser -{ - template - struct white_space : qi::grammar - { - white_space(); - qi::rule start; - }; - - template - struct flow : qi::grammar > - { - flow( - int& indent, - qi::symbols& anchors, - std::string const& source_file = ""); - - using white_space_t = white_space; - - using object_element_rule_locals_t = qi::rule< - Iterator, - ast::object_element_t(), - qi::locals, - white_space_t - >; - - qi::rule flow_sequence; - qi::rule flow_seq_entries; - qi::rule flow_seq_entry; - qi::rule flow_mapping; - qi::rule flow_map_entries; - qi::rule flow_map_entry; - qi::rule flow_map_explicit_entry; - qi::rule flow_map_implicit_entry; - object_element_rule_locals_t flow_map_yaml_key_entry; - qi::rule flow_map_empty_key_entry; - qi::rule flow_map_separate_value; - object_element_rule_locals_t flow_map_json_key_entry; - qi::rule flow_map_adjacent_value; - qi::rule flow_pair; - qi::rule flow_pair_entry; - object_element_rule_locals_t flow_pair_yaml_key_entry; - qi::rule flow_pair_json_key_entry; - qi::rule implicit_yaml_key; - qi::rule implicit_json_key; - qi::rule flow_yaml_content; - qi::rule flow_json_content; - qi::rule flow_content; - qi::rule flow_yaml_node; - qi::rule flow_json_node; - qi::rule flow_node; - - scalar scalar_value; - - typedef omd::yaml::parser::error_handler error_handler_t; - boost::phoenix::function const error_handler; - }; -}}} - -#endif diff --git a/yaml/parser/flow_def.hpp b/yaml/parser/flow_def.hpp deleted file mode 100644 index efe9989a..00000000 --- a/yaml/parser/flow_def.hpp +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Copyright (C) 2010, 2011, 2012 Object Modeling Designs - * consultomd.com - * - * 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) - */ - -#if !defined(OMD_PARSER_FLOW_DEF_HPP) -#define OMD_PARSER_FLOW_DEF_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace omd { namespace yaml { namespace parser { - - template - white_space::white_space() - : white_space::base_type(start) - { - qi::char_type char_; - qi::eol_type eol; - qi::space_type space; - - start = - space // tab/space/cr/lf - | '#' >> *(char_ - eol) >> eol // comments - ; - } - - template - flow::flow( - int& indent, - qi::symbols& anchors, - std::string const& source_file) - : flow::base_type(flow_node), - scalar_value(indent, anchors), - error_handler(error_handler_t(source_file)) - { - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_b_type _b; - qi::_val_type _val; - qi::char_type char_; - qi::lit_type lit; - qi::eps_type eps; - qi::omit_type omit; - qi::no_skip_type no_skip; - using qi::as; - - namespace phx = boost::phoenix; - auto ins = phx::insert(_val, _1); - phx::function::adder> add_anchor(anchors.add); - using boost::phoenix::construct; - - auto & separate = scalar_value.string_value.separate; - auto & plain_safe = scalar_value.string_value.plain_safe; - auto & plain = scalar_value.string_value.unquoted; - auto & single_quoted = scalar_value.string_value.single_quoted; - auto & double_quoted = scalar_value.string_value.double_quoted; - - auto & alias_node = scalar_value.alias_node; - auto & properties = scalar_value.properties; - - // 7.4.1 Flow Sequences - - // [137] - flow_sequence = - '[' >> -flow_seq_entries >> ']' - ; - - // [138] - flow_seq_entries = - flow_seq_entry % ',' >> -omit[char_(",")] - ; - - // [139] - flow_seq_entry = - as()[flow_pair] - | flow_node - ; - - // 7.4.2 Flow Mappings - - // [140] - flow_mapping = - '{' >> -flow_map_entries >> '}' - ; - - // [141] - flow_map_entries = - flow_map_entry[ins] % ',' >> -omit[char_(",")] - ; - - // [142] - flow_map_entry %= - '?' >> flow_map_explicit_entry - | flow_map_implicit_entry - ; - - // [143] - flow_map_explicit_entry = - flow_map_implicit_entry[_val = _1] - | eps[_val = ast::object_element_t()] - ; - - // [144] - flow_map_implicit_entry %= - flow_map_yaml_key_entry - | flow_map_empty_key_entry - | flow_map_json_key_entry - ; - - // [145] - flow_map_yaml_key_entry = ( - flow_yaml_node[_a = _1] - >> -flow_map_separate_value[_b = _1] - ) - [_val = construct(_a, _b)] - ; - - // [146] - flow_map_empty_key_entry = - flow_map_separate_value - [_val = construct(ast::null_t(), _1)] - ; - - // [147] - flow_map_separate_value = - ':' >> !no_skip[plain_safe] - >> -flow_node[_val = _1] - ; - - // [148] - flow_map_json_key_entry = ( - flow_json_node[_a = _1] - >> -flow_map_adjacent_value[_b = _1] - ) - [_val = construct(_a, _b)] - ; - - // [149] - flow_map_adjacent_value = - ':' >> -flow_node[_val = _1] - ; - - // [150] - flow_pair = - '?' >> flow_map_explicit_entry[ins] - | flow_pair_entry[ins] - ; - - // [151] - flow_pair_entry = - flow_pair_yaml_key_entry - | flow_map_empty_key_entry - | flow_pair_json_key_entry - ; - - // [152] - flow_pair_yaml_key_entry = - (implicit_yaml_key[_a = _1] >> flow_map_separate_value[_b = _1]) - [_val = construct(_a, _b)] - ; - - // [153] - flow_pair_json_key_entry %= - implicit_json_key >> flow_map_adjacent_value - ; - - // [154] - implicit_yaml_key = - flow_yaml_node.alias() - ; - - // [155] - implicit_json_key = - flow_json_node.alias() - ; - - // 7.5 Flow Nodes - - // [156] - flow_yaml_content = - plain - ; - - // [157] - flow_json_content = - flow_sequence - | flow_mapping - | single_quoted - | double_quoted - ; - - // [158] - flow_content = - flow_yaml_content - | flow_json_content - ; - - // TODO: Use Niabelek trick to handle parse after properties. - - // [159] - flow_yaml_node = - alias_node[_val = _1] - | flow_yaml_content[_val = _1] - | properties >> (no_skip[separate] >> flow_yaml_content[_val = _1] | eps) - ; - - // [160] - flow_json_node = - -(properties > no_skip[separate]) >> flow_json_content[_val = _1] - ; - - // [161] - flow_node = - alias_node[_val = _1] - | flow_content[_val = _1] - | properties >> (no_skip[separate] >> flow_content[_val = _1] | eps) - ; - - BOOST_SPIRIT_DEBUG_NODES( - (flow_sequence) - (flow_seq_entries) - (flow_seq_entry) - (flow_mapping) - (flow_map_entries) - (flow_map_entry) - (flow_map_explicit_entry) - (flow_map_implicit_entry) - (flow_map_yaml_key_entry) - (flow_map_empty_key_entry) - (flow_map_separate_value) - (flow_map_json_key_entry) - (flow_map_adjacent_value) - (flow_pair) - (flow_pair_entry) - (flow_pair_yaml_key_entry) - (flow_pair_json_key_entry) - (implicit_yaml_key) - (implicit_json_key) - (flow_yaml_content) - (flow_json_content) - (flow_content) - (flow_yaml_node) - (flow_json_node) - (flow_node) - ); - - qi::on_error(flow_node, error_handler(_1, _2, _3, _4)); - } - -} } } - -#endif diff --git a/yaml/parser/flow_styles.hpp b/yaml/parser/flow_styles.hpp index a22aa77a..bb01ea5b 100644 --- a/yaml/parser/flow_styles.hpp +++ b/yaml/parser/flow_styles.hpp @@ -11,7 +11,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { template struct flow_styles @@ -78,6 +78,6 @@ namespace omd { namespace yaml { namespace parser { qi::rule flow_node; }; -} } } +} } #endif diff --git a/yaml/parser/flow_styles_def.hpp b/yaml/parser/flow_styles_def.hpp index a3a6f68e..8afa2538 100644 --- a/yaml/parser/flow_styles_def.hpp +++ b/yaml/parser/flow_styles_def.hpp @@ -17,7 +17,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { namespace detail { @@ -470,6 +470,6 @@ namespace omd { namespace yaml { namespace parser { ); } -} } } +} } #endif diff --git a/yaml/parser/scalar.hpp b/yaml/parser/scalar.hpp deleted file mode 100644 index 2569d656..00000000 --- a/yaml/parser/scalar.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (C) 2010, 2011, 2012 Object Modeling Designs : consultomd.com - * Copyright (c) 2010 Joel de Guzman - * - * 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) - */ - -#if !defined(OMD_PARSER_SCALAR_HPP) -#define OMD_PARSER_SCALAR_HPP - -#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS -#define BOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT - -#include - -#include -#include - -#include // our AST -#include // Our Error Handler - -namespace omd { namespace yaml { namespace parser -{ - namespace qi = boost::spirit::qi; - namespace ascii = boost::spirit::ascii; - - typedef boost::uint32_t uchar; // a unicode code point - - template - struct unicode_string : qi::grammar - { - int& indent; - unicode_string(int& indent); - - qi::rule escape; - qi::rule char_esc; - qi::rule char_lit; - qi::rule double_quoted; - qi::rule single_quoted; - qi::rule unquoted_char; - qi::rule unquoted; - qi::rule explicit_; - qi::rule unicode_start; - qi::rule separate; - qi::rule plain_safe; - qi::rule nb_char; - qi::rule ns_char; - qi::rule uri_char; - qi::rule tag_char; - qi::rule anchor_char; - }; - - template - struct scalar : qi::grammar - { - scalar(int& indent, qi::symbols& symbol_table); - - qi::rule scalar_value; - qi::rule scalar_value_no_strings; - qi::rule map_key; - unicode_string string_value; - qi::rule int_value; - qi::rule strict_float_value; - qi::rule float_value; - qi::symbols bool_value_; - qi::rule bool_value; - qi::rule null_value; - qi::rule alias_node; - qi::rule anchor_name; - qi::rule anchored_value; - qi::rule anchored_string; - qi::rule tag_handle; - - qi::rule< - Iterator, - ast::properties_t(), - qi::locals - > properties; - - qi::rule tag_property; - qi::rule anchor_property; - }; -}}} - -#endif diff --git a/yaml/parser/scalar_def.hpp b/yaml/parser/scalar_def.hpp deleted file mode 100644 index 87903f07..00000000 --- a/yaml/parser/scalar_def.hpp +++ /dev/null @@ -1,436 +0,0 @@ -/** - * Copyright (C) 2010, 2011, 2012 Object Modeling Designs : consultomd.com - * Copyright (c) 2010 Joel de Guzman - * - * 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) - */ - -#if !defined(OMD_COMMON_SCALAR_DEF_HPP) -#define OMD_COMMON_SCALAR_DEF_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace omd { namespace yaml { namespace parser { - - namespace detail { - - struct push_utf8 - { - template - struct result { typedef void type; }; - - void operator()(std::string& utf8, uchar code_point) const - { - typedef std::back_insert_iterator insert_iter; - insert_iter out_iter(utf8); - boost::utf8_output_iterator utf8_iter(out_iter); - *utf8_iter++ = code_point; - } - }; - - struct push_esc - { - template - struct result { typedef void type; }; - - void operator()(std::string& utf8, uchar c) const - { - switch (c) - { - case ' ': utf8 += ' '; break; - case '\t': utf8 += '\t'; break; - case '0': utf8 += char(0); break; - case 'a': utf8 += 0x7; break; - case 'b': utf8 += 0x8; break; - case 't': utf8 += 0x9; break; - case 'n': utf8 += 0xA; break; - case 'v': utf8 += 0xB; break; - case 'f': utf8 += 0xC; break; - case 'r': utf8 += 0xD; break; - case 'e': utf8 += 0x1B; break; - case '"': utf8 += '"'; break; - case '/': utf8 += '/'; break; - case '\\': utf8 += '\\'; break; - - case '_': push_utf8()(utf8, 0xA0); break; - case 'N': push_utf8()(utf8, 0x85); break; - case 'L': push_utf8()(utf8, 0x2028); break; - case 'P': push_utf8()(utf8, 0x2029); break; - } - } - }; - - template - struct yaml_strict_real_policies : qi::real_policies - { - static bool const expect_dot = true; - - template - static bool - parse_nan(Iterator& first, Iterator const& last, Attribute& attr) - { - using boost::spirit::unused; - - if (first == last) - return false; // end of input reached - - // .nan ? - if (qi::detail::string_parse(".nan", ".NAN", first, last, unused)) - { - attr = std::numeric_limits::quiet_NaN(); - return true; - } - return false; - } - - template - static bool - parse_inf(Iterator& first, Iterator const& last, Attribute& attr) - { - using boost::spirit::unused; - - if (first == last) - return false; // end of input reached - - // -.inf - if (qi::detail::string_parse("-.inf", "-.INF", first, last, unused)) - { - attr = -std::numeric_limits::infinity(); - return true; - } - // .inf - if (qi::detail::string_parse(".inf", ".INF", first, last, unused)) - { - attr = std::numeric_limits::infinity(); - return true; - } - return false; - } - }; - - template - struct yaml_real_policies : yaml_strict_real_policies - { - static bool const expect_dot = false; - }; - } - - template - unicode_string::unicode_string(int& indent_) - : unicode_string::base_type(unicode_start), - indent(indent_) - { - qi::char_type char_; - qi::_val_type _val; - qi::_r1_type _r1; - qi::_1_type _1; - qi::_2_type _2; - qi::lit_type lit; - qi::blank_type blank; - qi::print_type print; - qi::eol_type eol; - qi::repeat_type repeat; - qi::inf_type inf; - qi::alnum_type alnum; - qi::hex_type hex; - qi::omit_type omit; - - using boost::spirit::qi::uint_parser; - using boost::phoenix::function; - using boost::phoenix::ref; - using boost::spirit::qi::copy; - - uint_parser hex4; - uint_parser hex8; - function push_utf8; - function push_esc; - - escape = - ('x' > hex) [push_utf8(_r1, _1)] - | ('u' > hex4) [push_utf8(_r1, _1)] - | ('U' > hex8) [push_utf8(_r1, _1)] - | char_("0abtnvfre\"/\\N_LP \t") [push_esc(_r1, _1)] - | eol // continue to next line - ; - - char_esc = - '\\' > escape(_r1) - ; - - double_quoted = - '"' - > *(char_esc(_val) | (~char_('"')) [_val += _1]) - > '"' - ; - - single_quoted = - '\'' - > *( - lit("''") [_val += '\''] - | (~char_('\'')) [_val += _1] - ) - > '\'' - ; - - separate = copy( - blank | (eol >> repeat(ref(indent), inf)[blank]) - ); - - plain_safe = ~char_(" \n\r\t,[]{}#"); - - // These are not allowed as first plain-style character - auto unsafe_first = char_(" \n\r\t?:-,[]{}#&*!|>\\\"%@`"); - - unquoted_char = - plain_safe - char_(":#") - | ~char_(" \n\r\t") >> &char_("#") - | ':' >> plain_safe - ; - - unquoted = - (~unsafe_first | char_("?:-") >> &plain_safe) [_val = _1] - >> *( - (+separate >> unquoted_char) [_val += ' ', _val += _2] - | unquoted_char [_val += _1] - ) - ; - - explicit_ = - "!!str" - > omit[+blank] - > ( double_quoted - | single_quoted - | unquoted - ) - ; - - unicode_start = - explicit_ - | double_quoted - | single_quoted - | unquoted - ; - - // [27] - nb_char = - print - eol /* - bom */ - ; - - // [34] - ns_char = - print - eol /* - bom */ - blank - ; - - // [39] - uri_char = - char_("%") > hex > hex - | alnum | char_("-") // word_char [38] - | char_("#;/?:@&=+$,_.!~*'()[]") - ; - - // [40] - tag_char = - uri_char - char_("!,[]{}") // '!' | flow_indicator [23] - ; - - // [102] - anchor_char = - ns_char - char_(",[]{}") - ; - - BOOST_SPIRIT_DEBUG_NODES( - (escape) - (char_esc) - (single_quoted) - (double_quoted) - (unquoted) - (unicode_start) - (explicit_) - ); - } - - template - scalar::scalar(int& indent, qi::symbols& anchors) - : scalar::base_type(scalar_value), - string_value(indent) - { - qi::lit_type lit; - qi::char_type char_; - qi::alnum_type alnum; - qi::hex_type hex; - qi::oct_type oct; - qi::no_case_type no_case; - qi::int_type int_; - qi::attr_type attr; - qi::blank_type blank; - qi::omit_type omit; - qi::_a_type _a; - qi::_b_type _b; - qi::_1_type _1; - qi::_val_type _val; - qi::raw_type raw; - qi::eoi_type eoi; - - namespace phx = boost::phoenix; - using boost::spirit::qi::copy; - using phx::construct; - - phx::function::adder> add_anchor(anchors.add); - qi::real_parser< - double, detail::yaml_strict_real_policies > - strict_double_value; - qi::real_parser< - double, detail::yaml_real_policies > - double_value; - - auto & uri_char = string_value.uri_char; - auto & tag_char = string_value.tag_char; - auto & anchor_char = string_value.anchor_char; - auto & separate = string_value.separate; - - scalar_value = - scalar_value_no_strings - | string_value - ; - - auto delimeter = copy(char_(" \n\r\t,[]{}:#") | eoi); - - scalar_value_no_strings = - alias_node - | anchored_value - | ("!!float" > omit[+blank] > float_value) - | ("!!bool" > omit[+blank] > bool_value) - | ("!!int" > omit[+blank] > int_value) - | ("!!null" > omit[+blank] > null_value) - | strict_float_value - | int_value - | bool_value - | null_value - ; - - // this is a special form of scalar for use as map keys - map_key = - alias_node - | anchored_string - | string_value - | ("!!float" > omit[+blank] > float_value) - | ("!!bool" > omit[+blank] > bool_value) - | ("!!int" > omit[+blank] > int_value) - | ("!!null" > omit[+blank] > null_value) - ; - - int_value = - ( (no_case["0x"] > hex) - | (no_case["0o"] > oct) - | ('0' >> oct) - | int_ - ) - >> &delimeter - ; - - float_value = - double_value - >> &delimeter - ; - - strict_float_value = - strict_double_value - >> &delimeter - ; - - bool_value_.add - ("true", true) - ("false", false) - ; - - bool_value = - bool_value_ - >> &delimeter - ; - - null_value = - (lit("null") | '~') - >> &delimeter - >> attr(ast::null_t()) - ; - - // [104] - alias_node = - '*' - > anchor_name - > attr((ast::value_t*)0) - ; - - anchored_value %= - '&' - >> (+~char_(" \n\r\t,{}[]")) [ add_anchor(_1) ] - >> omit[+blank] - >> scalar_value - ; - - anchored_string %= - '&' - >> (+~char_(" \n\r\t,{}[]")) [ add_anchor(_1) ] - >> omit[+blank] - >> string_value - ; - - // [89] - tag_handle %= - // "alnum..." below is word_char [38] - '!' >> +(alnum | char_("-")) >> '!' // named_tag_handle [92] (must match existing TAG-defined prefix) - | "!!" // secondary_tag_handle [91] - | '!' // primary_tag_handle [90] - ; // TODO: Check that nonempty handle matches existing TAG prefix (or better yet, use a symbol table) - - // [96] - properties = ( - tag_property[_a = _1] >> -(separate >> anchor_property[_b = _1]) - | anchor_property[_b = _1] >> -(separate >> tag_property[_a = _1]) - ) - [_val = construct(_a, _b)] - ; - - // [97] - tag_property %= - lit('!') >> "<" > +uri_char > ">" // verbatim_tag [98] - | tag_handle >> +tag_char // shorthand_tag [99] - | '!' // non_specific_tag [100] - ; - - // [101] - anchor_property %= - '&' >> +anchor_char - ; - - // [103] - anchor_name %= - +anchor_char - ; - - BOOST_SPIRIT_DEBUG_NODES( - (scalar_value) - (int_value) - (float_value) - (strict_float_value) - (null_value) - (alias_node) - (anchor_name) - (anchored_value) - ); - } - -} } } - -#endif diff --git a/yaml/parser/stream.hpp b/yaml/parser/stream.hpp index c871b60f..d6a972f4 100644 --- a/yaml/parser/stream.hpp +++ b/yaml/parser/stream.hpp @@ -18,7 +18,7 @@ #endif -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { template struct stream @@ -51,7 +51,7 @@ namespace omd { namespace yaml { namespace parser { std::string const& source_file = "" ); -} } } +} } #include diff --git a/yaml/parser/stream_def.hpp b/yaml/parser/stream_def.hpp index f98e7839..1ff842be 100644 --- a/yaml/parser/stream_def.hpp +++ b/yaml/parser/stream_def.hpp @@ -16,7 +16,7 @@ #include -namespace omd { namespace yaml { namespace parser { +namespace yaml { namespace parser { template stream::stream (std::string const & source_file) @@ -126,6 +126,6 @@ namespace omd { namespace yaml { namespace parser { qi::on_error(yaml_stream, error_handler_(_1, _2, _3, _4)); } -} } } +} } #endif diff --git a/yaml/parser/yaml.hpp b/yaml/parser/yaml.hpp deleted file mode 100644 index 2c42cf00..00000000 --- a/yaml/parser/yaml.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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) - */ - -#if !defined(OMD_PARSER_YAML_HPP) -#define OMD_PARSER_YAML_HPP - -#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS - -#include -#include -#include -#include - - -#ifndef YAML_HEADER_ONLY -#define YAML_HEADER_ONLY 1 -#endif - - -namespace omd { namespace yaml { namespace parser { - - template - struct yaml : qi::grammar()> - { - yaml(std::string const& source_file = ""); - - typedef white_space white_space_t; - typedef block block_t; - - white_space_t ws; - - block_t block_g; - - qi::rule directive; - qi::rule reserved_directive; - qi::rule yaml_directive; - qi::rule tag_directive; - qi::rule tag_prefix; - qi::rule document_prefix; - qi::rule document_suffix; - qi::rule forbidden; - qi::rule bare_document; - qi::rule explicit_document; - qi::rule directive_document; - qi::rule any_document; - qi::rule()> yaml_stream; - - typedef omd::yaml::parser::error_handler error_handler_t; - boost::phoenix::function const error_handler; - }; - -#if YAML_HEADER_ONLY - inline -#endif - bool parse_yaml( - std::istream & is, - std::vector & result, - std::string const& source_file = "" - ); - -} } } - -#include - -#endif diff --git a/yaml/parser/yaml_def.hpp b/yaml/parser/yaml_def.hpp deleted file mode 100644 index f11f7cdb..00000000 --- a/yaml/parser/yaml_def.hpp +++ /dev/null @@ -1,168 +0,0 @@ -/** - * Copyright (C) 2010, 2011, 2012 Object Modeling Designs - * consultomd.com - * - * 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) - */ - -#if !defined(OMD_PARSER_YAML_DEF_HPP) -#define OMD_PARSER_YAML_DEF_HPP - -#include - -#include -#include -#include -#include -#include - -namespace omd { namespace yaml { namespace parser { - - template - yaml::yaml(std::string const& source_file) - : yaml::base_type(yaml_stream), - block_g(source_file), - error_handler(error_handler_t(source_file)) - { - namespace phx = boost::phoenix; - using boost::spirit::qi::copy; - - qi::skip_type skip; - - qi::_val_type _val; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::char_type char_; - qi::digit_type digit; - qi::attr_type attr; - qi::eol_type eol; - qi::eoi_type eoi; - qi::blank_type blank; - qi::omit_type omit; - qi::space_type qi_space; - - auto comment = copy('#' >> *(char_ - eol) >> eol); // comments - auto blank_eol = copy(*blank >> (comment | eol)); // empty until eol - - auto & ns_char = block_g.flow_g.scalar_value.string_value.ns_char; - auto & tag_char = block_g.flow_g.scalar_value.string_value.tag_char; - auto & uri_char = block_g.flow_g.scalar_value.string_value.uri_char; - auto & tag_handle = block_g.flow_g.scalar_value.tag_handle; - auto & block_node = block_g;// TODO .block_node; - - auto pb = phx::push_back(_val, _1); - - // [82] - directive = - '%' - >> (yaml_directive | tag_directive | reserved_directive) - >> blank_eol - ; - - // [83] - reserved_directive = - +ns_char - >> *(+blank >> +ns_char) - ; - - // [86] - yaml_directive = - "YAML" >> +blank >> +digit >> '.' >> +digit - // TODO [report warnings and errors for YAML versions != 1.2] - ; - - // [88] - tag_directive = - "TAG" >> +blank >> tag_handle >> +blank >> tag_prefix - // TODO [add tag to tag symbol table] - ; - - // [93] - tag_prefix = - '!' >> *uri_char - | tag_char >> *uri_char - ; - - // [202] - document_prefix = - // TODO -bom >> - +blank_eol - ; - - // [205] - document_suffix = - "..." >> blank_eol - ; - - // [206] - forbidden = - eol - | eoi - | blank - | "---" - | "..." - /* | TODO: Detect start of line. */ - ; - - // [207] - bare_document = - block_node/*TODO (-1, context_t::block_in)*/ - forbidden - ; - - // [208] - explicit_document = - "---" - >> omit[*qi_space] - >> (bare_document | comment >> attr(ast::value_t())) - ; - - // [209] - directive_document = - +directive - >> explicit_document - ; - - // [210] - any_document = - directive_document - | explicit_document - | bare_document - ; - - // [211] - yaml_stream = - *document_prefix - >> -any_document[pb] - >> *( - +document_suffix >> *document_prefix >> any_document[pb] - | *document_prefix >> explicit_document[pb] - ) - >> *document_suffix >> *document_prefix - > block_g.end_of_input - ; - - BOOST_SPIRIT_DEBUG_NODES( - (directive) - (reserved_directive) - (yaml_directive) - (tag_directive) - (tag_prefix) - (document_prefix) - (document_suffix) - (forbidden) - (bare_document) - (explicit_document) - (directive_document) - (any_document) - (yaml_stream) - ); - - qi::on_error(yaml_stream, error_handler(_1, _2, _3, _4)); - } - -} } } - -#endif