boost-spirit

Questions about Spirit.Qi sequence operator and semantic actions

喜你入骨 提交于 2019-12-24 03:04:18
问题 I have some questions about the sequence operator and semantic actions in Spirit Qi. I'm trying to define a grammar rule for a floating point number that accepts metric prefixes (u, m, k, M, etc.) as well as the normal exponent form. rule<Iterator, std::string()> sign = char_("+-") [ _val = _1 ]; rule<Iterator, std::string()> exp = char_("eE") >> -sign >> +digit; rule<Iterator, std::string()> suffix = char_("yzafpnumkKMGTPEZY") [ _val = _1 ]; rule<Iterator, std::string()> mantissa = ((*digit

Boost Spirit and abstract syntax tree design

…衆ロ難τιáo~ 提交于 2019-12-24 02:39:29
问题 I'm using Qi from Boost Spirit to parse VRML 1.0. There is a group node called Separator and immediately under Separator, many different types of nodes can be held. The AST is based upon Boost.Variant and so far is looking lengthy. I'm close to hitting the limit of 20 types in the variant. I know I can extend number of types a variant has, but I'm sure there must be a better way to design this. Ideas welcome. typedef boost::variant< Nil, Coordinate3, Info, Material, MaterialBinding, Normal,

Semantic actions runs multiple times in boost::spirit parsing

徘徊边缘 提交于 2019-12-24 01:48:46
问题 I am trying to create AST with semantic rules while parsing with boost::spirit. AST must be built only for piece of the input, another part of the input should be parsed without sintax tree. For example, for such input strings: "self.usedFoo(Bar).filter( self.baz > baz )" or "self.Foo.filter( true )" AST should be build only for bold part. And there is a problem: parser runs multimple times parsing grammar and calling semantic action (instatntiating AST nodes) multimple times too, so I got

Object in parameter specification

杀马特。学长 韩版系。学妹 提交于 2019-12-23 22:36:40
问题 Why this sentence is valid in C++? qi::rule<Iterator, std::string(), skipper<Iterator> > name; Extracted from here: Boost::spirit::qi - mini C compiler tutorial - function.hpp The definition of rule is (resumed) the following: template <typename Iterator, typename T1, typename T2, typename T3, typename T4> struct rule : boost::proto::extends<bla, bla>, parser<bla, bla> { bla, bla }; Extracted from here: rule.hpp file The rule definition expects a type, however I send it an object. It is

reuse parsed variable with boost karma

拈花ヽ惹草 提交于 2019-12-23 19:39:01
问题 I have a code base which is quite equivalent to the code below. I try to generate a text file with two times the content of a variable. I feel that the answer is in semantic actions and _a and _val but cannot manage to get through even with the documentation. How will you do to have : "toto" in str and output : toto some stuff toto i.e how to reuse a parsed variable in karma ? struct data { std::string str; }; BOOST_FUSION_ADAPT_STRUCT( data, (std::string, str) ) template <typename Iterator>

Use karma to generate output for a vector of pointers

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 18:39:45
问题 I'm having some trouble using karma to generate output for a struct that is held in a vector of boost::shared_ptrs. I've got a small test case using ints that doesn't compile. I was thinking I could use the deref_iterator customization point to handle this case or that perhaps that out-of-the-box spirit would notice that my container held a pointer type and do the extra dereference. Anyway here's the test case: #include <boost/spirit/include/karma.hpp> #include <boost/shared_ptr.hpp> #include

Boost spirit semantic actions on qi::rule

旧巷老猫 提交于 2019-12-23 17:52:19
问题 I've been reading up on semantic actions and I have a rule that looks like this: property_rule %= identifier_rule % ',' >> lit(L":") >> type_specification_rule >> -(lit(L":=") >> +(alnum - ';')) >> lit(L";"); The property_rule is defined as qi::rule<Iterator, property(), space_type> property_rule; Now, I also want to support operator ≡ so what I want is to change the rule to something like ... >> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';')) ... In the semantic action,

Boost spirit takes for ever to parse expressions

怎甘沉沦 提交于 2019-12-23 16:24:47
问题 i am new here working with boost spirit Reading alot of very good articels for boost Spirit i decide to make an own Parser and run into the Problem that parsing an Expression like this 1+(2+(3+(4+(5+(6+(7+(8))))))) takes forever on runtime.. making it more simple 1+(2+(3)) works fine. I Looks like the backtracking of the Parser is active. Please give me a hint how to modify the grammer or behaviour to make this run in time. Here is a bit code from the grammer. I use the "iter_pos" for

boost spirit, recursion and stack overflow

霸气de小男生 提交于 2019-12-23 14:57:03
问题 Why does the following code crash in run-time (it'll give a stack overflow error)? #include <boost/any.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/fusion/include/define_struct.hpp> #include <boost/fusion/adapted.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/variant.hpp> #include <iostream> #include <string> #include <vector> namespace qi = boost::spirit::qi; // Helper structs // types enum class types { void_t, int_t, double_t,

Boost::Spirit::Qi autorules — avoiding repeated copying of AST data structures

社会主义新天地 提交于 2019-12-23 14:35:12
问题 I've been using Qi and Karma to do some processing on several small languages. Most of the grammars are pretty small (20-40 rules). I've been able to use autorules almost exclusively, so my parse trees consist entirely of variants, structs, and std::vectors. This setup works great for the common case: 1) parse something (Qi), 2) make minor manipulations to the parse tree (visitor), and 3) output something (Karma). However, I'm concerned about what will happen if I want to make complex