boost-spirit

Boost spirit take away keyword and ignore skipper

岁酱吖の 提交于 2019-12-24 12:12:43
问题 This is a small part of a grammer using expressions. prefix = (lit(L"not") >> prefix) |(lit('-') >> prefix) | postfix ; Some way inside postfix I have name_pure to take an identifier .. name_pure = lexeme[+(boost::spirit::standard_wide::alpha | '_') >> *(boost::spirit::standard_wide::alnum | '_')]; So far all is fine. Can write something like a=not b But if I start to use not as a name prefix like this one a=not notvarname I get a parser Output from the AST which look like this a=not not

boost spirit - unable to get attributes

我是研究僧i 提交于 2019-12-24 11:34:37
问题 I have the following code: #define BOOST_SPIRIT_DEBUG #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> #include <vector> struct parameter { std::string type; std::string name; }; BOOST_FUSION_ADAPT_STRUCT( parameter, (std::string, type) (std::string, name) ) inline std::ostream& operator<<(std::ostream& os, const parameter& param) { os << param.type << ' ' << param.name; return

Implicit cast doesnt work for BOOST_STRONG_TYPEDEF and BOOST_SPIRIT_DEBUG_NODE

无人久伴 提交于 2019-12-24 10:58:39
问题 I have defined a boost::spirit::qi rule: boost::spirit::qi::rule<Iterator, Identifier()> id; where Identifier is defined by: BOOST_STRONG_TYPEDEF(std::string, Identifier) but when I use BOOST_SPIRIT_DEBUG_NODE(id); It fails to compile with following error: boost_1_51_0/boost/spirit/home/support/attributes.hpp:1203: error: no match for 'operator<<' in 'out << val' and it lists the overloaded operators of ostream. Knowing that BOOST_STRONG_TYPEDEF defines a cast operator to the original type,

Boost Spirit : something like permutation, but not exactly

Deadly 提交于 2019-12-24 10:52:03
问题 I'm trying to get a grasp of Spirit, meaning I'm a noob at it (hence expect lack of proper terminology in the below). I have to parse this: value1 = 10 value2 = 20 value3 = 30 value4 = 40 Order doesn't matter but each "value1" ... "value4" line must be present exactly once. This would be OK: value1 = 10 value4 = 40 value2 = 20 value3 = 30 but this would not be OK (duplicated "value1"): value1 = 10 value2 = 20 value3 = 30 value4 = 40 value1 = 10000 Nor this (missing "value4"): value1 = 10

Why does parsing a blank line with Spirit produce an empty key value pair in map?

橙三吉。 提交于 2019-12-24 10:27:55
问题 I'm trying to use Spirit.Qi to parse a simple file format that has key value pairs separated with an equals sign. The file also supports comments and blank lines, as well as quoted values. I can get nearly all of this to work as expected, however, any blank lines or comments cause an empty key value pair to be added to the map. When the map is traded for a vector, no blank entries are produced. Example Program: #include <fstream> #include <iostream> #include <string> #include <map> #include

Virtual classes as AST nodes with Spirit

旧街凉风 提交于 2019-12-24 10:22:09
问题 i was working on an interpreter for a language with a friend, and we started with a decision I'm guessing wasn't that wise: we made all the elements for execution first (practically a tree made of different classes); but now looking at boost examples i get a lot confused about how to merge the two. I know what to start from (the grammar), i know what to reach (instantiated classes owning each other), i don't know how to reach it. We started with expressions without variables, hence we looked

boost spirit parsing with no skipper

纵然是瞬间 提交于 2019-12-24 08:57:06
问题 Think about a preprocessor which will read the raw text (no significant white space or tokens). There are 3 rules. resolve_para_entry should solve the Argument inside a call. The top-level text is returned as string. resolve_para should resolve the whole Parameter list and put all the top-level Parameter in a string list. resolve is the entry On the way I track the iterator and get the text portion Samples: sometext(para) → expect para in the string list sometext(para1,para2) → expect para1

Boost spirit semantic action not invoked

痴心易碎 提交于 2019-12-24 04:27:10
问题 I've been trying to parse a string with Boost Spirit like following: integer_count int1 int2 int3 ... intN Where N is the integer_count. For example, 5 1 2 3 4 5 The code is following: #define BOOST_SPIRIT_USE_PHOENIX_V3 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <string> namespace qi = boost::spirit::qi; namespace spirit = boost::spirit; namespace ascii = boost::spirit::ascii; using boost::phoenix::ref; template <typename Iterator> struct x

How to get error position using the spirit parser

佐手、 提交于 2019-12-24 03:39:07
问题 I wrote a simple parser with spirit, akin to json (but simpler and more specialised). By following the advice in here, I tried to implement error handling by tracking the error position. In particular, my parsing function is as follows bool parse_properties(std::istream& is, const std::string &filename, PropertyList &pset) { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace classic = boost::spirit::classic; typedef std::istreambuf_iterator<char> base_iterator

Can't call a lazy lambda function with parameters via boost::phoenix::function

我与影子孤独终老i 提交于 2019-12-24 03:37:25
问题 I tried to call boost::phoenix::function based on lambda function with parameters and failed. If I call it without parameters in such a way: const auto closure = [](){ cout<< "test" << endl; }; typedef decltype(closure) ClosureType; const boost::phoenix::function<ClosureType> lazyFunc (std::move(closure)); lazyFunc()(); all compiles nice. But when I declare at least one parameter of lambda: const auto closure = [](int& param) { cout<<"Test" << param << endl; }; typedef decltype(closure)