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:
@@ -2,4 +2,5 @@
|
||||
- B
|
||||
- C
|
||||
- [x, y, z]
|
||||
- D
|
||||
- D
|
||||
- E
|
||||
2
test/test_files/yaml_block_array3.yaml
Normal file
2
test/test_files/yaml_block_array3.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
-
|
||||
- B
|
||||
6
test/test_files/yaml_block_array4.yaml
Normal file
6
test/test_files/yaml_block_array4.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
- A
|
||||
-
|
||||
[
|
||||
a, b, c
|
||||
]
|
||||
- B
|
||||
@@ -1,2 +1,2 @@
|
||||
Apple : 6,
|
||||
Apple : 6
|
||||
Orange : [1, 2, 3]
|
||||
6
test/test_files/yaml_block_map3.yaml
Normal file
6
test/test_files/yaml_block_map3.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
key0:
|
||||
key1: 1
|
||||
key2: 2
|
||||
key3: 3
|
||||
key4: # null value
|
||||
key5: 4
|
||||
3
test/test_files/yaml_block_map4.yaml
Normal file
3
test/test_files/yaml_block_map4.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
key1: 1
|
||||
key2:
|
||||
key3: 2
|
||||
@@ -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>
|
||||
|
||||
@@ -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()>
|
||||
|
||||
@@ -165,6 +165,7 @@ namespace omd { namespace parser
|
||||
| no_case[bool_value]
|
||||
| no_case[null_value]
|
||||
| string_value
|
||||
//~ | attr(ast::null_t())
|
||||
;
|
||||
|
||||
integer_value =
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user