boost-spirit

Troubles with boost::spirit::lex & whitespace

。_饼干妹妹 提交于 2019-11-26 17:16:22
问题 I try learning to use boost::spirit. To do that, I wanted to create some simple lexer, combine them and then start parsing using spirit. I tried modifying the example, but it doesn't run as expected (the result r isn't true). Here's the lexer: #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct lexer_identifier : lex::lexer<Lexer> { lexer_identifier() : identifier("[a-zA-Z_][a-zA-Z0-9_]*") , white_space("[ \\t\\n]+") { using

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

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

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

自作多情 提交于 2019-11-26 12:33:58
问题 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? 回答1: nvcc sometimes has trouble

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

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

时光毁灭记忆、已成空白 提交于 2019-11-26 11:32:32
问题 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

Boost Spirit X3 cannot compile repeat directive with variable factor

人走茶凉 提交于 2019-11-26 11:27:36
问题 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