Allow comments in scraplang.
Re-use the ini comment skipper I wrote for kamokan. Comments are the same as ini files in scraplang, use #
This commit is contained in:
parent
5a9e4e09a4
commit
9cd2608406
2 changed files with 31 additions and 2 deletions
|
@ -67,12 +67,14 @@ BOOST_FUSION_ADAPT_STRUCT(
|
|||
)
|
||||
|
||||
namespace duck { namespace sl {
|
||||
typedef kamokan::IniCommentSkipper<std::string_view::const_iterator> skipper_type;
|
||||
|
||||
std::vector<ScrapNode> parse (std::string_view parData) {
|
||||
ScrapGrammar<std::string_view::const_iterator, boost::spirit::qi::ascii::blank_type> gramm;
|
||||
ScrapGrammar<std::string_view::const_iterator, skipper_type> gramm;
|
||||
auto it_start = parData.cbegin();
|
||||
|
||||
std::vector<ScrapNode> retval;
|
||||
const bool ok = qi::phrase_parse(it_start, parData.cend(), gramm, sp::ascii::blank, retval);
|
||||
const bool ok = qi::phrase_parse(it_start, parData.cend(), gramm, skipper_type(), retval);
|
||||
|
||||
std::cout << "parse ok: " << std::boolalpha << ok << '\n';
|
||||
std::cout << "end == it: " << std::boolalpha << (parData.cend() == it_start) << '\n';
|
||||
|
|
|
@ -19,6 +19,33 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
|
||||
namespace kamokan {
|
||||
template <typename Iterator>
|
||||
struct IniCommentSkipper : boost::spirit::qi::grammar<Iterator> {
|
||||
IniCommentSkipper() :
|
||||
IniCommentSkipper::base_type(skipping),
|
||||
first_char(true)
|
||||
{
|
||||
namespace px = boost::phoenix;
|
||||
using boost::spirit::qi::blank;
|
||||
using boost::spirit::qi::lit;
|
||||
using boost::spirit::qi::eol;
|
||||
using boost::spirit::qi::char_;
|
||||
using boost::spirit::qi::eps;
|
||||
|
||||
skipping = comment | blank;
|
||||
comment = (eps(px::cref(first_char) == true) | eol) >>
|
||||
*blank >> lit("#")[px::ref(first_char) = false] >>
|
||||
*(!eol >> char_);
|
||||
}
|
||||
|
||||
boost::spirit::qi::rule<Iterator> skipping;
|
||||
boost::spirit::qi::rule<Iterator> comment;
|
||||
bool first_char;
|
||||
};
|
||||
} //namespace kamokan
|
||||
|
||||
namespace duck::sl {
|
||||
namespace qi = ::boost::spirit::qi;
|
||||
|
|
Loading…
Add table
Reference in a new issue