boost-spirit-qi

Boost Spirit 2.4.2: Cannot extract a string

痴心易碎 提交于 2019-12-04 14:25:51
问题 Following the resolved question Boost Spirit: Error C2664, Cannot convert 'const boost::phoenix::actor<Eval>' to 'char' , I have another question: Why using the code below for js_key and js_string, I cannot capture print the strings in the format "str" or 'str'. Those always return blank! For example: Input: {"a":"aa", b:'c'} Actual output: { str: str: str: b str: Successfully parsed the input as JSON! Expected output: { str: a str: aa str: b str: c Successfully parsed the input as JSON!

Using boost::spirit, how do I require part of a record to be on its own line?

别说谁变了你拦得住时间么 提交于 2019-12-04 11:57:53
问题 I have a record parser that throws one of several exceptions to indicate which rule failed. Front matter: #include <iostream> #include <sstream> #include <stdexcept> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/classic_position_iterator.hpp> using namespace boost::spirit; using namespace boost::spirit::ascii; using namespace boost::spirit::qi; using namespace boost::spirit::qi::labels; using boost::phoenix:

Parentheses in template parameters in Boost Spirit rules and grammars

夙愿已清 提交于 2019-12-04 10:27:30
Looking at this example for implementing a Spirit parser, something caught me out when I was trying to write something similar. The attribute template parameter of the grammar ( std::map<std::string, std::string>() ) and the signature template parameter of the rules (e.g. qi::rule<Iterator, std::string()> key, value ) contain parentheses. namespace qi = boost::spirit::qi; template <typename Iterator> struct keys_and_values : qi::grammar<Iterator, std::map<std::string, std::string>()> // <- parentheses here { keys_and_values() : keys_and_values::base_type(query) { query = pair >> *((qi::lit(';'

Boost.Spirit.Qi: How to return attributes with Nabialek trick

两盒软妹~` 提交于 2019-12-04 09:17:09
问题 Following several tutorials (e.g. http://boost-spirit.com/home/articles/qi-example/nabialek-trick/) I want to use the Nabialek trick to have a dynamic parser. Parsing already works fine, but I don't get the attributes transported. Explanations like https://stackoverflow.com/a/9109972/2524462 suggest, that attributes should be possible but not arguments. This is just a small example parsing a string and a number into a struct. It is just for showcasing my problem; this method should be used in

Qi Symbols slow performance?

半腔热情 提交于 2019-12-04 08:07:37
I wanted to raise a subject that just sent me down a rabbit hole and brought up a question about qi::symbols. It all started while I was looking into the new beast library and read a tutorial example It starts with a function that guesses mime types from http path extensions. I started to look more closely and saw this: auto const ext = [&path] { auto const pos = path.rfind("."); if(pos == boost::beast::string_view::npos) return boost::beast::string_view{}; return path.substr(pos); }(); It took me a while to figure out it was a IIFE in C++ style, and was used to initialize ext while declaring

parsing into std::vector<string> with Spirit Qi, getting segfaults or assert failures

两盒软妹~` 提交于 2019-12-04 05:03:03
问题 I am using Spirit Qi as my parser, to parse mathematical expressions into an expression tree. I keep track of such things as the types of the symbols which are encountered as I parse, and which must be declared in the text I am parsing. Namely, I am parsing Bertini input files, a simple-ish example of which is here, a complicated example is here, and for completeness purposes, as below: %input: our first input file variable_group x,y; function f,g; f = x^2 - 1; g = y^2 - 4; END; The grammar I

Why does boost::spirit::qi::parse() not set this boost::variant's value?

喜你入骨 提交于 2019-12-03 16:00:35
When trying to parse text into a boost::variant, the variant's value does not get changed. The parsers by themselves appear to work fine, so my assumption is that I'm doing something wrong with the variant code. I'm using boost 1.46.1 and the following code compiles in Visual Studio 2008. 1st Update hkaiser noted that the rule and grammar template arguments must not be Variant but Variant() . This got a bit "further" as I now have a compilation error in boost_1_46_1\boost\variant\variant.hpp(1304) . The comment says: // NOTE TO USER : // Compile error here indicates that the given type is not

Is it possible to re-use boost::spirit::qi grammar in another grammar definition?

浪尽此生 提交于 2019-12-03 14:57:02
问题 Is it possible to reuse boost::spirit:qi grammar in another grammar (as a rule for example)? For example if I define a grammar to parse line of text into a structure holding street address. template< typename iter > struct address_grammar : qi::grammar< iter, address() > { ... qi::rule< iter, std::string() > street_name; qi::rule< iter, std::string() > street_number; qi::rule< iter, address() > address_; } I might want to reuse that grammar in two other grammars, for example one might be for

boost::spirit::qi and out-of-sequence variables

假装没事ソ 提交于 2019-12-03 14:52:16
I'm writing a lexigraphical analyser. It takes an English string, and converts it into a set of latitude/longitude co-ordinates. It's a bit like Google Earth. Anyway, I've written my symbol tables and grammar, and it's happily parsing formatted data. struct LatLongDegrees { std::string dirLat_; double degLat_; std::string dirLong_; double degLong_; } For example: {"North", 23.59, "East", -30.82} Here is my grammar: basic =(latitude >> ' ' >> double_ >> ' ' >> longitude >> ' ' >> double_); Where latitude and longitude are symbol tables that map from shorthand compass directions to strings (eg

Performance issue with parser written with Boost::spirit

有些话、适合烂在心里 提交于 2019-12-03 08:31:53
I want to parse a file that looks like this (FASTA-like text format): >InfoHeader "Some text sequence that has a line break after every 80 characters" >InfoHeader "Some text sequence that has a line break after every 80 characters" ... e.g.: >gi|31563518|ref|NP_852610.1| microtubule-associated proteins 1A/1B light chain 3A isoform b [Homo sapiens] MKMRFFSSPCGKAAVDPADRCKEVQQIRDQHPSKIPVIIERYKGEKQLPVLDKTKFLVPDHVNMSELVKI IRRRLQLNPTQAFFLLVNQHSMVSVSTPIADIYEQEKDEDGFLYMVYASQETFGFIRENE I wrote a parser for this with boost::spirit. The parser correctly stores the header line and the following text