boost-spirit

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

Generating Spirit parser expressions from a variadic list of alternative parser expressions

这一生的挚爱 提交于 2019-11-27 05:21:13
I'm looking for the simplest way to implement variadic function which takes list of boost::spirit::qi rules and expands the list into expression of format: rule1 | rule2 | rule3 |.... Let's assume that the rules synthesize no attribute. Your kind help is very much appreciated. #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <string> #include <iostream> #include <boost/spirit/include/phoenix_operator.hpp> namespace qi = boost::spirit::qi; namespace ph = boost::phoenix; namespace ascii = boost::spirit::ascii; using boost::spirit::qi::phrase_parse;

Boost Spirit X3 cannot compile repeat directive with variable factor

梦想的初衷 提交于 2019-11-27 05:06:59
I am trying to use the Boost Spirit X3 directive repeat with a repetition factor that is variable. The basic idea is that of a header + payload, where the header specifies the size of the payload. A simple example “3 1 2 3” is interpreted as header = 3, data= {1, 2, 3} (3 integers). I could only find examples from the spirit qi documentation. It uses boost phoenix reference to wrap the variable factor: http://www.boost.org/doc/libs/1_50_0/libs/spirit/doc/html/spirit/qi/reference/directive/repeat.html std::string str; int n; test_parser_attr("\x0bHello World", char_[phx::ref(n) = _1] >> repeat

How to provider user with autocomplete suggestions for given boost::spirit grammar?

我的未来我决定 提交于 2019-11-27 04:56:45
I am using Boost::Spirit to build simple "data-filter" language in my C++ GUI application for non-technical users. Language is very similiar to plain English and parse-able into AST. I am requested to make the process as user-friendly as possible, so I wish to provide CLang-like error messages ("Unrecognized 'tokken', did you meant 'token'?") and autocompletion. The question in place is how to use Boost::Spirit grammar to generate possible token list for both goals (I will use simple string distance algorithm to satisfy first requirement)? My ideas so far: Add position and length in source

undefined behaviour somewhere in boost::spirit::qi::phrase_parse

淺唱寂寞╮ 提交于 2019-11-27 02:26:48
I am learning to use boost::spirit library. I took this example http://www.boost.org/doc/libs/1_56_0/libs/spirit/example/qi/num_list1.cpp and compiled it on my computer - it works fine. However if I modify it a little - if I initialize the parser itself auto parser = qi::double_ >> *(',' >> qi::double_); somewhere as global variable and pass it to phrase_parse, everything goes crazy. Here is the complete modified code (only 1 line is modified and 1 added) - http://pastebin.com/5rWS3pMt If I run the original code and pass "3.14, 3.15" to stdin, it says Parsing succeeded, but with my modified

Why does nvcc fails to compile a CUDA file with boost::spirit?

怎甘沉沦 提交于 2019-11-27 02:24:49
I'm trying to integrate CUDA to an existing aplication wich uses boost::spirit. Isolating the problem, I've found out that the following code does not copile with nvcc: main.cu : #include <boost/spirit/include/qi.hpp> int main(){ exit(0); } Compiling with nvcc -o cudaTest main.cu I get a lot of errors that can be seen here . But if I change the filename to main.cpp , and compile again using nvcc , it works. What is happening here and how can I fix it? nvcc sometimes has trouble compiling complex template code such as is found in Boost, even if the code is only used in __host__ functions. When

Custom Skip Parser with Boost::Spirit

别等时光非礼了梦想. 提交于 2019-11-27 01:21:30
问题 The standard ascii::space_type skipper does of course not skip my comments. The docs mention you can make your own skip parser but there is no example of actually how to do it. I'd just need an example code or anything, I've been googling for 2 hours now. Please don't point me to the examples, the few links that work are hopelessly outdated, dealing with Spirit 1.6. 回答1: After some experimentation, I have found a way to specify a custom skipper and will outline it here: template<typename

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 parser: index of parsed element

我与影子孤独终老i 提交于 2019-11-26 23:23:37
问题 Is it possible (using Boost::Spirit::QI) to parse numbers from a comma separated string so that I get the index of each parsed number? Suppose I have a string "23,123,65,1" and I want to insert each of these numbers into a matrix at given locations (0, 1, 2, 3). One way to do it would to parse the numbers into an std::vector and then copy them to the matrix row, but it isn't particularly fast. Currently I'm using the vector variant: Matrix data(10, 4); int row = 0; int col = 0; std::string

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