FAQ Database Discussion Community


making shared_ptr's from Boost.Spirit.Qi

c++,parsing,boost,shared-ptr,boost-spirit-qi
I would like to use a Spirit Qi grammar to parse text into shared pointers to strings. Actually, I would like to parse multivariate polynomials into a system of them, with various kinds of previously-encountered symbols appearing in the polynomials, but for now, let's parse from text into std::shared_ptr<std::string>. I...

parsing into std::vector with Spirit Qi, getting segfaults or assert failures

c++,parsing,boost,boost-spirit,boost-spirit-qi
I am using Spirit Qi as my parser, to parse mathematical expressions into an expression tree. I keep track of such things as the types of the symbols which are encountered as I parse, and which must be declared in the text I am parsing. Namely, I am parsing Bertini...

boost::spirit::qi - Working with instance members in grammar struct

c++,grammar,boost-spirit,boost-spirit-qi
I am trying to create a grammar for parsing RTF files. At some points I need to store some information in the scope of the grammar. I know, that I could use inherited attributes, but this would worsen readability. So I asked myself if instance member variables of the grammar...

how to use list syntax with defaults spirit

c++,boost-spirit-qi
I am attempting to parse comma separated integers, with possible blanks. For instance, 1,2,,3,,-1 should be parsed as {1,2,n,3,n,-1} where is n is some constant. The expression, (int_ | eps) % ',' works when n == 0. More specifically, the following code works special cased for 0: #include <boost/spirit/include/qi.hpp> #include...

Parse c-struct-like declaration with boost::spirit

c++,boost,boost-spirit,boost-spirit-qi
I want to parse a c-struct-like declaration which has some scalars or arrays as members. Then a C++ header file which has this c-struct definition can be generated for HDF5 serialization. But I found some difficulty when tried to handle scalars and arrays using boost::spirit at the same time. #include...

Splitting string using boost spirit

c++,split,boost-spirit,boost-spirit-qi,string-split
Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile template <typename Iterator> struct ValueList : bsq::grammar<Iterator, std::vector<std::string>()> { ValueList(const std::string& sep, bool isCaseSensitive) : ValueList::base_type(query) { if(isCaseSensitive) { query =...

How to use the qi::hold[] Parser directive. (Issue with attribute type for boost::swap)

c++,boost,swap,boost-spirit,boost-spirit-qi
I have a parser that parses into a boost::variant<int, double, std::string> namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; using namespace std; typedef map<string, boost::variant<int, double, string> > namevalue; typedef pair<string, boost::variant<int, double, string> > namevaluepair; template <typename Iterator> struct keys_and_values2 : grammar<Iterator, namevalue(), ascii::blank_type> { keys_and_values2() : keys_and_values2::base_type(start) {...

Error when compiling a grammar with debug activated

visual-studio,debugging,boost,boost-spirit,boost-spirit-qi
I'm trying to debug a boost::spirit grammar that I want to use in a Visual Studio project: This is my code snippet: #include <boost/spirit/include/classic.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> // This is pasted and copied from another header file namespace StateMachine { namespace Private { struct LuaParameterData { std::wstring name; std::wstring...

boost qi::phrase_parse reads only first element

c++,boost,boost-spirit-qi
I've implemented simple ascii parser using boost::spirit. target ascii file looks like n 0 23 45 10.0 0.5 ..... n-1 x y ..... but it returns in measure_list only 1 element if I am trying to read ASCII as a simple vector<double> instead of structured for example - it works...

Getting compilation errors while binding a rule production to my struct members

c++,boost-spirit,boost-spirit-qi,boost-phoenix
Writing Qi grammar with Phoenix bind I got a compilation error like boost/spirit/home/support/context.hpp(180): error C2338: index_is_out_of_bounds here >> ruleHandId_[phx::bind(&parseContext::handId_, qi::_r1) = qi::_1]; I just havent too much expirience with phoenix binding but perv bind in the line ruleStart_ = ruleEncoding_[phx::bind(&parseContext::encoding_, qi::_r1) = qi::_1] works good without compilation errors It's all...

Parsing comma separated grammars when unordered

c++,parsing,boost,boost-spirit,boost-spirit-qi
From a previous post I found a way to parse with boost::spirit a struct of this type: "parameter" : { "name" : "MyName" , "type" : "MyType" , "unit" : "MyUnit" , "cardinality" : "MyCardinality", "value" : "MyValue" } It's a simple JSON with key-value pairs. Now I want to...

Iterative update of abstract syntax tree with boost spirit

c++,boost,abstract-syntax-tree,boost-spirit,boost-spirit-qi
I have a working boost spirit parser and was thinking if it is possible to do iterative update of an abstract syntax tree with boost spirit? I have a struct similar to: struct ast; typedef boost::variant< boost::recursive_wrapper<ast> > node; struct ast { std::vector<int> value; std::vector<node> children; }; Which is being...

boost spirit repetition parser behaves unexpectedly

boost-spirit-qi
using boost 1.57 spirit::qi under windows 7 I'm working on an ipv6 parser and must be misunderstanding how repetition parser directives work. Given the following (simplified) ipv6part = repeat(1, 4)[xdigit]; ipv6address = -(repeat(1,4)[ipv6part >> lit(':')] >> ipv6part) >> lit("::") >> ipv6part >> lit(':') >> ipv6part | ... I would expect...

C++ Boost spirit, parse a 2D array (and more) into a struct

c++,arrays,boost-spirit-qi
I am trying to modify the following example : http://www.boost.org/doc/libs/1_57_0/libs/spirit/example/qi/employee.cpp I would like to add a 2D vector in the employee struct, such as : struct employee { int age; std::string surname; std::string forename; double salary; std::vector<std::vector<int> > work_hours; }; To parse something like employee{42, "Foo", "Bar", 0 1 2...

Parsing heterogeneous data using Boost::Spirit

c++,boost,boost-spirit,boost-spirit-qi
I'm trying to figure out how to approach the following problem. I have a structure of the following format: struct Data { time_t timestamp; string id; boost::optional<int> data1; boost::optional<string> data2; // etc... }; This should be parsed out of a single line string in the following format: human_readable_timestamp;id;key1=value1 key2=value2..... Of...

How do I convert boost::spirit::qi::lexeme's attribute to std::string?

c++,boost,boost-spirit,boost-spirit-qi,boost-phoenix
Consider: struct s { AttrType f(const std::string &); }; ...and a rule r with an attribute AttrType: template <typename Signature> using rule_t = boost::spirit::qi::rule<Iterator, Signature, boost::spirit::qi::standard::space_type>; rule_t<AttrType()> r; r = lexeme[alnum >> +(alnum | char_('.') | char_('_'))][ _val = boost::phoenix::bind(&s::f, s_inst, _1) ]; When compiling this (with clang), I get...

boost spirit: how to match any lexer token in qi?

c++,boost,boost-spirit,boost-spirit-qi,boost-spirit-lex
I would like to match a C++ function declaration with default argument values, but ignoring these values. For example: int myFunction(int a, int b = 5 + 4); Here is (a part of) the lexer: struct Lexer : boost::spirit::lex::lexer<lexer_type> { Lexer() { identifier = "[A-Za-z_][A-Za-z0-9_]*"; numLiteral = "([0-9]+)|(0x[0-9a-fA-F]+)"; this->self.add ("int")...

Boost Spirit Symbol throws access violation

boost,boost-spirit,boost-spirit-qi
Hello I am new to Boost Spirit, and I am having trouble with the qi::symbol object. #include <iostream> #include <vector> #define BOOST_SPIRIT_DEBUG #define BOOST_SPIRIT_DEBUG_OUT std::cerr #include <boost/config/warning_disable.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include...

boost::spirit::qi difference parser behavior

c++,parsing,boost,boost-spirit,boost-spirit-qi
I'm trying to understand the behavior of Qi's Difference Parsers. With something like this: ruleA = ruleAa | ruleAb | ruleAc ; ruleB = ruleA - ruleAc ; I was imagining that the parser would match ruleB iff the input matches ruleAa or ruleAb. In other words, ruleB would subtract...

Parsing a boost::variant with User Defined Datatype containing std::string using Spirit Qi

c++,boost,boost-spirit-qi
I'm trying to create a GPIB parser using Spirit.Qi. Sometimes the response can be either an error or a normal response. This seemed like a good use case for the alternative parser which yields a boost::variant; however, if one of the variant types contains a string the code fails to...

making a vector of shared pointers from Spirit Qi

c++,shared-ptr,boost-spirit,boost-spirit-qi
This is a followup question from a previous question. I can parse into vectors of strings from my grammar, but I cannot seem to parse into a vector of shared pointers to strings; i.e. std::vector<std::shared_ptr<std::string> >, and need a bit of help. My compiling header: #define BOOST_SPIRIT_USE_PHOENIX_V3 1 #include <boost/spirit/include/qi_core.hpp>...

Boost Spirit 2 - Symbol expansion and backtracking

c++,boost,boost-spirit,boost-spirit-qi
I am having some issues specifying and parsing a rather simple grammar. vertex = char+ edge = vertex " -> " vertex start = ((vertex | edge) eol)* input = "a\nb\na -> b\n" Spirit is doing the following: "a" -> vertex "\n" -> eol -> start "b" -> vertex "\n"...

Constraining the existing Boost.Spirit real_parser (with a policy)

c++,parsing,boost,boost-spirit,boost-spirit-qi
I want to parse a float, but not allow NaN values, so I generate a policy which inherits from the default policy and create a real_parser with it: // using boost::spirit::qi::{real_parser,real_policies, // phrase_parse,double_,char_}; template <typename T> struct no_nan_policy : real_policies<T> { template <typename I, typename A> static bool parse_nan(I&, I...

Boost Spirit : something like permutation, but not exactly

boost-spirit,boost-spirit-qi
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...

Specify a charset without intepreting ranges

c++,boost,boost-spirit-qi
I'm quite puzzled with parsing strings when I have to define in rule the minus and it is just a minus character and not a range of characters between two endpoints. For example, when you write a rule to percent encode a string of characters you normally would write *(bk::char_("a-zA-Z0-9-_.~")...