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

More block tests (some tests are still failing).

This commit is contained in:
Joel de Guzman
2011-11-15 20:14:39 +08:00
parent 15eb9f3ea8
commit f43bcf31d8
11 changed files with 47 additions and 19 deletions

View File

@@ -2,4 +2,5 @@
- B
- C
- [x, y, z]
- D
- D
- E

View File

@@ -0,0 +1,2 @@
-
- B

View File

@@ -0,0 +1,6 @@
- A
-
[
a, b, c
]
- B

View File

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

View File

@@ -0,0 +1,6 @@
key0:
key1: 1
key2: 2
key3: 3
key4: # null value
key5: 4

View File

@@ -0,0 +1,3 @@
key1: 1
key2:
key3: 2

View File

@@ -77,8 +77,7 @@ namespace omd { namespace ast
template <typename A, typename B>
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 <typename T>

View File

@@ -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 <typename Iterator>
struct unicode_string : qi::grammar<Iterator, std::string()>

View File

@@ -165,6 +165,7 @@ namespace omd { namespace parser
| no_case[bool_value]
| no_case[null_value]
| string_value
//~ | attr(ast::null_t())
;
integer_value =

View File

@@ -24,7 +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;
qi::rule<Iterator, ast::value_t()> flow_in_block;
flow_t flow_g;
qi::rule<Iterator, std::size_t()> indent;

View File

@@ -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<detail::count_chars> 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)