From f43bcf31d8ed84229fa02d0e2edeaec409cbd83e Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Tue, 15 Nov 2011 20:14:39 +0800 Subject: [PATCH] More block tests (some tests are still failing). --- test/test_files/yaml_block_array1.yaml | 3 ++- test/test_files/yaml_block_array3.yaml | 2 ++ test/test_files/yaml_block_array4.yaml | 6 +++++ test/test_files/yaml_block_map1.yaml | 2 +- test/test_files/yaml_block_map3.yaml | 6 +++++ test/test_files/yaml_block_map4.yaml | 3 +++ yaml/detail/ast_impl.hpp | 3 +-- yaml/parser/scalar.hpp | 4 +-- yaml/parser/scalar_def.hpp | 1 + yaml/parser/yaml.hpp | 2 +- yaml/parser/yaml_def.hpp | 34 +++++++++++++++++--------- 11 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 test/test_files/yaml_block_array3.yaml create mode 100644 test/test_files/yaml_block_array4.yaml create mode 100644 test/test_files/yaml_block_map3.yaml create mode 100644 test/test_files/yaml_block_map4.yaml diff --git a/test/test_files/yaml_block_array1.yaml b/test/test_files/yaml_block_array1.yaml index 0d79f4b9..33c43dd8 100644 --- a/test/test_files/yaml_block_array1.yaml +++ b/test/test_files/yaml_block_array1.yaml @@ -2,4 +2,5 @@ - B - C - [x, y, z] -- D \ No newline at end of file +- D +- E \ No newline at end of file diff --git a/test/test_files/yaml_block_array3.yaml b/test/test_files/yaml_block_array3.yaml new file mode 100644 index 00000000..6b9dede4 --- /dev/null +++ b/test/test_files/yaml_block_array3.yaml @@ -0,0 +1,2 @@ +- +- B \ No newline at end of file diff --git a/test/test_files/yaml_block_array4.yaml b/test/test_files/yaml_block_array4.yaml new file mode 100644 index 00000000..781563ba --- /dev/null +++ b/test/test_files/yaml_block_array4.yaml @@ -0,0 +1,6 @@ +- A +- + [ + a, b, c + ] +- B \ No newline at end of file diff --git a/test/test_files/yaml_block_map1.yaml b/test/test_files/yaml_block_map1.yaml index 85f01ce3..8df5ac16 100644 --- a/test/test_files/yaml_block_map1.yaml +++ b/test/test_files/yaml_block_map1.yaml @@ -1,2 +1,2 @@ -Apple : 6, +Apple : 6 Orange : [1, 2, 3] \ No newline at end of file diff --git a/test/test_files/yaml_block_map3.yaml b/test/test_files/yaml_block_map3.yaml new file mode 100644 index 00000000..037cec2e --- /dev/null +++ b/test/test_files/yaml_block_map3.yaml @@ -0,0 +1,6 @@ +key0: + key1: 1 + key2: 2 + key3: 3 + key4: # null value + key5: 4 diff --git a/test/test_files/yaml_block_map4.yaml b/test/test_files/yaml_block_map4.yaml new file mode 100644 index 00000000..6d357464 --- /dev/null +++ b/test/test_files/yaml_block_map4.yaml @@ -0,0 +1,3 @@ +key1: 1 +key2: +key3: 2 diff --git a/yaml/detail/ast_impl.hpp b/yaml/detail/ast_impl.hpp index f0e908d8..9c7e0f49 100644 --- a/yaml/detail/ast_impl.hpp +++ b/yaml/detail/ast_impl.hpp @@ -77,8 +77,7 @@ namespace omd { namespace ast template bool operator()(A const& a, B const& b) const { - BOOST_ASSERT(false); // this should not happen. We cannot compare different types - return false; + return false; // comparing different types returns false } template diff --git a/yaml/parser/scalar.hpp b/yaml/parser/scalar.hpp index b886a949..8c3371dd 100644 --- a/yaml/parser/scalar.hpp +++ b/yaml/parser/scalar.hpp @@ -28,10 +28,10 @@ namespace omd { namespace parser char const* indicators = "-?:,[]{}#&*!|>\\\"%@`"; // These are not allowed as first plain-style character - char const* unsafe_first = ",[]{}#&*!|>\\\"%@`"; + char const* unsafe_first = " \n\r\t,[]{}#&*!|>\\\"%@`"; // These are not allowed as non-first plain-style character - char const* unsafe_plain = " \n\r\t-?:,[]{}#&*!|>\\\"%@`"; + char const* unsafe_plain = " \n\r\t?:,[]{}#&*!|>\\\"%@`-"; template struct unicode_string : qi::grammar diff --git a/yaml/parser/scalar_def.hpp b/yaml/parser/scalar_def.hpp index bd29b735..e16dbdce 100644 --- a/yaml/parser/scalar_def.hpp +++ b/yaml/parser/scalar_def.hpp @@ -165,6 +165,7 @@ namespace omd { namespace parser | no_case[bool_value] | no_case[null_value] | string_value + //~ | attr(ast::null_t()) ; integer_value = diff --git a/yaml/parser/yaml.hpp b/yaml/parser/yaml.hpp index a42101d0..e17bf52f 100644 --- a/yaml/parser/yaml.hpp +++ b/yaml/parser/yaml.hpp @@ -24,7 +24,7 @@ namespace omd { namespace parser white_space_t ws; qi::rule yaml_start; - qi::rule yaml_nested; + qi::rule flow_in_block; flow_t flow_g; qi::rule indent; diff --git a/yaml/parser/yaml_def.hpp b/yaml/parser/yaml_def.hpp index 1c2e7898..a96fc9ac 100644 --- a/yaml/parser/yaml_def.hpp +++ b/yaml/parser/yaml_def.hpp @@ -42,16 +42,18 @@ namespace omd { namespace parser qi::_4_type _4; qi::_r1_type _r1; qi::_a_type _a; + qi::char_type char_; qi::repeat_type repeat; qi::eol_type eol; - qi::char_type char_; qi::omit_type omit; qi::_pass_type _pass; qi::eps_type eps; + qi::attr_type attr; qi::blank_type blank; - auto blank_line = *blank >> eol; + auto comment = '#' >> *(char_ - eol) >> eol; // comments + auto blank_eol = (*blank >> eol) | comment; // empty until eol phx::function count_chars; @@ -59,14 +61,20 @@ namespace omd { namespace parser auto flow_value = skip(space)[flow_g.flow_value]; auto flow_scalar = skip(space)[flow_g.scalar_value.scalar_value]; + // no-skip version + auto flow_scalar_ns = flow_g.scalar_value.scalar_value.alias(); + yaml_start = flow_compound | blocks ; - yaml_nested = - blocks // Give blocks a higher precedence - | flow_value + flow_in_block = + blocks // Give blocks a higher precedence + | flow_compound + | flow_scalar_ns // Don't allow scalars to skip spaces + | (omit[blank_eol] // If all else fails, then null_t + >> attr(ast::null_t())) ; std::size_t& indent_var = @@ -99,7 +107,7 @@ namespace omd { namespace parser ; auto block_seq_indicator = // Lookahead and see if we have a - &(start_indent >> '-' >> blank) // sequence indicator. Save the indent + &(start_indent >> '-' >> (blank | eol)) // sequence indicator. Save the indent ; // in local variable _a block_seq = @@ -108,10 +116,10 @@ namespace omd { namespace parser ; // indent level block_seq_entry = - omit[*blank_line] // Ignore blank lines + omit[*blank_eol] // Ignore blank lines >> omit[repeat(_r1)[blank]] // Indent _r1 spaces - >> omit['-' >> blank] // Get the sequence indicator '-' - >> yaml_nested // Get the entry + >> omit['-' >> (blank | &eol)] // Get the sequence indicator '-' + >> flow_in_block // Get the entry ; auto block_map_indicator = // Lookahead and see if we have a @@ -127,16 +135,18 @@ namespace omd { namespace parser ; // indent level block_map_entry = - omit[*blank_line] // Ignore blank lines + omit[*blank_eol] // Ignore blank lines >> omit[repeat(_r1)[blank]] // Indent _r1 spaces >> flow_scalar // Get the key >> omit[skip(space)[':']] // Get the map indicator ':' - >> omit[*blank_line] // Ignore blank lines - >> yaml_nested // Get the value + >> omit[*blank] // Ignore blank spaces + //~ >> omit[*blank_eol] // Ignore blank lines + >> flow_in_block // Get the value ; BOOST_SPIRIT_DEBUG_NODES( (yaml_start) + (flow_in_block) (blocks) (block_seq) (block_seq_entry)