boost-spirit-qi

Is it possible to reuse a Spirit Qi grammar as a Spirit Karma grammar?

做~自己de王妃 提交于 2019-12-01 07:48:49
问题 I have a Qi grammar definition that I use to parse an input. Later I have a Karma generator to output in a way that should be similar to the input. Is this possible at all? It seem that a parser grammar can be transformed into a generator grammar automatically (??). #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/karma.hpp> #include <iostream> int main(){ //test input std::string s = "Xx 1.233 pseudo"; //input variables std:

How to incrementally parse (and act on) a large file with Boost.Spirit.Qi?

十年热恋 提交于 2019-12-01 06:48:42
I've created a Qi parser for a custom text file format. There are tens of thousands of entries to process and each entry usually has between 1-10 subentries. I put a trimmed down working example of my parser here . #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/include/support_istream

How to verify algebraic statements using boost::spirit?

无人久伴 提交于 2019-12-01 06:42:55
I'm trying to extend the calculator example so that instead of parsing and evaluating an algebraic expression, the parser will determine if an algebraic statement is true or not. By this I mean statements like 1 + 5 * 5 - 10 = 19 - 3 (desired parser result is true ) and 3 - 1 = 9 (desired parser result is false ). I've got to admit I'm new to boost::spirit and it's all kind of overwhelming at the moment. However, I do feel I understand the calculator example good enough to at least make some headway. Using the provided example as a starting point, the grammar looks like this: calculator() :

How to incrementally parse (and act on) a large file with Boost.Spirit.Qi?

无人久伴 提交于 2019-12-01 05:15:28
问题 I've created a Qi parser for a custom text file format. There are tens of thousands of entries to process and each entry usually has between 1-10 subentries. I put a trimmed down working example of my parser here. #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp>

boost::spirit::qi Expectation Parser and parser grouping unexpected behaviour

点点圈 提交于 2019-11-30 17:56:54
问题 I'm hoping someone can shine a light through my ignorance of using the > and >> operators in spirit parsing. I have a working grammar, where the top-level rule looks like test = identifier >> operationRule >> repeat(1,3)[any_string] >> arrow >> any_string >> conditionRule; It relies on attributes to automatically allocated parsed values to a fusion-adapted struct (ie a boost tuple). However, I know that once we match the operationRule, we must continue or fail (ie we don't want to allow

How to parse entries followed by semicolon or newline (boost::spirit)?

那年仲夏 提交于 2019-11-30 15:19:45
In Boost::Spirit, how can I parse entries that are followed by either a semicolon or by a newline with optional semicolon? Example input, where each entry is an int and a double: 12 1.4; 63 13.2 2423 56.4 ; 5 8.1 Here is example code that just parses entries followed by whitespace: #include <iostream> #include <boost/foreach.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/support_istream_iterator.hpp> #include <boost/fusion/include/std_pair.hpp> namespace qi = boost::spirit::qi; typedef std::pair<int, double> Entry; template <typename Iterator, typename Skipper>

Getting boost::spirit::qi to use stl containers

依然范特西╮ 提交于 2019-11-30 06:40:02
问题 I'm trying to parse something with boost.spirit's qi library, and I'm running into an issue. According to the spirit docs, a >> b should produce something with the type tuple<A, B> . But this is a boost::tuple (aka fusion vector), and not a std::tuple (which I want). Is there any easy way to make this conversion between boost::tuple => std::tuple ? The same documentation page says that *a should produce something with the type vector<A> . This seems to be producing a std::vector<A> (or some

How to parse entries followed by semicolon or newline (boost::spirit)?

倖福魔咒の 提交于 2019-11-29 21:35:26
问题 In Boost::Spirit, how can I parse entries that are followed by either a semicolon or by a newline with optional semicolon? Example input, where each entry is an int and a double: 12 1.4; 63 13.2 2423 56.4 ; 5 8.1 Here is example code that just parses entries followed by whitespace: #include <iostream> #include <boost/foreach.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/support_istream_iterator.hpp> #include <boost/fusion/include/std_pair.hpp> namespace qi = boost

Using boost::spirit::qi to parse numbers with separators

你说的曾经没有我的故事 提交于 2019-11-29 15:48:21
I am attempting to use boost::spirit::qi to do some parsing. It's actually going quite well, and I successfully have managed to parse numbers in various bases based on a suffix. Examples: 123, c12h, 777o, 110101b. I then wanted to add the ability to allow a completely ignored separator character, to allow values like 123_456 or 1101_0011b to parse. I tried using the skip parser, but I highly suspect that I completely misunderstood how it was to be used. It compiles just fine, but my attempt to make it ignore the underscore does absolutely nothing at all. Any suggestions on how to make this do

Boost::spirit::qi defining a calculator for nullaries

耗尽温柔 提交于 2019-11-29 15:14:19
I'm trying to write a parser for math expressions where named variables are nullaries in boost::spirit (version 1_51_0), to which I'm completely new. I define typedef boost::function<double()> Value and my rules will be declared like so: qi::rule<Iterator, Value()> expression, term, others, ...; I define binary operators on nullaries with this macro #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \ Value x_, y_; \ }; and have ADD , SUB , etc. From the examples I've seen, I'd expect the rules to be