boost-spirit

Boost Spirit lexeme vs no_skip

本小妞迷上赌 提交于 2021-02-05 07:46:36
问题 As like the description on Boost.Spirit, the only difference between lexeme and no_skip is the pre_skip. But after some test, I'm still confusing about the exactly meaning for pre_skip. So what kind of condition will make a difference, maybe a example can help me understand it much better. Thanks! 回答1: Pre-skip ignores whitespace at the start of the expression. Contrasting: Live On Coliru #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; static std::string const input =

Handling utf-8 in Boost.Spirit with utf-32 parser

筅森魡賤 提交于 2021-02-04 16:01:17
问题 I have a similar issue like How to use boost::spirit to parse UTF-8? and How to match unicode characters with boost::spirit? but none of these solve the issue i'm facing. I have a std::string with UTF-8 characters, i used the u8_to_u32_iterator to wrap the std::string and used unicode terminals like this: BOOST_NETWORK_INLINE void parse_headers(std::string const & input, std::vector<request_header_narrow> & container) { using namespace boost::spirit::qi; u8_to_u32_iterator<std::string::const

Issue with X3 and MS VS2017

三世轮回 提交于 2021-01-29 10:30:46
问题 I am having a weird problem with boost spirit X3 (v1.69) in combination with MS VS2017. I am getting compiling errors in well formed structures. When I use the same code block in gcc and clang through Coliru or Wandbox, the source compiles and everything goes right. But when I use that same code in VS 2017, compiling errors appears until I comment an 'omit' sentence. Please, any help with this? #include <vector> #include <iostream> #include <boost/spirit/home/x3.hpp> #include <boost/fusion

Parsing CSS with Boost.Spirit X3

我与影子孤独终老i 提交于 2021-01-29 06:23:04
问题 I'm attempting to write a (partial) CSS parser using Boost.Spirit X3. I have the (very) basic setup working: const auto declaration_block_def = '{' >> +declaration >> '}'; const auto declaration_def = property >> ':' >> value >> ';'; const auto property_def = +(char_ - ":"); const auto value_def = +(char_ - ";"); Here value is just a simple string parser, and property a symbol table of all the CSS property names to an enum listing all the properties. But now I wonder if I couldn't in some way

Compile error with boost::spirit::x3

拟墨画扇 提交于 2021-01-29 05:14:32
问题 I tried to compile example file with gcc 5.3.1 ( 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC) ), boost 1.61.0. #include <boost/config/warning_disable.hpp> #include <boost/spirit/home/x3.hpp> #include <iostream> // Presented are various ways to attach semantic actions // * Using plain function pointer // * Using simple function object namespace client { namespace x3 = boost::spirit::x3; using x3::_attr; struct print_action { template <typename Context> void operator()(Context const& ctx) const { std

How to move results parsed results into a struct using spirit x3

橙三吉。 提交于 2021-01-29 03:50:37
问题 I want to parse an input buffer containing function prototypes into a vector of function prototypes. I have created a function prototype struct that has 3 members: returnType, name and argument list. I am running into a compiler error that complains that it is unable to move the parsed results into the struct. Am I missing something? //#define BOOST_SPIRIT_X3_DEBUG #include <boost/spirit/home/x3.hpp> #include <boost/fusion/adapted.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp>

boost spirit parsing quote string fails

旧街凉风 提交于 2021-01-28 11:50:25
问题 This is my grammer unesc_char.add(L"\\a", L'\a')(L"\\b", L'\b')(L"\\f", L'\f')(L"\\n", L'\n') (L"\\r", L'\r')(L"\\t", L'\t')(L"\\v", L'\v')(L"\\\\", L'\\') (L"\\\'", L'\'')(L"\\\"", L'\"'); unesc_str = '\"' >> *((boost::spirit::standard_wide::char_ - '\"') | unesc_char) >> '\"'; with qi::rule<Iterator, std::wstring()> unesc_str; qi::symbols<wchar_t const, wchar_t const> unesc_char; Parsing fails on : "Hello\"" -> should return Hello" Parsing correct on : "Hello\\" -> should return Hello\

Replace lit with different string in boost spirit

江枫思渺然 提交于 2021-01-28 05:13:37
问题 I'm trying to parse a quoted string containing escape sequences using boost spirit. I'm looking for a way to replace escape sequences \" with the corresponding character ( " in this case). So far I've come up with this. c_string %= lit('"') >> *(lit("\\\"")[push_back(_val, '"')] | (char_ - '"')) >> lit('"') with the replacement being done with lit("\\\"")[push_back(_val, '"')] however this seems to me quite clumsy and unreadable. Is there a better way to accomplish this? 回答1: Iterating: you

How to use Boost Spirit auto rules with AST?

别说谁变了你拦得住时间么 提交于 2021-01-27 07:57:32
问题 EDIT: I expanded sehe's example to show the problem when I want to use it on another rule: http://liveworkspace.org/code/22lxL7$17 I'm trying to improve the performances of my Boost Spirit parser and I saw that since C++11, it was possible to use auto-rules like that: auto comment = "/*" >> *(char_ - "*/") >> "*/"; (or with BOOST_AUTO or BOOST_SPIRIT_AUTO). I have a rule declarer like that: qi::rule<lexer::Iterator, ast::SimpleType()> simple_type; and defined like that: simple_type %= const_

How to use Boost Spirit auto rules with AST?

我们两清 提交于 2021-01-27 07:53:17
问题 EDIT: I expanded sehe's example to show the problem when I want to use it on another rule: http://liveworkspace.org/code/22lxL7$17 I'm trying to improve the performances of my Boost Spirit parser and I saw that since C++11, it was possible to use auto-rules like that: auto comment = "/*" >> *(char_ - "*/") >> "*/"; (or with BOOST_AUTO or BOOST_SPIRIT_AUTO). I have a rule declarer like that: qi::rule<lexer::Iterator, ast::SimpleType()> simple_type; and defined like that: simple_type %= const_