From dcc019396b73306b01da48ad220128f6bff19702 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Tue, 15 Nov 2011 15:10:14 +0800 Subject: [PATCH] More block tests --- test/test_files/basic_yaml_block.yaml | 3 ++- test/test_files/scalar.yaml | 4 ++++ test/test_files/yaml_block_array1.yaml | 1 + test/test_files/yaml_block_map1.yaml | 2 ++ test/test_files/yaml_block_map2.yaml | 3 +++ yaml/parser/scalar.hpp | 2 +- yaml/parser/scalar_def.hpp | 6 +++--- yaml/parser/yaml.hpp | 1 + yaml/parser/yaml_def.hpp | 28 +++++++++++++++++++++++++- 9 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 test/test_files/scalar.yaml create mode 100644 test/test_files/yaml_block_map1.yaml create mode 100644 test/test_files/yaml_block_map2.yaml diff --git a/test/test_files/basic_yaml_block.yaml b/test/test_files/basic_yaml_block.yaml index 9f767a8d..632feafc 100644 --- a/test/test_files/basic_yaml_block.yaml +++ b/test/test_files/basic_yaml_block.yaml @@ -1,7 +1,8 @@ american: - Boston Red Sox - Detroit Tigers - - New York Yankees + - New York + Yankees national: - New York Mets - Chicago Cubs diff --git a/test/test_files/scalar.yaml b/test/test_files/scalar.yaml new file mode 100644 index 00000000..4fef35e6 --- /dev/null +++ b/test/test_files/scalar.yaml @@ -0,0 +1,4 @@ +[ + Apple +cider +] \ No newline at end of file diff --git a/test/test_files/yaml_block_array1.yaml b/test/test_files/yaml_block_array1.yaml index e0c4f7f5..776374e9 100644 --- a/test/test_files/yaml_block_array1.yaml +++ b/test/test_files/yaml_block_array1.yaml @@ -1,3 +1,4 @@ - Boston Red Sox - Detroit Tigers - New York Yankees +- [x, y, z] diff --git a/test/test_files/yaml_block_map1.yaml b/test/test_files/yaml_block_map1.yaml new file mode 100644 index 00000000..85f01ce3 --- /dev/null +++ b/test/test_files/yaml_block_map1.yaml @@ -0,0 +1,2 @@ +Apple : 6, +Orange : [1, 2, 3] \ No newline at end of file diff --git a/test/test_files/yaml_block_map2.yaml b/test/test_files/yaml_block_map2.yaml new file mode 100644 index 00000000..95ccd65c --- /dev/null +++ b/test/test_files/yaml_block_map2.yaml @@ -0,0 +1,3 @@ +Apple : + x : 2 + y : 3 \ No newline at end of file diff --git a/yaml/parser/scalar.hpp b/yaml/parser/scalar.hpp index 211a74f0..6796c318 100644 --- a/yaml/parser/scalar.hpp +++ b/yaml/parser/scalar.hpp @@ -43,7 +43,7 @@ namespace omd { namespace parser qi::rule double_quoted; qi::rule single_quoted; qi::rule unquoted; - qi::rule start; + qi::rule unicode_start; }; template diff --git a/yaml/parser/scalar_def.hpp b/yaml/parser/scalar_def.hpp index f60e2314..e5244fd9 100644 --- a/yaml/parser/scalar_def.hpp +++ b/yaml/parser/scalar_def.hpp @@ -58,7 +58,7 @@ namespace omd { namespace parser template unicode_string::unicode_string() - : unicode_string::base_type(start) + : unicode_string::base_type(unicode_start) { qi::char_type char_; qi::_val_type _val; @@ -108,7 +108,7 @@ namespace omd { namespace parser >> *((+space >> safe_plain) | safe_plain) ]; - start = + unicode_start = double_quoted | single_quoted | unquoted @@ -119,7 +119,7 @@ namespace omd { namespace parser (single_quoted) (double_quoted) (unquoted) - (start) + (unicode_start) ); } diff --git a/yaml/parser/yaml.hpp b/yaml/parser/yaml.hpp index 550ea897..2991ff44 100644 --- a/yaml/parser/yaml.hpp +++ b/yaml/parser/yaml.hpp @@ -24,6 +24,7 @@ namespace omd { namespace parser white_space_t ws; qi::rule yaml_start; + qi::rule yaml_nested; flow_t flow_g; qi::rule indent; diff --git a/yaml/parser/yaml_def.hpp b/yaml/parser/yaml_def.hpp index c56e9e7f..a124534d 100644 --- a/yaml/parser/yaml_def.hpp +++ b/yaml/parser/yaml_def.hpp @@ -63,9 +63,14 @@ namespace omd { namespace parser | blocks ; + yaml_nested = + blocks // Give blocks a higher precedence + | flow_value + ; + blocks = block_seq - //~ | block_map + | block_map ; indent = (*blank)[_val = count_chars(_1)]; @@ -86,6 +91,27 @@ namespace omd { namespace parser >> flow_value // Get the value ; + auto block_map_indicator = // Lookahead and see if we have a + &( indent[_a = _1] // map indicator. Save the indent + >> flow_scalar // in local variable _a + >> skip(space)[':'] + ) + ; + + block_map = + omit[block_map_indicator] + >> +block_map_entry(_a) // Get the entries passing in the + ; // indent level + + block_map_entry = + omit[*blank_line] // 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 + ; + BOOST_SPIRIT_DEBUG_NODES( (yaml_start) (blocks)