boost-spirit-qi

How to write a boost::spirit::qi parser to parse an integer range from 0 to std::numeric_limits<int>::max()?

佐手、 提交于 2020-01-15 05:58:09
问题 I tried to use qi::uint_parser<int>() . But it is the same like qi::uint_ . They all match integers range from 0 to std::numeric_limits<unsigned int>::max() . Is qi::uint_parser<int>() designed to be like this? What parser shall I use to match an integer range from 0 to std::numeric_limits<int>::max() ? Thanks. 回答1: Simplest demo, attaching a semantic action to do the range check: uint_ [ _pass = (_1>=0 && _1<=std::numeric_limits<int>::max()) ]; Live On Coliru #include <boost/spirit/include

How to write a boost::spirit::qi parser to parse an integer range from 0 to std::numeric_limits<int>::max()?

落花浮王杯 提交于 2020-01-15 05:57:29
问题 I tried to use qi::uint_parser<int>() . But it is the same like qi::uint_ . They all match integers range from 0 to std::numeric_limits<unsigned int>::max() . Is qi::uint_parser<int>() designed to be like this? What parser shall I use to match an integer range from 0 to std::numeric_limits<int>::max() ? Thanks. 回答1: Simplest demo, attaching a semantic action to do the range check: uint_ [ _pass = (_1>=0 && _1<=std::numeric_limits<int>::max()) ]; Live On Coliru #include <boost/spirit/include

Performance issue with parser written with Boost::spirit

邮差的信 提交于 2020-01-12 06:01:16
问题 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

Boost.Spirit Parsing Optional Prefix

女生的网名这么多〃 提交于 2020-01-11 09:43:08
问题 I'm attempting to parse a string of whitespace-delimited, optionally-tagged keywords. For example descr:expense type:receivable customer 27.3 where the expression before the colon is the tag, and it is optional (i.e. a default tag is assumed). I can't quite get the parser to do what I want. I've made some minor adaptations from a canonical example whose purpose it is to parse key/value pairs (much like an HTTP query string). typedef std::pair<boost::optional<std::string>, std::string> pair

Define parsers parameterized with sub-parsers in Boost Spirit

爱⌒轻易说出口 提交于 2020-01-11 05:22:06
问题 I would like to convert some old hand-written parsing code to Boost Spirit and learn (more of) spirit in the process. The old code uses streams and templates to parse definitions for some data-types and some containers. Some typical formats: VECTOR[number_of_items,(item_1, item_2 .... item_n)] PAIR(p1, p2) RECT[(left,top)-(right,bottom)] Point( x, y ) Size( x, y ) The parsing functions are templates with the type of the items as template parameter and use streams as input, e.g. template<class

How do you create a generic parser using qi?

我的梦境 提交于 2020-01-07 06:25:16
问题 I am attempting to create generic parser-elements using qi as I unfortunately (MSVC must be supported) can not use X3. The idea is to have a templated struct: template<class T> struct parse_type; Which I could use like this: template<class T> T from_string(std::string const& s) { T res; parse_type<T> t; ... if (phrase_parse(...,parse_type<T>(),...,t)) } or specialise like this template<class T,class Alloc> struct parse_type<std::vector<T,Alloc>> { // Parse a vector using rule '[' >> parse

How do you create a generic parser using qi?

本小妞迷上赌 提交于 2020-01-07 06:25:05
问题 I am attempting to create generic parser-elements using qi as I unfortunately (MSVC must be supported) can not use X3. The idea is to have a templated struct: template<class T> struct parse_type; Which I could use like this: template<class T> T from_string(std::string const& s) { T res; parse_type<T> t; ... if (phrase_parse(...,parse_type<T>(),...,t)) } or specialise like this template<class T,class Alloc> struct parse_type<std::vector<T,Alloc>> { // Parse a vector using rule '[' >> parse

Boost Spirit QI slow

混江龙づ霸主 提交于 2020-01-06 19:31:29
问题 I try to parse TPCH files with Boost Spirit QI. My implementation inspired by the employee example of Spirit QI ( http://www.boost.org/doc/libs/1_52_0/libs/spirit/example/qi/employee.cpp ). The data is in csv format and the tokens are delimited with a '|' character. It works but it is very slow (20 sec. for 1 GB). Here is my qi grammer for the lineitem file: struct lineitem { int l_orderkey; int l_partkey; int l_suppkey; int l_linenumber; std::string l_quantity; std::string l_extendedprice;

segmentation fault with trivial spirit parser

我的未来我决定 提交于 2020-01-06 02:57:24
问题 I've been using spirit::qi quite often for the past several months. However, this time I got a segfault that I really can't make any sense out of. I have reduced it to an extremely minimal test case, the grammar definition is 12 lines of code. This feels a lot like an earlier question but the solution there, of adding .alias() to some of the terminals so that qi doesn't make copies of them, doesn't seem to fix this. I'm concerned that there's something fundamental I'm missing here, since I've

Using semantic action together with attribute propagation in spirit

夙愿已清 提交于 2020-01-05 04:26:05
问题 I played a little with code at link and I have another question. I added semantic action to: action = actions_ >> '(' >> parameters >> ')'[ /* semantic action placed here */]; so I can reuse the rule together with verification at multiple places. The problem is that then the spirit stops propagate my attribute type to the upper rules (which uses the action as parser). I read at link that operator %= should be used to enable it again (to have semantic actions and attribute propagation). But