2
0
mirror of https://github.com/boostorg/parser.git synced 2026-01-19 04:22:13 +00:00

More block tests

This commit is contained in:
Joel de Guzman
2011-11-15 15:10:14 +08:00
parent 8d83cfafa1
commit dcc019396b
9 changed files with 44 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
- New York
Yankees
national:
- New York Mets
- Chicago Cubs

View File

@@ -0,0 +1,4 @@
[
Apple
cider
]

View File

@@ -1,3 +1,4 @@
- Boston Red Sox
- Detroit Tigers
- New York Yankees
- [x, y, z]

View File

@@ -0,0 +1,2 @@
Apple : 6,
Orange : [1, 2, 3]

View File

@@ -0,0 +1,3 @@
Apple :
x : 2
y : 3

View File

@@ -43,7 +43,7 @@ namespace omd { namespace parser
qi::rule<Iterator, std::string()> double_quoted;
qi::rule<Iterator, std::string()> single_quoted;
qi::rule<Iterator, std::string()> unquoted;
qi::rule<Iterator, std::string()> start;
qi::rule<Iterator, std::string()> unicode_start;
};
template <typename Iterator>

View File

@@ -58,7 +58,7 @@ namespace omd { namespace parser
template <typename Iterator>
unicode_string<Iterator>::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)
);
}

View File

@@ -24,6 +24,7 @@ namespace omd { namespace parser
white_space_t ws;
qi::rule<Iterator, ast::value_t()> yaml_start;
qi::rule<Iterator, ast::value_t()> yaml_nested;
flow_t flow_g;
qi::rule<Iterator, std::size_t()> indent;

View File

@@ -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)