boost-spirit-qi

Boost Spirit Qi Custom Syntesized Attribute (Set a specific member of a struct attribute via a semantic action)

白昼怎懂夜的黑 提交于 2019-12-21 01:45:26
问题 Suppose I have a structure that I want to parse into with Spirit Qi, that is defined as such: struct data_ { bool export; std::wstring name; data_() : export(false) {} }; Also, suppose the struct has been adapted to fusion like this: BOOST_FUSION_ADAPT_STRUCT( data_, (bool, export) (std::wstring, name) ) And the associated rule is: qi::rule<Iterator, data_(), skipper<Iterator> > rule_data; rule_data = -lexeme["SpecialText" >> !(alnum | '_')] [ boost::phoenix::at_c<0> = true ] // If this

Parsing a grammar with Boost Spirit

一笑奈何 提交于 2019-12-20 10:42:12
问题 I am trying to parse a C-function like tree expressions like the following (using the Spirit Parser Framework): F( A() , B( GREAT( SOME , NOT ) ) , C( YES ) ) For this I am trying to use the three rules on the following grammar: template< typename Iterator , typename ExpressionAST > struct InputGrammar : qi::grammar<Iterator, ExpressionAST(), space_type> { InputGrammar() : InputGrammar::base_type( ) { tag = ( qi::char_("a-zA-Z_") >> *qi::char_("a-zA-Z_0-9") )[ push_back( at_c<0>(qi::_val) ,

Using boost::spirit::qi to parse numbers with separators

微笑、不失礼 提交于 2019-12-18 09:02:13
问题 I am attempting to use boost::spirit::qi to do some parsing. It's actually going quite well, and I successfully have managed to parse numbers in various bases based on a suffix. Examples: 123, c12h, 777o, 110101b. I then wanted to add the ability to allow a completely ignored separator character, to allow values like 123_456 or 1101_0011b to parse. I tried using the skip parser, but I highly suspect that I completely misunderstood how it was to be used. It compiles just fine, but my attempt

Boost Spirit Qi: Omit element in Kleene Star parser

限于喜欢 提交于 2019-12-18 08:58:33
问题 I want to parse special constructs and throw the rest away. But I don't want to use a skipper. I want to get a vector of these constructs, so I use a Kleene Star parser as main rule. But, everytime something gets thrown away, a default constructed element is inserted into the vector. Here is a made up example. It just looks for the string Test and throws the rest away, at least this is the plan. But every time the rule garbage succeeds it adds a default constructed item to the vector in the

Boost.Spirit.Qi crashes when assigning rule to a sequence including itself

橙三吉。 提交于 2019-12-18 08:55:31
问题 I have the following MWE: #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/support_istream_iterator.hpp> namespace spirit = boost::spirit; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; int main() { std::string input("1 2"); qi::rule<std::string::iterator, void(), qi::space_type> parser; qi::rule<std::string::iterator, void(), qi::space_type> parser2; qi::rule<std::string::iterator, void(

boost spirit parse with the source

青春壹個敷衍的年華 提交于 2019-12-18 08:46:11
问题 I would like to be able to parse a Number, to store its original source and to track its position in the source preserving it in the structure itself. This is what I have so far: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/home/support/iterators/line_pos_iterator.hpp> #include

boost spirit parse with the source

故事扮演 提交于 2019-12-18 08:44:12
问题 I would like to be able to parse a Number, to store its original source and to track its position in the source preserving it in the structure itself. This is what I have so far: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/home/support/iterators/line_pos_iterator.hpp> #include

Boost::spirit::qi defining a calculator for nullaries

我的梦境 提交于 2019-12-18 08:41:06
问题 I'm trying to write a parser for math expressions where named variables are nullaries in boost::spirit (version 1_51_0), to which I'm completely new. I define typedef boost::function<double()> Value and my rules will be declared like so: qi::rule<Iterator, Value()> expression, term, others, ...; I define binary operators on nullaries with this macro #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \

Boost::spirit::qi defining a calculator for nullaries

夙愿已清 提交于 2019-12-18 08:40:03
问题 I'm trying to write a parser for math expressions where named variables are nullaries in boost::spirit (version 1_51_0), to which I'm completely new. I define typedef boost::function<double()> Value and my rules will be declared like so: qi::rule<Iterator, Value()> expression, term, others, ...; I define binary operators on nullaries with this macro #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \

How can I use the skipper ascii::space WITHOUT skipping eol?

爱⌒轻易说出口 提交于 2019-12-17 22:37:16
问题 I have to use boost::spirit for parsing, and I want use phrase_parse function : qi::phrase_parse(str.begin(), str.end(), grammar, ascii::space - qi::eol); But the fourth term (ascii::space - qi::eol), isnt allowed by my compiler. How can I use the skipper ascii::space WITHOUT skipping eol ? 回答1: The simplest answer is qi::phrase_parse(str.begin(), str.end(), grammar, ascii::blank); Of course, it depends on your grammar too: if it expects a specific skipper class you might need to change that.