boost-spirit

boost::Spirit Grammar for unsorted schema

五迷三道 提交于 2019-12-05 17:52:22
I have a section of a schema for a model that I need to parse. Lets say it looks like the following. { type = "Standard"; hostname="x.y.z"; port="123"; } The properties are: The elements may appear unordered. All elements that are part of the schema must appear, and no other. All of the elements' synthesised attributes go into a struct. (optional) The schema might in the future depend on the type field -- i.e., different fields based on type -- however I am not concerned about this at the moment. According to the Spirit forums, the following is the answer. You might want to have a look at the

in boost::spirit::qi, is it possible to dynamically modify rule definition in runtime

♀尐吖头ヾ 提交于 2019-12-05 17:37:26
I wrote some grammar with boost::spirit::qi::rule to parse the internet packet. the grammar is something like: qi::rule<Iterator> start, request, response, status, query ; start = (request | response | status | query) >> lit("\r\n"); to improve the performance, user maybe want to skip some rules in the runtime, e.g. ignore "response","status","query" and only try to match request, so the rule will change to: start = (request ) >> lit("\r\n"); is it possible to do that? e.g, is there a function like "disable()" to just disable the rule "response", "status" and "query"? sehe The most natural

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

how to parse and verify an ordered list of integers using qi

穿精又带淫゛_ 提交于 2019-12-05 08:53:33
I'm parsing a text file, possibly several GB in size, consisting of lines as follows: 11 0.1 14 0.78 532 -3.5 Basically, one int and one float per line. The ints should be ordered and non-negative. I'd like to verify the data are as described, and have returned to me the min and max int in the range. This is what I've come up with: #include <iostream> #include <string> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/std_pair.hpp> namespace px = boost::phoenix; namespace qi = boost::spirit::qi; namespace my_parsers { using

How to use boost::spirit to parse a sequence of words into a vector?

独自空忆成欢 提交于 2019-12-05 05:09:33
I'm trying to learn boost::spirit . As an example, I'm trying to parse a sequence of words into a vector<string> . I tried this: #include <boost/spirit/include/qi.hpp> #include <boost/foreach.hpp> namespace qi = boost::spirit::qi; int main() { std::vector<std::string> words; std::string input = "this is a test"; bool result = qi::phrase_parse( input.begin(), input.end(), +(+qi::char_), qi::space, words); BOOST_FOREACH(std::string str, words) { std::cout << "'" << str << "'" << std::endl; } } which gives me this output: 'thisisatest' but I wanted the following output, where each word is matched

How to parse a mathematical expression with boost::spirit and bind it to a function

こ雲淡風輕ζ 提交于 2019-12-05 04:28:50
问题 I would like to define a function taking 2 arguments double func(double t, double x); where the actual implementation is read from an external text file. For example, specifying in the text file function = x*t; the function should implement the multiplication between x and t , so that it could be called at a later stage. I'm trying to parse the function using boost::spirit. But I do not know how to actually achieve it. Below, I created a simple function that implements the multiplication. I

Operator precedence in boost::spirit?

谁说我不能喝 提交于 2019-12-05 04:10:23
I made some tests using the spirit mini_c sample. Unfortunately it does not keep the operator precedence as expected: int main() { return 3 > 10 || 3 > 1; } evaluates to 0. return (3 > 10) || (3 > 1); returns 1 I tried to move the definition of "||" and "&&" to the very top in the constructor of template <typename Iterator> expression<Iterator>::expression( but that does not change anything. How can that be fixed. I am using boost 1.3.38. Confirmed, that's a bug in the mini_c example related to operator precedence. I committed a fix to SVN, which will be available in Boost V1.45. Here is what

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>

What is the most efficient way to recalculate attributes of a Boost Spirit parse with a different symbol table?

孤人 提交于 2019-12-05 02:56:25
问题 I'm using Boost Spirit to implement functionality in some software that allows the user to enter a mathematical equation that will be repeatedly applied to an input stream. Input stream values are represented as symbols using boost::spirit::qi::symbols which the user can reference in their equation. (e.g. out1 = 3 * in1 + in2 ) Parsing and compiling the user's equation is not performance sensitive but calculating its output value is as it forms part of a time-critical pipeline. The standard

How to put results into a STL map by using boost-spirit?

江枫思渺然 提交于 2019-12-05 02:46:14
问题 #include <QtCore/QCoreApplication> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <iostream> #include <string> #include <list> #include <map> #define CODE_CPP_KEYWORD_ENUM "enum" namespace haha { //简单表示c++的enum的类(A structure use to simply description C++ enum) struct CPPCodeEnum { //enum的名称(enum Name) ::std::string enumName; //成员的名称(enum Members‘name) ::std::list<::std::string> enumMembers; }; } namespace haha { namespace fusion = boost::fusion;