boost-spirit

How to use Boost Spirit auto rules with AST?

醉酒当歌 提交于 2021-01-27 07:53:08
问题 EDIT: I expanded sehe's example to show the problem when I want to use it on another rule: http://liveworkspace.org/code/22lxL7$17 I'm trying to improve the performances of my Boost Spirit parser and I saw that since C++11, it was possible to use auto-rules like that: auto comment = "/*" >> *(char_ - "*/") >> "*/"; (or with BOOST_AUTO or BOOST_SPIRIT_AUTO). I have a rule declarer like that: qi::rule<lexer::Iterator, ast::SimpleType()> simple_type; and defined like that: simple_type %= const_

How to parse an CSV like escaped String with Boost Spirit?

柔情痞子 提交于 2020-05-15 11:11:16
问题 For my express parser project i would like to use CSV like escaping: "" to escape " Examples: "\"hello\"", " \" hello \" ", " \" hello \"\"stranger\"\" \" ", online compile&try: https://wandbox.org/permlink/5uchQM8guIN1k7aR my current parsing rule only parses the first 2 tests qi::rule<std::string::const_iterator, qi::blank_type, utree()> double_quoted_string = '"' >> qi::no_skip[+~qi::char_('"')] >> '"'; i've found this stackoverflow question and one answer is given using spirit: How can I

How to set max recursion in boost spirit

北慕城南 提交于 2020-04-14 02:58:34
问题 Using boost::spirit, if I have a recursive rule to parse parentheses rule<std::string::iterator, std::string()> term; term %= string("(") >> *term >> string(")"); how do I limit the maximum amount of recursion? For example, if I try to parse a million nested parentheses, I get a segfault because the stack size has been exceeded. To be concrete, here is a complete sample. #include <iostream> #include <string> #include <boost/spirit/include/qi.hpp> int main(void) { using namespace boost::spirit

How to set max recursion in boost spirit

好久不见. 提交于 2020-04-14 02:58:11
问题 Using boost::spirit, if I have a recursive rule to parse parentheses rule<std::string::iterator, std::string()> term; term %= string("(") >> *term >> string(")"); how do I limit the maximum amount of recursion? For example, if I try to parse a million nested parentheses, I get a segfault because the stack size has been exceeded. To be concrete, here is a complete sample. #include <iostream> #include <string> #include <boost/spirit/include/qi.hpp> int main(void) { using namespace boost::spirit

Simple expression with boost::spirit

寵の児 提交于 2020-02-25 05:13:46
问题 I need to parse simple_expression ::= limit int_number (days | hours | minutes) . I wrote code for grammar struct Parser: grammar<std::string::const_iterator, boost::spirit::ascii::space_type> { public: Parser(ConditionTree& a_lTree): Parser::base_type(limit_expression), m_lTree(a_lTree) { using boost::spirit::qi::uint_; using boost::spirit::qi::_1; using boost::spirit::qi::_2; limit_expression = limit_days_operator | limit_hours_operator | limit_minutes_operator ; limit_days_operator = (

how to avoid defining token which matchs everything in boost::spirit::lex

孤人 提交于 2020-02-05 03:12:06
问题 I want to create a grammar and lexer to parse the below string: 100 reason phrase regular expression will be: "\d{3} [^\r\n]*" token definition: template <typename Lexer> struct custom_tokens : lex::lexer<Lexer> { custom_tokens() { this->self.add_pattern ("STATUSCODE", "\\d{3}") ("SP", " ") ("REASONPHRASE", "[^\r\n]*") ; this->self.add ("{STATUSCODE}", T_STATUSCODE) ("{SP}", T_SP) ("{REASONPHRASE}", T_REASONPHRASE) ; } }; grammar: template <typename Iterator> struct custom_grammar : qi:

spirit x3 cannot propagate attributes of type optional<vector>

六月ゝ 毕业季﹏ 提交于 2020-01-24 15:48:47
问题 A simple parser as on Coliru. The parser -(+x3::alpha) should be able to propagate an attribute of type boost::optional<std::string> as Qi does. But it does not compile. std::string const input = "abc"; boost::optional<std::string> attr; if(x3::parse(boost::begin(input),boost::end(input), -(+x3::alpha), attr)) { std::cout<<"match!"<<std::endl; } else { std::cout<<"NOT match!"<<std::endl; } 回答1: I don't think the normative claim "should be able [...] as Qi does" cuts wood. X3 is not an

Boost Spirit x3 conditional (ternary) operator parser (follow up question)

核能气质少年 提交于 2020-01-23 17:27:13
问题 This question is a follow up question for the one in Boost Spirit x3 conditional (ternary) operator parser The original question context did not show (my bad!) the ast attributes and the answer therefore could not take all the moving parts into account. This question now shows how the ast attributes looks like and how the ast is used to evaluate the expression with a symbol table. The follow up question is therefore that how the correctly spelled ternary conditional should change the ast

How to use boost::spirit to parse a sequence of words into a vector?

≡放荡痞女 提交于 2020-01-23 05:51:55
问题 I'm trying to learn boost::spirit . As an example, I'm trying to parse a sequence of words into a vector<string> . I tried this: #include <boost/spirit/include/qi.hpp> #include <boost/foreach.hpp> namespace qi = boost::spirit::qi; int main() { std::vector<std::string> words; std::string input = "this is a test"; bool result = qi::phrase_parse( input.begin(), input.end(), +(+qi::char_), qi::space, words); BOOST_FOREACH(std::string str, words) { std::cout << "'" << str << "'" << std::endl; } }

Defining function in spirit rule gives warning

故事扮演 提交于 2020-01-15 08:15:27
问题 qi::repeat(1,2) funtion in rule is giving me warrning and i dont want to ignore that warning so i want to optimized this code like separating the rule from the parsering method. qi::phrase_parse is doing the same thing which is in the the rule but i want to sperate the rule and give rule to the pharse_parse funtion. std::ifstream ifs("f:/test.txt"); std::string line; //In header in my code std::vector<unsigned long long> v_BF_Char; //qi::int_parser<uintmax_t, 16> hex_int; static qi::uint