boost-spirit-x3

x3 linker error with separate TU

送分小仙女□ 提交于 2019-12-06 14:02:59
As my parser grows I separated some rules into different translation units (TU) and the linker problem rises. After weeks of several try&errors without success I reduced my ~50 rules to the (hopefully) minimal example presented here. I've read the related linking errors while separate parser using boost spirit x3 and checked, that I use at the context typedef iso8859_1::space_type and that I invoke iso8859_1::space later on. Also I don't let the compiler deduce the iterator_type. The linker error I made more fancy by replacing some things: In function `bool x3::rule<parser::string_literal

Dynamically switching symbol tables in x3

六眼飞鱼酱① 提交于 2019-12-06 12:47:56
问题 Given the following x3 grammar that parses correctly, I want to add validation of parameters, qualifiers, and properties. This would seem to indicate some method of dynamically switching which symbol table is being used within the various rules. What is the best way to implement this? It would seem to be some mixture of semantic actions and attributes, but it is not clear to me how. #include <string> #include <vector> #include <iostream> #include <iomanip> #include <map> #include <boost

X3, how to populate a more complex AST?

喜欢而已 提交于 2019-12-06 09:27:23
Trying to generate an AST like the employee example that has more than just the employee. In my current mindset, the RExpressions example isn't helping me. The example I have doesn't compile, but I went as far as I understood in adding teams, departments, and corporations to the employee example. My problem is in understanding how to add the different structs into a variant and add the variant to phrase_parse, if that's the idea. In this example, there can be several of the same lines following each other. So wondering if that's what requires making an AST recursive. #include <boost/config

Strange semantic behaviour of boost spirit x3 after splitting

偶尔善良 提交于 2019-12-06 08:31:37
问题 I came across a strange behaviour of boost spirit x3, after I splittet my grammar up into the recommended parser.hpp , parser_def.hpp , parser.cpp files. My example gramar parses some kind of easy enums: enum = "enum" > identifier > "{" > identifier % "," > "} this is my enum grammar. When I don't split the enum and identifier parser into the recommended files, everything works fine, especially the string "enum {foo, bar}" throws an expectation failure, as expected. This example can be found

Recursive rule in Spirit.X3

允我心安 提交于 2019-12-06 08:30:17
问题 I want to parse a recursive grammar with Boost.Spirit x3, but it fails with a template instantiation depth problem. The grammar looks like : value: int | float | char | tuple int: "int: " int_ float: "float: " real_ char: "char: " char_ tuple: "tuple: [" value* "]" Here is a contained example: #include <boost/fusion/adapted.hpp> #include <boost/spirit/home/x3.hpp> #include <string> #include <vector> #include <variant> struct value: std::variant<int,float,std::vector<value>> { using std:

Recursive x3 parser with results passing around

a 夏天 提交于 2019-12-06 07:41:42
(1) Say we want to parse a simple recursive block surrounded by {} . { Some text. { { Some more text. } Some Text again. {} } } This recursive parser is quite simple. x3::rule<struct idBlock1> const ruleBlock1{"Block1"}; auto const ruleBlock1_def = x3::lit('{') >> *( ruleBlock1 | (x3::char_ - x3::lit('}')) ) >> x3::lit('}'); BOOST_SPIRIT_DEFINE(ruleBlock1) (2) Then the block becomes more complex. It could also be surrounded by [] . { Some text. [ { Some more text. } Some Text again. [] ] } We need somewhere to store what kind of opening bracket that we have. Since x3 does not have locals, we

Overloaded output operator not found for Boost.Spirit expression

巧了我就是萌 提交于 2019-12-06 07:31:14
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; int sq; }; using pieces = std::vector<boost::variant<range, occupance>>; struct placement { char c;

Can spirit X3 work with BOOST_FUSION_ADAPT_ADT?

自闭症网瘾萝莉.ら 提交于 2019-12-06 03:06:32
Change my codes from QI to X3, and get some compile error with BOOST_FUSION_ADAPT_ADT . I tried boost 1.64 and 1.67, neither of them work. I modified the spirit X3 example rexpr_min , adding getter and setter to struct rexpr , changing the BOOST_FUSION_ADAPT_STRUCT to BOOST_FUSION_ADAPT_ADT , and compile it fail, too. Enviroment: ubuntu 16.04 G++ 5.4, with -std=c++17 flag boost 1.67 Error message: boost/spirit/home/x3/core/detail/parse_into_container.hpp:142:35: error: invalid initialization of non-const reference of type ‘boost::fusion::extension::adt_attribute_proxy<client::ast::rexpr, 0,

Boost Spirit X3 AST not working with semantic actions when using separate rule definition and instantiation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 11:31:14
I am trying to use Boost Spirit X3 with semantic actions while parsing the structure to an AST. If I use a rule without separate definition and instantiation it works just fine, for example: #include <vector> #include <string> #include <iostream> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/home/x3.hpp> namespace ast { struct ast_struct { int number; std::vector<int> numbers; }; } BOOST_FUSION_ADAPT_STRUCT( ast::ast_struct, (int, number) (std::vector<int>, numbers) ) namespace x3 = boost::spirit::x3; using namespace std; void parse( const std::string &data ) { string

X3 parse rule doesn't compile

心已入冬 提交于 2019-12-05 03:55:21
问题 I'm learning Boost Spirit by writing a parser that parses two variants of hex number used by NAMS: Hex number with either suffix of 0x / 0h or prefix of h / x . Hex number with prefix of $ and must be followed by a decimal digit. Here is what I have come up so far and with Coliru Session: //#define BOOST_SPIRIT_X3_DEBUG #include <iostream> #include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3/support/ast/variant.hpp> #include <boost/spirit/include/support_extended_variant.hpp>