boost-spirit

How can I extend a boost spirit grammar

一曲冷凌霜 提交于 2019-12-05 01:00:30
问题 The thing is that I made a grammar that has been useful for a task, but now the task has changed and I need to define new rules. But I wouldn't like to modify the grammar I already have instead of that I'd like to create a new grammar that uses the existing grammar I have without code duplication, so I just need to define the new rules I need. I tried something like this, but is not working : struct New_grammar : Old_grammar<Iterator, Skipper> { New_grammar() : New_grammar::base_type(Command

How to parse DSL input to high performance expression template

扶醉桌前 提交于 2019-12-04 21:34:24
( EDITED both title and main text and created a spin-off question that arose) For our application it would be ideal to parse a simple DSL of logical expressions. However the way I'd like to do this is to parse (at runtime) the input text which gives the expressions into some lazily evaluated structure (an expression template) which can then be later used within more performance sensitive code. Ideally the evaluation is as fast as possible using this technique as it will be used a large number of times with different values substituting into the placeholders each time. I'm not expecting the

Spirit Qi : rule for char [5]

懵懂的女人 提交于 2019-12-04 19:05:36
I have the following structure struct MyStruct { char CODE; char NAME[5]; }; I make it a fusion struct BOOST_FUSION_ADAPT_STRUCT ( MyStruct, (char, MARKET_CODE) (char, NAME[5]) ) My grammar is implemented as follow: MyStruct_parser() : ticker_parser::base_type(start) { using qi::lexeme; using ascii::char_; a_word %= lexeme[+(char_)]; start %= a_word >> a_word; } qi::rule<Iterator, std::string(), ascii::space_type> quoted_string; qi::rule<Iterator, Ticker(), ascii::space_type> start; Unfortunately it does not compile. Now I use std::string instead of char[5] I have no problem. Can you please

Splitting string using boost spirit

半世苍凉 提交于 2019-12-04 18:44:55
Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile template <typename Iterator> struct ValueList : bsq::grammar<Iterator, std::vector<std::string>()> { ValueList(const std::string& sep, bool isCaseSensitive) : ValueList::base_type(query) { if(isCaseSensitive) { query = value >> *(sep >> value); value = *(bsq::char_ - sep); } else { auto separator = bsq::no_case[sep]; query = value >> *(separator >> value); value = *(bsq::char_ - separator); } } bsq::rule<Iterator, std::vector<std:

I can't get the string value of a token

╄→гoц情女王★ 提交于 2019-12-04 18:32:20
问题 I try to implement a Lexer for a little programming language with Boost Spirit. I have to get the value of a token and I get a bad_get exception : terminate called after throwing an instance of 'boost::bad_get' what(): boost::bad_get: failed value get using boost::get Aborted I obtain this exception when doing : std::string contents = "void"; base_iterator_type first = contents.begin(); base_iterator_type last = contents.end(); SimpleLexer<lexer_type> lexer; iter = lexer.begin(first, last);

Ambiguous variant and boost spirit x3

血红的双手。 提交于 2019-12-04 18:22:43
问题 Trying to tweak the boost spirit x3 calc example to parse functions that can take functions as arguments. However it does not compile. namespace client{ namespace ast{ struct ts; struct fnc; typedef boost::variant< ts, boost::recursive_wrapper<fnc> > node; struct ts{ unsigned int id; }; struct fnc{ std::vector<char> id; std::vector<node> args; }; }} BOOST_FUSION_ADAPT_STRUCT( client::ast::ts, (unsigned int, id) ) BOOST_FUSION_ADAPT_STRUCT( client::ast::fnc, (std::vector<char>, id) (std:

basic boost spirit semantic action doesn't compile

淺唱寂寞╮ 提交于 2019-12-04 16:58:07
I am trying to add a greater than operator > to a ast: the code is 95% identical to the code in the docs. Two points of interest below A block of code where I'm trying to write support for greater than: commented in the code below. A single line in the parse for term which fails to compile because I don't yet understand semantic actions yet: not sure how to bind the lhs of lhs > rhs through phoenix and semantic actions. The solution should be trivial for regular users of Spirit, but I am still learning, and only getting by through examples so far. Any help would be appreciated. TIA. Code

how to get rid of escape character in a token with spirit::lex?

妖精的绣舞 提交于 2019-12-04 14:23:53
I want to tokenize my own extension of SQL syntax. This involves recognizing an escaped double quote inside a double quoted string. E.g. in MySQL these two string tokens are equivalent: """" (the second double quote acts as an escape character) and '"' . I have tried different things but I am stuck at how to replace a token's value. #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct sql_tokens : lex::lexer<Lexer> { sql_tokens() { string_quote_double = "\\\""; // '"' this->self("INITIAL") = string_quote_double [ lex::_state =

Strange semantic behaviour of boost spirit x3 after splitting

这一生的挚爱 提交于 2019-12-04 14:04:38
I came across a strange behaviour of boost spirit x3, after I splittet my grammar up into the recommended parser.hpp , parser_def.hpp , parser.cpp files. My example gramar parses some kind of easy enums: enum = "enum" > identifier > "{" > identifier % "," > "} this is my enum grammar. When I don't split the enum and identifier parser into the recommended files, everything works fine, especially the string "enum {foo, bar}" throws an expectation failure, as expected. This example can be found here: unsplitted working example But when I split the exactly same grammar up into the different files,

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: