boost-spirit-qi

How to use boost spirit list operator with mandatory minimum amount of elements?

旧巷老猫 提交于 2019-12-08 08:09:53
问题 I would like to parse dot language (http://www.graphviz.org/content/dot-language). It's a graph definition language that defines nodes and connections between them. A typical statement looks like node1->node2->node3; . It would be nice to use a boost::spirit list operator % to make a list of nodes. A naive approach would be: edge_stmt %= ( node_or_subgraph(_r1) % (qi::eps(_r1) >> tok.diredgeop | tok.undiredgeop) ) >> -attr_list; _r1 indicates if this is directed or undirected graph, diredgeop

Discarding parsed result after semantic action

只谈情不闲聊 提交于 2019-12-08 08:06:05
问题 In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input

Error when compiling a grammar with debug activated

泄露秘密 提交于 2019-12-08 07:44:33
问题 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 type; std::wstring unit; std::wstring cardinality; std::wstring value; }; } // namespace

128 bit string to array using boost::spirit::*

佐手、 提交于 2019-12-08 05:30:25
问题 I am currently starting with boost::spirit::*. I try to parse a 128 bit string into a simple c array with corresponding size. I created a short test which does the job: boost::spirit::qi::int_parser< boost::uint8_t, 16, 2, 2 > uint8_hex; std::string src( "00112233445566778899aabbccddeeff" ); boost::uint8_t dst[ 16 ]; bool r; for( std::size_t i = 0; i < 16; ++i ) { r = boost::spirit::qi::parse( src.begin( ) + 2 * i, src.begin( ) + 2 * i + 2, uint8_hex, dst[ i ] ); } I have the feeling that

Parsing imperial values using boost spirit (qi)

不羁的心 提交于 2019-12-08 05:27:16
问题 I'm a spirit beginner I'd like to parse an imperial string value into a struct using spirit. The input should accept following syntaxes: 5'3"1/2 5'1/2 3"1/2 the struct imp_constant looks like this, please note stream operator below, I'll print results as this operator does: struct imp_constant { explicit imp_constant(unsigned int feet=0 ,unsigned int inch=0 ,unsigned int fracn=0 ,unsigned int fracd=1) :feet_(feet),inches_(inch),fracn_(fracn),fracd_(fracd){} unsigned int feet_,inches_,fracn_

Learning Boost.Spirit: parsing INI

泪湿孤枕 提交于 2019-12-08 04:41:10
问题 I started to learn Boost.Spirit and finish reading Qi - Writing Parsers section. When reading, everything is easy and understandable. But when I try to do something, there are a lot of errors, because there are too many includes and namespaces and I need to know when to include/use them. As the practice, I want to write simple INI parser. Here is the code (includes are from one of examples inside Spirit lib as almost everything else): #include <boost/config/warning_disable.hpp> #include

Resolve ambiguous boost::spirit::qi grammar with lookahead

我们两清 提交于 2019-12-08 02:43:58
问题 I want to a list of name-value pairs. Each list is terminated by a '.' and EOL. Each name-value pair is separated by a ':'. Each pair is separated by a ';' in the list. E.g. NAME1: VALUE1; NAME2: VALUE2; NAME3: VALUE3.<EOL> The problem I have is that the values contain '.' and the last value always consumes the '.' at the EOL. Can I use some sort of lookahead to ensure the last '.' before the EOL is treated differently? 回答1: I have created a sample, that presumably looks like what you have.

boost::spirit::qi::grammar and variadic templates

半腔热情 提交于 2019-12-08 02:32:12
问题 I'm facing with an issue in defining a grammar with variadic templates. I started by defining some simple grammars contained into some struct (e.g. Latitude, Longitude) as follows: #include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/variant.hpp> #include <iostream> #include <string> using namespace boost::spirit; template <class Attribute> using command_rule = qi::rule<std::string::iterator, Attribute, ascii::space_type>; template <class

Constructing a qi::rule with a function attribute

非 Y 不嫁゛ 提交于 2019-12-08 02:09:05
问题 I'm trying to create a rule that returns a function<char(char const *)> constructed by currying a Phoenix expression. E.g., start = int_[_val = xxx]; rule<Iterator, function<char(char const *)> start; What should xxx be so that parsing the string "5" should give me a function that gives me the fifth character of its input? I've tried things like lambda(_a = arg1)[arg1[_a]](_1) might work, but I've not been able to hit on the magic formula. In other words, I'd like the attribute to curry arg2

OBJ Parser with Boost Spirit - Ignoring comments

半世苍凉 提交于 2019-12-08 01:03:46
问题 I'm trying to write a basic OBJ file loader using the Boost Spirit library. Although I got it working using the standard std::ifstreams, I'm wondering if it's possible to do a phrase_parse on the entire file using a memory mapped file, since it seems to provide the best performance as posted here. I have the following code, which seems to work well, but it breaks when there is a comment in the file. So, my question is how do you ignore a comment that starts with a '#' in the OBJ file using