boost-spirit-qi

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?

Optimizing a boost::spirit::qi parser

♀尐吖头ヾ 提交于 2019-12-07 18:49:22
问题 I have a parser that basically prints out the actions of a stack machine with my operator precedence given some expression. My goal is to optimize for speed as much as possible. I have read an article concerning qi optimizations that provides this example code. I understand the gist of the optimizations described in the main article, however I am unclear how to integrate this into my code. Here is a following working example of my parser. I have already tried to optimize it somewhat by using

Deeply-recursive qi grammars (parsers) with synthesized and inherited attributes

感情迁移 提交于 2019-12-07 12:22:47
问题 I'm using spirit::qi grammars that construct and return nontrivial objects as their synthesized attributes. The problem is that I want the grammars to recursively depend on each other. It is straightforward to use recursive rules , but I want recursive grammars . Here's some example code. Notice the comments that say CIRCULAR REFERENCE. Obviously this cannot compile if I uncomment those lines, because the FooGrammar and BarGrammar objects include each other. I can think of two ways to achieve

Parsing a number of named sets of other named sets

你说的曾经没有我的故事 提交于 2019-12-07 03:17:46
问题 So I want to write a... well... not-so-simple parser with boost::spirit::qi. I know the bare basics of boost spirit, having gotten acquainted with it for the first time in the past couple of hours. Basically I need to parse this: # comment # other comment set "Myset A" { figure "AF 1" { i 0 0 0 i 1 2 5 i 1 1 1 f 3.1 45.11 5.3 i 3 1 5 f 1.1 2.33 5.166 } figure "AF 2" { i 25 5 1 i 3 1 3 } } # comment set "Myset B" { figure "BF 1" { f 23.1 4.3 5.11 } } set "Myset C" { include "Myset A" #

boost::optional to bool, inside boost::spirit::qi grammar

断了今生、忘了曾经 提交于 2019-12-07 02:30:26
问题 In my boost::spirit grammar I have the following snippet; implicit_method_declaration = (-(qi::token(ABSTRACT)) >> ...) The type of -(qi::token(ABSTRACT) is boost::optional<boost::iterator_range<std::string::iterator>> however I'm only using this construct to check if the abstract keyword, is actually present, that is, I'd rather have -(qi::token(ABSTRACT) have the type bool with the value boost::optional<...> operator bool() const . How would I go about achieving this? 回答1: I think you're

How to use boost::tuple as attribute in a boost::spirit rule?

人走茶凉 提交于 2019-12-07 02:11:46
问题 I have the following rule in boost::spirit : typedef boost::tuple<int, int> Entry; qi::rule<Iterator, Entry(), Skipper> entry; entry = qi::int_ >> qi::int_; But the second int is not written into the tuple. Is there a way to make it work without having to use boost::fusion::tuple ? It works if I use std::pair , so why can't I use boost::tuple ? Here is a full compiling example: #include <iostream> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/tuple.hpp> #include <boost

Boost Spirit char parser

风格不统一 提交于 2019-12-06 15:40:40
Here is a code sample: // file main.cpp #include <iostream> #include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/spirit/include/qi.hpp> int main() { std::string s( "1 A" ); boost::tuple<double, char> p; complex_matrix_parser::iterator b = s.begin(); complex_matrix_parser::iterator e = s.end(); qi::phrase_parse( b, e, ( qi::double_ >> qi::char_('A') ), qi::space, qi::skip_flag::postskip, p ); std::cerr << "==== " << p << std::endl; return 0; } This should print ==== (1 A) right? But it prints ==== (1 ) , so it skips the 'A' character. What am I doing wrong here?

OBJ Parser with Boost Spirit - Ignoring comments

╄→гoц情女王★ 提交于 2019-12-06 15:24:25
I'm trying to write a basic OBJ file loader using the Boost Spirit library. Although I got it working using the standard std::ifstreams, I'm wondering if it's possible to do a phrase_parse on the entire file using a memory mapped file, since it seems to provide the best performance as posted here . I have the following code, which seems to work well, but it breaks when there is a comment in the file. So, my question is how do you ignore a comment that starts with a '#' in the OBJ file using Spririt? struct vertex { double x, y, z; }; BOOST_FUSION_ADAPT_STRUCT( vertex, (double, x) (double, y)

Discarding parsed result after semantic action

丶灬走出姿态 提交于 2019-12-06 14:53:40
In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input format and I should be able to prereserve the space in the vector. For example if the input string is "3

Splitting string using boost spirit

柔情痞子 提交于 2019-12-06 13:41:54
问题 Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile template <typename Iterator> struct ValueList : bsq::grammar<Iterator, std::vector<std::string>()> { ValueList(const std::string& sep, bool isCaseSensitive) : ValueList::base_type(query) { if(isCaseSensitive) { query = value >> *(sep >> value); value = *(bsq::char_ - sep); } else { auto separator = bsq::no_case[sep]; query = value >> *