mirror of
https://github.com/boostorg/parser.git
synced 2026-01-24 18:12:32 +00:00
Allow top-level scalars
This commit is contained in:
@@ -97,8 +97,8 @@ success:
|
||||
- "Sammy Sosa completed another fine season with great stats.\n 63 Home Runs\n0.288 Batting Average What a year!\n"
|
||||
- {accomplishment : "Mark set a major league home run record in 1998.\n", name : "Mark McGwire", stats : "65 Home Runs\n0.278 Batting Average\n"}
|
||||
- {quoted : " # not a 'comment'.", single : "\"Howdy!\" he cried.", tie-fighter : "|\\-*-/|", unicode : "Sosa did fine."}
|
||||
- ["Fun with \\\" \a \b \e \f \n \r \t \v \0 \_ \N \L \P A A"]
|
||||
- ["Mark McGwire's year was crippled by a knee injury."]
|
||||
- "Fun with \\\" \a \b \e \f \n \r \t \v \0 \_ \N \L \P A A"
|
||||
- "Mark McGwire's year was crippled by a knee injury."
|
||||
|
||||
C:\dev\yaml_spirit\test\test_files>C:\dev\compile\parse_yaml_test.exe C:\dev\yaml_spirit\test\test_files\yaml_block_array1.yaml
|
||||
success:
|
||||
|
||||
@@ -107,13 +107,13 @@ quoted: ' # not a ''comment''.'
|
||||
tie-fighter: '|\-*-/|'
|
||||
|
||||
---
|
||||
- "Fun with \\\" \a \b \e \f \
|
||||
\n \r \t \v \0 \
|
||||
\ \_ \N \L \P \
|
||||
\x41 \u0041"
|
||||
"Fun with \\\" \a \b \e \f \
|
||||
\n \r \t \v \0 \
|
||||
\ \_ \N \L \P \
|
||||
\x41 \u0041"
|
||||
|
||||
---
|
||||
- Mark McGwire's
|
||||
Mark McGwire's
|
||||
year was crippled
|
||||
by a knee injury.
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace omd { namespace parser
|
||||
{
|
||||
template <typename Iterator>
|
||||
struct block : qi::grammar<Iterator, ast::value_t(), qi::locals<int> >
|
||||
struct block : qi::grammar<Iterator, ast::value_t()>
|
||||
{
|
||||
block(std::string const& source_file = "");
|
||||
|
||||
@@ -23,11 +23,6 @@ namespace omd { namespace parser
|
||||
typedef std::pair<ast::string_t, ast::value_t> map_element_t;
|
||||
|
||||
white_space_t ws;
|
||||
//~ qi::rule<Iterator, ast::value_t()> stream;
|
||||
//~ qi::rule<Iterator, ast::value_t()> document;
|
||||
//~ qi::rule<Iterator, ast::value_t()> implicit_document;
|
||||
//~ qi::rule<Iterator, ast::array_t()> explicit_document;
|
||||
//~ qi::rule<Iterator> document_end;
|
||||
qi::rule<Iterator> end_of_input;
|
||||
|
||||
qi::rule<Iterator, ast::value_t()> block_node;
|
||||
@@ -38,6 +33,7 @@ namespace omd { namespace parser
|
||||
qi::rule<Iterator> indent;
|
||||
qi::rule<Iterator> skip_indent;
|
||||
qi::rule<Iterator> skip_indent_child;
|
||||
qi::rule<Iterator, ast::value_t()> start;
|
||||
qi::rule<Iterator, ast::value_t(), qi::locals<int> > blocks;
|
||||
qi::rule<Iterator, ast::value_t(), qi::locals<int> > flow_compound;
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace omd { namespace parser
|
||||
|
||||
template <typename Iterator>
|
||||
block<Iterator>::block(std::string const& source_file)
|
||||
: block::base_type(blocks),
|
||||
: block::base_type(start),
|
||||
flow_g(current_indent),
|
||||
current_indent(-1),
|
||||
error_handler(error_handler_t(source_file))
|
||||
@@ -163,10 +163,14 @@ namespace omd { namespace parser
|
||||
auto comment = '#' >> *(char_ - eol) >> eol; // comments
|
||||
auto blank_eol = *blank >> (comment | eol); // empty until eol
|
||||
|
||||
auto flow_string = skip(space)[flow_g.scalar_value.string_value.unicode_start];
|
||||
auto flow_string =
|
||||
skip(space)[flow_g.scalar_value.string_value.unicode_start]
|
||||
;
|
||||
|
||||
// no-skip version
|
||||
auto flow_scalar_ns = flow_g.scalar_value.scalar_value.alias();
|
||||
auto flow_scalar_ns =
|
||||
flow_g.scalar_value.scalar_value.alias()
|
||||
;
|
||||
|
||||
auto get_indent =
|
||||
phx::ref(current_indent)
|
||||
@@ -262,6 +266,16 @@ namespace omd { namespace parser
|
||||
>> restore_indent
|
||||
;
|
||||
|
||||
start %=
|
||||
blocks
|
||||
|
||||
// YAML allows bare top-level scalars. Allow this, but set
|
||||
// the indent to 1 to force unquoted strings to be indented,
|
||||
// otherwise, unquoted strings will gobble up too much in
|
||||
// its path.
|
||||
| eps[get_indent = 1] >> skip(space)[flow_g.scalar_value]
|
||||
;
|
||||
|
||||
auto start_indent =
|
||||
omit[indent] PRINT_INDENT
|
||||
;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace omd { namespace parser
|
||||
int& indent;
|
||||
unicode_string(int& indent);
|
||||
|
||||
qi::rule<Iterator, void(std::string&)> escape;
|
||||
qi::rule<Iterator, void(std::string&)> char_esc;
|
||||
qi::rule<Iterator, std::string()> char_lit;
|
||||
qi::rule<Iterator, std::string()> double_quoted;
|
||||
|
||||
@@ -141,14 +141,16 @@ namespace omd { namespace parser
|
||||
function<detail::push_utf8> push_utf8;
|
||||
function<detail::push_esc> push_esc;
|
||||
|
||||
char_esc =
|
||||
'\\'
|
||||
> ( ('x' > hex) [push_utf8(_r1, _1)]
|
||||
escape =
|
||||
('x' > hex) [push_utf8(_r1, _1)]
|
||||
| ('u' > hex4) [push_utf8(_r1, _1)]
|
||||
| ('U' > hex8) [push_utf8(_r1, _1)]
|
||||
| char_("0abtnvfre\"/\\N_LP \t") [push_esc(_r1, _1)]
|
||||
| eol // continue to next line
|
||||
)
|
||||
;
|
||||
|
||||
char_esc =
|
||||
'\\' > escape(_r1)
|
||||
;
|
||||
|
||||
double_quoted =
|
||||
@@ -189,6 +191,7 @@ namespace omd { namespace parser
|
||||
;
|
||||
|
||||
BOOST_SPIRIT_DEBUG_NODES(
|
||||
(escape)
|
||||
(char_esc)
|
||||
(single_quoted)
|
||||
(double_quoted)
|
||||
|
||||
Reference in New Issue
Block a user