boost-spirit-qi

boost spirit V2 qi bug associated with optimization level

有些话、适合烂在心里 提交于 2019-11-27 05:30:12
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 bash -vex WARN="-W -Wall -Wextra" INCLUDE="-isystem /c/libs/boost-trunk" OPT="-O2" g++ -x c++ - -std=gnu+

Understanding Boost.spirit's string parser

假装没事ソ 提交于 2019-11-27 05:28:39
#include <iostream> #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; int main () { using qi::string; std::string input("a"); std::string::iterator strbegin = input.begin(); std::string p; bool ok = qi::phrase_parse(strbegin, input.end(), ((string("a") >> string("a")) | string("a")), qi::space, p); if (ok && strbegin == input.end()) { std::cout << p << std::endl; std::cout << p.size() << std::endl; } else { std::cout << "fail" << std::endl; std::cout << std::string(strbegin, input.end()) << std::endl; } } This program outputs aa . How is it possible? Input string is a .

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

最后都变了- 提交于 2019-11-27 05:21:26
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 intermediate attributes while doing so. These benefits get payed for with runtime because lookahead parsing is

Spirit unable to assign attribute to single-element struct (or fusion sequence)

心不动则不痛 提交于 2019-11-26 23:36:17
问题 My goal is to have my qi::grammar return an attribute. I'm having significant difficulty doing this with a spirit::lexer though. I'd expect that with the given grammar below, if I called it with spirit::qi::parse(begin, end, grammar, output); , that the struct ident output would have the contents of the parsed lexeme. The error seems to mostly flow out of this line: start %= lexer.identifier; System Notes Boost 1.47.0 Mac OS X 10.7.2 clang++ or g++ (errors shown below are from clang++)

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

风流意气都作罢 提交于 2019-11-26 23:16:32
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? qi::hold is one way about it, as correctly mentioned by @Andrzej I think I have a few observations that might help, as well as a

How can I use polymorphic attributes with boost::spirit::qi parsers?

两盒软妹~` 提交于 2019-11-26 22:55:34
I would like my boost::spirit-based parser to be able to parse a file, convert the parsed rules into different types, and emit a vector containing all of the matches it found. All of the types that are emitted as attributes should be inherited from a base type, for example: #include <boost/spirit/include/qi.hpp> #include <boost/fusion/adapt_struct.hpp> #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> struct CommandBase { virtual void commandAction() { std::cout << "This is a base command. You should never see this!" << std::endl; //Boost::spirit seems to get mad if I make this

boost::spirit::qi keywords and identifiers

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:53:50
问题 I've seen a few posts related to the nuances of keyword/identifier use in qi grammars, but I can't quite make sense of how the approach demonstrated in the boost examples is supposed to work... Keywords declaration: qi::symbols<char> keywords; Example keyword set: keywords.add ("foo") ("bar") ; Identifier rule declaration: qi::rule<std::string::const_iterator, std::string(), ascii::space_type> identifier; Here's how the identifier rule is defined in the qi calc and compiler examples:

boost::spirit access position iterator from semantic actions

一曲冷凌霜 提交于 2019-11-26 21:17:02
问题 Lets say I have code like this (line numbers for reference): 1: 2:function FuncName_1 { 3: var Var_1 = 3; 4: var Var_2 = 4; 5: ... I want to write a grammar that parses such text, puts all indentifiers (function and variable names) infos into a tree (utree?). Each node should preserve: line_num, column_num and symbol value. example: root: FuncName_1 (line:2,col:10) children[0]: Var_1 (line:3, col:8) children[1]: Var_1 (line:4, col:9) I want to put it into the tree because I plan to traverse

Parse quoted strings with boost::spirit

时光总嘲笑我的痴心妄想 提交于 2019-11-26 20:58:52
I would like to parse a sentence where some strings may be unquoted, 'quoted' or "quoted". The code below almost works - but it fails to match closing quotes. I'm guessing this is because of the qq reference. A modification is commented in the code, the modification reults in "quoted' or 'quoted" also parsing and helps show the original problem is with the closing quote. The code also describes the exact grammar. To be completely clear: unquoted strings parse. A quoted string like 'hello' will parse the open quote ' , all the characters hello , but then fail to parse the final quote ' . I made

Spirit Qi attribute propagation issue with single-member struct

一笑奈何 提交于 2019-11-26 18:59:45
I have an compilation issue with Spirit Qi where it complains that value_type is not a member of identifier . For some reason, Qi's attribute system considers identifier to be a container type, and tries to enumerate it's value type. This is a similar issue as in this question , however, I believe the cause is the single member struct and may be related to this bug . #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> using namespace boost::spirit::qi; struct identifier { std::wstring name; }; struct problem { identifier _1; identifier _2;