FAQ Database Discussion Community


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"...

Read empty values with boost::spirit

c++,boost,boost-spirit
I want to read a CSV into a struct : struct data { std::string a; std::string b; std::string c; } However, I want to read even empty string to ensure all values are in their proper place. I adapted the struct to a boost::fusion, so the following works : //...

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...

Why does'n boost::spirit match foo123 with (+alpha | +alnum) grammar?

c++,boost,boost-spirit
I have a more complex boost::spirit grammar that doesn't match like I expected. I was able to break it down to this minimal example: http://ideone.com/oPu2e7 (doesn't compile there, but compiles with VS2010) Basically this is my grammar: my_grammar() : my_grammar::base_type(start) { start %= (+alpha | +alnum) ; } qi::rule<Iterator, std::string(),...

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...

Parse into a vector> with boost::spirit

c++,boost,stdvector,boost-spirit
My intent is to parse a comma separated list of values into a nested vector. This list is two-dimensional. The basic question is: is it possible to parse into a vector of vector with boost::spirit? Something like the table under "Traction": ' ' RPM 0,5000,10000,15000,20000,25000 ' ' Temp ' -40.,0.,20.,40....

Strange static_cast compilation error while compile boost spirit parser

c++,parsing,boost,boost-spirit
To parse expressions like follow: "asd {img} {ref I}sdkflsdlk {img} wmrwerml" I have code like this: struct CMyTag { std::string tagName; std::string tagData; }; BOOST_FUSION_ADAPT_STRUCT(::CMyTag, (std::string, tagName) (std::string, tagData)); struct fillMyTag { template <typename A, typename B = boost::spirit::unused_type, typename C = boost::spirit::unused_type, typename D = boost::spirit::unused_type> struct result {...

Aditional symbols in spirit parser output

c++,parsing,boost,boost-spirit
We try parse simple number/text(in text present numbers, so we must split input sequence, into 2 elements type(TEXT and NUMBER) vector) gramar where number can be in follow format: +10.90 10.90 10 +10 -10 So we write gramar: struct CMyTag { TagTypes tagName; std::string tagData; std::vector<CMyTag> tagChild; }; BOOST_FUSION_ADAPT_STRUCT(::CMyTag, (TagTypes,...

Parsing nested key value pairs in Boost Spirit

c++,boost,boost-spirit
I am having trouble writing what I think should be a simple parser using Boost::Spirit. (I'm using Spirit instead of just using string functions as this is partly a learning exercise for me). Data The data to parse takes the form of key value pairs, where a value can itself...

Is it possible to use mpl::map to initialize symbol parser?

c++,boost-spirit,boost-mpl
If I have a mpl::map, how can I generate a corresponding boost::spirit::symbol parser? Example: using blocks = mpl::map< mpl::pair<mpl::string<'p'>, do_para>, mpl::pair<mpl::string<'ul'>, do_ul>, mpl::pair<mpl::string<'ol'>, do_ol> >; qi::symbols<const char *, T> block_parser(?????); Thanks for the help with the minimal code question!...

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...

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...

Defining a symbol which may be part of a literal function in boost spirit

c++,boost,boost-spirit,boost-phoenix
I am trying to read a mathematical function which depends on the symbol t with boost::spirit. In the example below, I'm trying evaluate the function "tan(t)" in t=1.2. Instead of having Exit: 1, value = 2.5721 I get Exit: 1, value = 1.2 I understand that when I try 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...

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...

Declaration of cross-recursive rules

c++,recursion,static,boost-spirit,forward-declaration
I declared rules of my grammar as static const. That worked fine till I tried to use cross-recursive rules (rule1 is defined using rule2 which is defined using rule1). The source code still can be built, but segfaults on parsing source containing such cross-recursive case. Here's a simplified code of...

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 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 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...

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...

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...

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...

Function or functor calling using sprit boost parser library rule to save values in vector c++

c++,boost,boost-spirit
I want to parse this line and storing all hex values in functor <005F> <0061> [<00660066> <00660069> <00660066006C>] this values in txt file and m reading this fill line by line like 005F 0061 00660066 00660069 00660066006C all values should be in vector but its not working the spirit rule...

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>...

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) {...

Parse html escape sequence with boost spirit

c++,parsing,boost,boost-spirit
I try to parse text with html escape sequences and want to chnage this esaceps with they utf8 equvivalents: &nbsp; - 0xC2A0 utf8 representation &shy; - 0xC2AD utf8 representation And have gramar to solve this template <typename Iterator> struct HTMLEscape_grammar : qi::grammar<Iterator, std::string()> { HTMLEscape_grammar() : HTMLEscape_grammar::base_type(text) { htmlescapes.add("&nbsp;", 0xC2AD);...

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 parse data into c++ Struct with boost spirit if I have an “or” ('|') in my grammer

c++,struct,boost-spirit
I have the following C++ Struct: struct Dimension { enum Type { PARENT, CHILD, PIXEL }; Type mWidth_type = Type::PIXEL; int mWidth = 0; Type mHeight_type = Type::PIXEL; int mHeight = 0; }; My grammar looks like this: +(char_ - "{") >> "{" >> -(lit("width") >> ":" >> (int_ |...

parsing fails when using istream iterator

c++,parsing,stl,iterator,boost-spirit
I'm using boost::spirit to parse csv input (please don't suggest an alternative, this is just testing). When I read the contents of stdin to a string and iterate over that, the parsing succeeds; however, when the contents of std::cin are read directly (through a wrapper that I wrote myself because...

Boost spirit library not working properly while parsing roman numerals when using wide strings

c++,unicode,boost-spirit
struct add_1000 { add_1000(unsigned& r_) : r(r_) {} void operator()(wchar_t) const { r += 1000; } unsigned& r; }; struct add_roman { add_roman(unsigned& r_) : r(r_) {} void operator()(unsigned n) const { r += n; } unsigned& r; }; /////////////////////////////////////////////////////////////////////////////// // // roman (numerals) grammar // /////////////////////////////////////////////////////////////////////////////// struct roman :...

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 Karma equivalent to Qi matches

boost,boost-spirit,boost-spirit-karma
What is the equivalent to boost::spirit::qi::matches in boost::spirit::karma? For example I want to generate a literal "array" only if a boolean flag is set true.

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...