boost-spirit

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>

storing line numbers of expressions with boost.spirit 2

為{幸葍}努か 提交于 2019-12-01 03:36:10
I am planning on doing a script transformation utility (for extended diagnostic information) using Boost.Spirit 2. While there is support for line information etc. for parsing errors, how i can store line numbers for successfully parsed expressions with Qi? As per the mailing list, Spirit.Classic positional iterators can also be used with Spirit 2 . There is also an article on an iter_pos-parser on the Spirit -blog. I will update when i had time to test. sehe I realize I noticed the question late, but let me add this anyway. I wrote a sample of an INI file parser in another answer: Cross

Spirit X3, Is this error handling approach useful?

限于喜欢 提交于 2019-12-01 01:27:47
After reading the the Spirit X3 tutorial on error handling and some experimentation. I was drawn to a conclusion. I believe there is some room for improvement on the topic of error handing in X3. An important goal from my perspective is to provide a meaningful error message. First and foremost adding a semantic action that will set the _pass(ctx) member to false wouldn’t do it because X3 will try to match something else. Only throwing an x3::expectation_failure will quit the parse function prematurely, i.e. without trying to match anything else. So what is left are the parser directive expect

boost::spirit::hold_any memory corruption

試著忘記壹切 提交于 2019-12-01 01:03:26
I have a large code base that can use boost::any or boost::spirit::hold_any (depending on a macro definition). hold_any seems to be compatible with boost::any (e.g. How to print boost::any to a stream? or Type erasure - Part IV ) and faster ( Why you shouldn’t use boost::any ) but I'm experiencing several segmentation fault errors using hold_any (Boost v1.55 / 1.54 / 1.53). This is a minimal working example that exhibits the same problem as the original code: #include <iostream> #include <string> #include <vector> #include <boost/spirit/home/support/detail/hold_any.hpp> typedef boost::spirit:

How do I capture the original input into the synthesized output from a spirit grammar?

自作多情 提交于 2019-12-01 00:49:58
I'm working on a boost::spirit::qi::grammar and would like to copy a portion of the original text into the synthesized output structure of the grammar (more specifically, the portion that matched one of the components of the rule). The grammar would ultimately be used as a sub-grammar for a more complicated grammar, so I don't really have access to the original input. I'm guessing that this can be done through semantic actions or the grammar context, but I can't find an example that does this without access to the original parse(). Here's what I have so far: #include <iostream> #include <boost

storing line numbers of expressions with boost.spirit 2

房东的猫 提交于 2019-12-01 00:14:19
问题 I am planning on doing a script transformation utility (for extended diagnostic information) using Boost.Spirit 2. While there is support for line information etc. for parsing errors, how i can store line numbers for successfully parsed expressions with Qi? 回答1: As per the mailing list, Spirit.Classic positional iterators can also be used with Spirit 2 . There is also an article on an iter_pos-parser on the Spirit -blog. I will update when i had time to test. 回答2: I realize I noticed the

Spirit Lex: Which token definition generated this token?

时光怂恿深爱的人放手 提交于 2019-11-30 23:36:06
Sorry if this is a newbie question, but I need to know which token definition produced a certain token. When I print the token ID, I just get an integer. I need to know which regex generated this token. Edit: Here's how I define my tokens: template <typename LexerT> class Tokens: public lex::lexer<LexerT> { public: Tokens(const std::string& input): lineNo_(1) { using boost::spirit::lex::_start; using boost::spirit::lex::_end; using boost::spirit::lex::_pass; using boost::phoenix::ref; using boost::phoenix::construct; // macros this->self.add_pattern ("EXP", "(e|E)(\\+|-)?\\d+") ("SUFFIX", "

Boost spirit floating number parser precision

Deadly 提交于 2019-11-30 21:59:46
There is something strange I noticed when comparing boost::lexical_cast and boost spirit parsing. I'm trying to parse a string into float. for some reason spirit gives very imprecise result. for example: when parsing string "219721.03839999999" using lexical_cast i get 219721.03 which is more or less OK. but when I use spirit (see code below) I get "219721.11" which is far from bein OK. Any idea why it happens? template<> inline float LexicalCastWithTag(const std::string& arg) { float result = 0; if(arg.empty()) { throw BadLexicalCast("Cannot convert from to std::string to float"); } auto

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>