boost-spirit-qi

parsing into several vector members

那年仲夏 提交于 2019-11-26 18:24:52
问题 I want to recursively parse a string and store the results in one struct. I've written a parser that can handle one iteration. The input is formatted as follows: v 1.5 2.0 2.5 v 3.0 3.5 4.0 f 1 2 3 f 4 5 6 v 4.5 5.0 5.5 v 6.0 6.5 7.0 f 7 8 9 f 10 11 12 The problem is that it only parses the first 4 lines, it stops at the third encountered 'v'. The complete code is given below. How do I modify this code so it also parses the rest of the input into the same struct? I've tried modifying the

How to parse csv using boost::spirit

拥有回忆 提交于 2019-11-26 17:50:39
问题 I have this csv line std::string s = R"(1997,Ford,E350,"ac, abs, moon","some "rusty" parts",3000.00)"; I can parse it using boost::tokenizer : typedef boost::tokenizer< boost::escaped_list_separator<char> , std::string::const_iterator, std::string> Tokenizer; boost::escaped_list_separator<char> seps('\\', ',', '\"'); Tokenizer tok(s, seps); for (auto i : tok) { std::cout << i << std::endl; } It gets it right except token "rusty" should have double quotes which are getting stripped. Here is my

boost spirit semantic action parameters

只愿长相守 提交于 2019-11-26 17:15:46
in this article about boost spirit semantic actions it is mentioned that There are actually 2 more arguments being passed: the parser context and a reference to a boolean ‘hit’ parameter. The parser context is meaningful only if the semantic action is attached somewhere to the right hand side of a rule. We will see more information about this shortly. The boolean value can be set to false inside the semantic action invalidates the match in retrospective, making the parser fail. All fine, but i've been trying to find an example passing a function object as semantic action that uses the other

Parse int or double using boost spirit (longest_d)

爷,独闯天下 提交于 2019-11-26 17:03:36
问题 I'm looking for a way to parse a string as an int or a double, the parser should try both alternatives and choose the one matching the longest portion of the input stream. There is a deprecated directive (longest_d) that does exactly what I'm looking for: number = longest_d[ integer | real ]; ...since it's deprecated, there are any other alternatives? In case it's necessary to implement a semantic action to achieve the desired behavior, does anyone have a suggestion? 回答1: Firstly, do switch

Assigning parsers to auto variables

人盡茶涼 提交于 2019-11-26 15:28:45
Are spirit parsers not meant to be used with auto ? A simple parser works fine when passed to qi::parse() inline, but crashes with segfault if passed via an auto variable: #include <cstdio> #include <string> #include <boost/spirit/include/qi.hpp> using namespace std; namespace qi = boost::spirit::qi; int main() { string line = "[z]"; auto bracketed_z = '[' >> +qi::char_('z') >> ']'; auto p = line.cbegin(); printf("%d", qi::parse(p, line.cend(), '[' >> +qi::char_('z') >> ']')); // Works p = line.cbegin(); printf("%d", qi::parse(p, line.cend(), bracketed_z)); // Crashes } Reproes with g++-4.8

How to parse reserved words correctly in boost spirit

☆樱花仙子☆ 提交于 2019-11-26 14:52:38
问题 I'm trying to parse a sequence of the syntax: < direction > < type > < name >. For example: in float foo where the direction can be either in , out , or in_out . I've succeeded in parsing correct text by using a qi::symbols class to convert the direction keywords to an enum. However, the problem shows when I don't have correct text. Take the example: int foo The symbol table parser will except the 'in' part of the 'int' type and so the results will be: direction: in type: t name: foo And the

Understanding the List Operator (%) in Boost.Spirit

我怕爱的太早我们不能终老 提交于 2019-11-26 14:38:12
问题 Can you help me understand the difference between the a % b parser and its expanded a >> *(b >> a) form in Boost.Spirit? Even though the reference manual states that they are equivalent, The list operator, a % b , is a binary operator that matches a list of one or more repetitions of a separated by occurrences of b . This is equivalent to a >> *(b >> a) . the following program produces different results depending on which is used: #include <iostream> #include <string> #include <vector>

Spirit-Qi: How can I write a nonterminal parser?

守給你的承諾、 提交于 2019-11-26 12:47:29
问题 I want to write a parser (as a qi extension) which can be used via my_parser(p1, p2, ...) where p1, p2, ... are qi parser expressions. Actually, I want to implement a best_match parser which works like qi alternative, but selects not the first matching rule but the rule which \'explains\' most of the input. Given two rules simple_id = +(qi::alpha) and complex_id = simple_id >> *(qi::string(\"::\") > simple_id) it would select complex_id on the input willy::anton . And it would not produce

boost spirit V2 qi bug associated with optimization level

狂风中的少年 提交于 2019-11-26 11:37:19
问题 I develop my code in my spare time. Preferably in debug mode. Recently, when I tried to build release version, then I got the error (runtime, output: 1\\n2\\n then failure). I located the piece of code (below), which contains the error, and I found, that the error only occurs, when optimization level is -Os, -Ofast, -O2, -O3 but not -O, -O0, -O1, -Og . In release mode I am constrained in debug abilities. What is the cause of the error? What is the method to find such errors? #!/usr/bin/env

boost::spirit::qi duplicate parsing on the output

和自甴很熟 提交于 2019-11-26 08:37:26
问题 I have this very simple parser using Boost::Spirit: rule<std::string::iterator, std::string()> zeroTo255 = (string(\"25\") >> char_(\'0\', \'5\')) | (char_(\'2\') >> char_(\'0\', \'4\') >> digit) | (char_(\'1\') >> repeat[2](digit)) | (char_(\'1\', \'9\') >> digit) | digit; When I try to parse std::string o{\"1\"}; std::string s; parse(o.begin(), o.end(), zeroTo255, s); std::cout << o << \": \" << s << std::endl; I have as output 1: 111 I\'m obviously doing something wrong, but what? 回答1: qi: