diff --git a/test/test_files/gold.txt b/test/test_files/gold.txt index 304ff183..0b2796db 100644 --- a/test/test_files/gold.txt +++ b/test/test_files/gold.txt @@ -97,8 +97,8 @@ success: - "Sammy Sosa completed another fine season with great stats.\n 63 Home Runs\n0.288 Batting Average What a year!\n" - {accomplishment : "Mark set a major league home run record in 1998.\n", name : "Mark McGwire", stats : "65 Home Runs\n0.278 Batting Average\n"} - {quoted : " # not a 'comment'.", single : "\"Howdy!\" he cried.", tie-fighter : "|\\-*-/|", unicode : "Sosa did fine."} -- ["Fun with \\\" \a \b \e \f \n \r \t \v \0 \_ \N \L \P A A"] -- ["Mark McGwire's year was crippled by a knee injury."] +- "Fun with \\\" \a \b \e \f \n \r \t \v \0 \_ \N \L \P A A" +- "Mark McGwire's year was crippled by a knee injury." C:\dev\yaml_spirit\test\test_files>C:\dev\compile\parse_yaml_test.exe C:\dev\yaml_spirit\test\test_files\yaml_block_array1.yaml success: diff --git a/test/test_files/test.yaml b/test/test_files/test.yaml index 4646d280..5147e7ac 100644 --- a/test/test_files/test.yaml +++ b/test/test_files/test.yaml @@ -107,13 +107,13 @@ quoted: ' # not a ''comment''.' tie-fighter: '|\-*-/|' --- -- "Fun with \\\" \a \b \e \f \ - \n \r \t \v \0 \ - \ \_ \N \L \P \ - \x41 \u0041" +"Fun with \\\" \a \b \e \f \ +\n \r \t \v \0 \ +\ \_ \N \L \P \ +\x41 \u0041" --- -- Mark McGwire's + Mark McGwire's year was crippled by a knee injury. diff --git a/yaml/parser/block.hpp b/yaml/parser/block.hpp index c0429d57..74d4b6f1 100644 --- a/yaml/parser/block.hpp +++ b/yaml/parser/block.hpp @@ -14,7 +14,7 @@ namespace omd { namespace parser { template - struct block : qi::grammar > + struct block : qi::grammar { block(std::string const& source_file = ""); @@ -23,11 +23,6 @@ namespace omd { namespace parser typedef std::pair map_element_t; white_space_t ws; - //~ qi::rule stream; - //~ qi::rule document; - //~ qi::rule implicit_document; - //~ qi::rule explicit_document; - //~ qi::rule document_end; qi::rule end_of_input; qi::rule block_node; @@ -38,6 +33,7 @@ namespace omd { namespace parser qi::rule indent; qi::rule skip_indent; qi::rule skip_indent_child; + qi::rule start; qi::rule > blocks; qi::rule > flow_compound; diff --git a/yaml/parser/block_def.hpp b/yaml/parser/block_def.hpp index 546f8630..d2ee2039 100644 --- a/yaml/parser/block_def.hpp +++ b/yaml/parser/block_def.hpp @@ -125,7 +125,7 @@ namespace omd { namespace parser template block::block(std::string const& source_file) - : block::base_type(blocks), + : block::base_type(start), flow_g(current_indent), current_indent(-1), error_handler(error_handler_t(source_file)) @@ -163,10 +163,14 @@ namespace omd { namespace parser auto comment = '#' >> *(char_ - eol) >> eol; // comments auto blank_eol = *blank >> (comment | eol); // empty until eol - auto flow_string = skip(space)[flow_g.scalar_value.string_value.unicode_start]; + auto flow_string = + skip(space)[flow_g.scalar_value.string_value.unicode_start] + ; // no-skip version - auto flow_scalar_ns = flow_g.scalar_value.scalar_value.alias(); + auto flow_scalar_ns = + flow_g.scalar_value.scalar_value.alias() + ; auto get_indent = phx::ref(current_indent) @@ -262,6 +266,16 @@ namespace omd { namespace parser >> restore_indent ; + start %= + blocks + + // YAML allows bare top-level scalars. Allow this, but set + // the indent to 1 to force 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 = omit[indent] PRINT_INDENT ; diff --git a/yaml/parser/scalar.hpp b/yaml/parser/scalar.hpp index c9f637f3..26ce2a4b 100644 --- a/yaml/parser/scalar.hpp +++ b/yaml/parser/scalar.hpp @@ -32,6 +32,7 @@ namespace omd { namespace parser int& indent; unicode_string(int& indent); + qi::rule escape; qi::rule char_esc; qi::rule char_lit; qi::rule double_quoted; diff --git a/yaml/parser/scalar_def.hpp b/yaml/parser/scalar_def.hpp index e6bda52b..6fddbd6d 100644 --- a/yaml/parser/scalar_def.hpp +++ b/yaml/parser/scalar_def.hpp @@ -141,14 +141,16 @@ namespace omd { namespace parser function push_utf8; function push_esc; - char_esc = - '\\' - > ( ('x' > hex) [push_utf8(_r1, _1)] + 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 = @@ -189,6 +191,7 @@ namespace omd { namespace parser ; BOOST_SPIRIT_DEBUG_NODES( + (escape) (char_esc) (single_quoted) (double_quoted)