boost-spirit-x3

Parser rule dependent on parameter

空扰寡人 提交于 2019-12-23 22:06:03
问题 I was trying to define a parser where the rules are not fully pre-defined, i.e. they contain a variable part. This was no problem with Spirit Qi, but I was not able to implement it due to the static nature of X3. I tried the with directive , which is unfortunately undocumented, but without luck so far. The only examples I found so far are inside a lambda expression. I constructed a simple example to demonstrate the issue: parsing integers where the separator is given as a parameter. #include

parse into vector<boost::string_view> using boost::spirit::x3

无人久伴 提交于 2019-12-23 12:36:14
问题 This is a follow-up question to my previous one regarding boost::spirit::x3 and boost::string_view . While I can parse into a std::vector<std::string> (live example), parsing into a std::vector<boost::string_view> fails with the following compile errors: #include <iostream> #include <string> #include <boost/utility/string_view.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits { template <typename It> void move_to(It b, It e, boost::string_view& v) { v = boost::string

error handling and annotation in Boost.Spirit X3

大城市里の小女人 提交于 2019-12-23 09:55:56
问题 What is the logic under using boost::spirit::x3::position_tagged as base class for some AST nodes (how to choose which should be tagged, e.g. for C-like language?) and other constructions, used in rule ID definition, like: struct error_handler_tag; struct error_handler_base { template< typename Iterator, typename Exception, typename Context > x3::error_handler_result on_error(Iterator & /*first*/, Iterator const & /*last*/, Exception const & x, Context const & context) { std::string message_

Spirit X3, semantic action makes compilation fails with: Attribute does not have the expected size

喜夏-厌秋 提交于 2019-12-23 07:47:35
问题 This code does not compiles (gcc 5.3.1 + boost 1.60): #include <boost/spirit/home/x3.hpp> namespace x3 = boost::spirit::x3; template <typename T> void parse(T begin, T end) { auto dest = x3::lit('[') >> x3::int_ >> ';' >> x3::int_ >> ']'; auto on_portal = [&](auto& ctx) {}; auto portal = (x3::char_('P') >> -dest)[on_portal]; auto tiles = +portal; x3::phrase_parse(begin, end, tiles, x3::eol); } int main() { std::string x; parse(x.begin(), x.end()); } It fails with a static assertion: error:

Overloaded output operator not found for Boost.Spirit expression

人盡茶涼 提交于 2019-12-22 14:52:39
问题 This is a follow-up on this Q&A. I now have several data structures in a namespace ast , subdivided over two sub-namespaces ( algebraic and numeric ) that correspond to the two different formats that the grammar recognizes. namespace ast { namespace algebraic { struct occupance { char pc; char col; int row; }; using pieces = std::vector<occupance>; struct placement { char c; boost::optional<pieces> p; }; } namespace numeric { struct occupance { char pc; int sq; }; struct range { occupance oc;

Boost-Spirit (X3) parsing without default constructors

怎甘沉沦 提交于 2019-12-21 23:57:13
问题 I'm trying to use Spirit X3 from Boost 1.65.1 to make a parser. I have reduced my problem to the following smaller example with simpler structures: #include <boost/config/warning_disable.hpp> #include <boost/spirit/home/x3.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <iostream> #include <vector> struct MyPair { MyPair(int x, int y) : mx(x), my(y) {}; //MyPair() {} // No default constructor - neither needed nor wanted. int mx; int my; }; /* BOOST_FUSION_ADAPT_STRUCT( MyPair,

Using std::array as Attribute for boost::spirit::x3

江枫思渺然 提交于 2019-12-21 04:40:25
问题 I'm trying to parse a list of numbers into a fixed sized std::array container using boost::spirit's newest release x3 (as included in boost 1.54). Since std::array has the necessary functions, it is detected as an Container, but it is lacking the insert function which makes it incompatible. Here is a short example of what I am trying to accomplish: #include <boost/spirit/home/x3.hpp> #include <array> #include <iostream> #include <string> namespace x3 = boost::spirit::x3; namespace ascii =

parsing from std::string into a boost::string_view using boost::spirit::x3

独自空忆成欢 提交于 2019-12-19 04:12:48
问题 In my my previous question it was suggested that the performance of my boost::spirit::x3 parser could be improved by parsing into a boost::string_view using the raw directive. However, I have difficulties getting it to compile. This is what I found out: Before x3 , one had to specialize assign_to_attribute_from_iterators (see e.g. this SO answer) to handle the raw directive. x3 now uses the move_to free function instead (see e.g. this SO answer). I therefore added a move_to overload which

Attributes from Boost.Spirit grammar: error from std:vector of boost::variant

陌路散爱 提交于 2019-12-18 08:48:23
问题 I got a working parser for reading position descriptions for a board game (international draughts, official grammar): #include <boost/spirit/home/x3.hpp> #include <iostream> namespace x3 = boost::spirit::x3; auto const colon = x3::lit(':'); auto const comma = x3::lit(','); auto const dash = x3::lit('-'); auto const dot = x3::lit('.'); auto const king = x3::char_('K'); auto const color = x3::char_("BW"); auto const num_sq = x3::int_; auto const num_pc = -king >> num_sq; // Kxx means king on

X3: How to create parser to read in sets?

梦想与她 提交于 2019-12-13 14:26:50
问题 How would one create a rule for reading integers in sets of 3. I.e., ... 1 2 3 OK, 1 set of 3 ints 1 2 3 4 5 6 OK, 2 sets of 3 ints 1 2 3 4 5 ERROR, 1 set of 3 ints, 1 short for 2nd 1 2 3 4 5 6 7 8 9 OK, 3 sets of 3 ints 1 2 3 4 5 6 7 8 9 10 ERROR, 3 sets of 3 ints, 1 short for 4th I'm having issue with the fusion adapt struct (how to make the number of args variable) ... BOOST_FUSION_ADAPT_STRUCT(client::ast::number, n1, n2, n3, n4, n5, n6) And not sure why this rule wouldn't work. ... = *