boost-spirit

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.

Recursive x3 parser with results passing around

流过昼夜 提交于 2019-12-08 02:23:47
问题 (1) Say we want to parse a simple recursive block surrounded by {} . { Some text. { { Some more text. } Some Text again. {} } } This recursive parser is quite simple. x3::rule<struct idBlock1> const ruleBlock1{"Block1"}; auto const ruleBlock1_def = x3::lit('{') >> *( ruleBlock1 | (x3::char_ - x3::lit('}')) ) >> x3::lit('}'); BOOST_SPIRIT_DEFINE(ruleBlock1) (2) Then the block becomes more complex. It could also be surrounded by [] . { Some text. [ { Some more text. } Some Text again. [] ] } We

X3, how to populate a more complex AST?

别来无恙 提交于 2019-12-08 02:20:05
问题 Trying to generate an AST like the employee example that has more than just the employee. In my current mindset, the RExpressions example isn't helping me. The example I have doesn't compile, but I went as far as I understood in adding teams, departments, and corporations to the employee example. My problem is in understanding how to add the different structs into a variant and add the variant to phrase_parse, if that's the idea. In this example, there can be several of the same lines

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

How can i implement const in Boost Spirit?

雨燕双飞 提交于 2019-12-08 02:03:35
问题 I am interested in Boost Spirit nowadays and trying to build something. Can we implement something like a const in C++ using Spirit? For instance, user will define an item like; constant var PROG_LANG="Java"; "constant var" seems weird, I accept but you got the idea. I searched the internet but can't found anything about it. 回答1: What the BigBoss said :) Only I'd do without the semantic actions - making it far less... verbose (See also Boost Spirit: "Semantic actions are evil"?): vdef = (

Parsing with Boost::Spirit (V2.4) into container

送分小仙女□ 提交于 2019-12-08 01:01:52
问题 I just started to dig into Boost::Spirit, latest version by now -- V2.4. The essense of my problem is following: I would like to parse strings like "1a2" or "3b4". So the rule I use is: (double_ >> lit('b') >> double_) | (double_ >> lit('a') >> double_); The attribute of the rule must be "vector <double>". And I'm reading it into the container. The complete code: #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix

Boost Spirit 2 - Symbol expansion and backtracking

六月ゝ 毕业季﹏ 提交于 2019-12-07 19:24:02
问题 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" -> eol -> start and "a" -> vertex terminate instead of identifying the edge in the end and parsing the entire input. That is, it could parse the entire input but it's not. Shouldn't it backtrack and attempt to parse using the alternate rule?