boost-spirit-qi

Boost Spirit Segfault In Parser

不想你离开。 提交于 2019-12-06 11:21:18
I have been trying to convert some lex and yacc code I wrote in an undergraduate compiler, course to spirit code to learn spirit and I have found a segfault that I can't seem to figure out. I wrote the lexer like this: namespace lex = boost::spirit::lex; enum Tokens { k_andTok = 1, k_def = 2, k_elihw = 3, k_elseTok = 4, k_falseTok = 5, k_fed = 6, k_fi = 7, k_ifTok = 8, k_input = 9, k_notTok = 10, k_orTok = 11, k_print = 12, k_returnTok = 13, k_trueTok = 14, k_whileTok = 15, k_plues = 16, k_minus = 17, k_mult = 18, k_div = 19, k_bang = 20, k_equalTo = 21, k_greaterEq = 22, k_lessEq = 23, k

Boost Spirit Qi crashes for memory violation

耗尽温柔 提交于 2019-12-06 11:00:56
But I cannot figure out why...? http://coliru.stacked-crooked.com/a/2912593bb421a35e #include <boost/fusion/adapted/struct.hpp> #include <boost/spirit/include/qi.hpp> namespace bsq = boost::spirit::qi; int main() { std::uint16_t major, minor, build, revision; auto versionParser = bsq::uint_ >> -('.' >> bsq::uint_) >> -('.' >> bsq::uint_) >> -('.' >> bsq::uint_); std::string version = "3.5.1"; auto start = version.begin(); if (!bsq::parse(start, version.end(), versionParser, major, minor, build, revision)) { std::cout << "Error!\n"; } std::cout << major << "-" << minor << "-" << build << "-" <<

Resolve ambiguous boost::spirit::qi grammar with lookahead

☆樱花仙子☆ 提交于 2019-12-06 08:15:41
I want to a list of name-value pairs. Each list is terminated by a '.' and EOL. Each name-value pair is separated by a ':'. Each pair is separated by a ';' in the list. E.g. NAME1: VALUE1; NAME2: VALUE2; NAME3: VALUE3.<EOL> The problem I have is that the values contain '.' and the last value always consumes the '.' at the EOL. Can I use some sort of lookahead to ensure the last '.' before the EOL is treated differently? I have created a sample, that presumably looks like what you have. The tweak is in the following line: value = lexeme [ *(char_ - ';' - ("." >> (eol|eoi))) ]; Note how - ("." >

Optimizing a boost::spirit::qi parser

╄→гoц情女王★ 提交于 2019-12-06 07:36:18
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 raw[] to provide base iterators. The phoenix action calls must be given strings or iterators by which

boost::spirit::qi::grammar and variadic templates

与世无争的帅哥 提交于 2019-12-06 06:15:16
I'm facing with an issue in defining a grammar with variadic templates. I started by defining some simple grammars contained into some struct (e.g. Latitude, Longitude) as follows: #include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/variant.hpp> #include <iostream> #include <string> using namespace boost::spirit; template <class Attribute> using command_rule = qi::rule<std::string::iterator, Attribute, ascii::space_type>; template <class Attribute> using command_grammar = qi::grammar<std::string::iterator, Attribute, ascii::space_type>;

Qi Symbols slow performance?

痞子三分冷 提交于 2019-12-06 03:20:43
问题 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

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

扶醉桌前 提交于 2019-12-06 01:25:45
I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext(execContext) { start = qi::double_[ boost::bind(&my_grammar::newValueForXY, dataContext, ::_1) ]; However, I

C++/Boost: Writing a more powerful sscanf replacement

女生的网名这么多〃 提交于 2019-12-05 23:31:04
问题 I want to write a function in C++ to replace C's sscanf that assigns the matches to iterator. Basically, I want something like: string s = "0.5 6 hello"; std::vector<boost::any> any_vector; sscanv(s, "%f %i %s", any_vector); cout << "float: " << any_cast<float>(any_vector[0]); cout << "integer: " << any_cast<integer(any_vector[1]); cout << "string: " << any_cast<string>(any_vector[2]); The exact details may vary, but you get the idea. Any ideas for implementation? Options so far along with

parse typed csv file with boost::spirit::qi

妖精的绣舞 提交于 2019-12-05 22:51:54
I want to parse a CSV-File with typed values. The type of every column is defined in the header, e.x.: int double double int unsigned 12 1.3 23445 1 42 45 46 47 48 49 The result data structure may be something like this 2-dimensional vector: using ColumnType = boost::variant< std::vector<int>, std::vector<unsigned>, std::vector<double> >; using ResultType = std::vector<ColumnType>; My working code: namespace phoenix = boost::phoenix; namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; using ColumnType = boost::variant< std::vector<int>, std::vector<unsigned>, std::vector

Is there a way to match the content of a spirit::lex string token as a literal in a spirit::qi grammar

对着背影说爱祢 提交于 2019-12-05 20:49:34
I'm writing a DSL and using a Boost Spirit lexer to tokenize my input. In my grammar, I want a rule similar to this (where tok is the lexer): header_block = tok.name >> ':' >> tok.stringval > ';' >> tok.description >> ':' >> tok.stringval > ';' ; Rather than specifying reserved words for the language (e.g. "name", "description") and deal with synchronizing these between the lexer and grammar, I want to just tokenize everything that matches [a-zA-Z_]\w* as a single token type (e.g. tok.symbol ), and let the grammar sort it out. If I weren't using a lexer, I might do something like this: