boost-spirit-qi

Parse a '.' chained identifier list, with qi::lexeme and prevent space skipping

丶灬走出姿态 提交于 2021-02-05 08:21:33
问题 im currently working on a Spirit based Expression Parser that should allow in the end (far far in the future) expressions like "a*b*c" "10+20*x.y.z" "a.b.c[ a.b ][ e.c( d.e()*4 )].e.f( (a.b+23)*d, -23*b.e(a.b.c) ).x.y" wild mix of member accesses, array subscriptions, function calling and expressions [] -> subscription () -> function call or expression bracket . member chaining currently im fighting with the space skipping on member-chaining "a . b . c" is not valid in my world - but gets

boost spirit parsing quote string fails

旧街凉风 提交于 2021-01-28 11:50:25
问题 This is my grammer unesc_char.add(L"\\a", L'\a')(L"\\b", L'\b')(L"\\f", L'\f')(L"\\n", L'\n') (L"\\r", L'\r')(L"\\t", L'\t')(L"\\v", L'\v')(L"\\\\", L'\\') (L"\\\'", L'\'')(L"\\\"", L'\"'); unesc_str = '\"' >> *((boost::spirit::standard_wide::char_ - '\"') | unesc_char) >> '\"'; with qi::rule<Iterator, std::wstring()> unesc_str; qi::symbols<wchar_t const, wchar_t const> unesc_char; Parsing fails on : "Hello\"" -> should return Hello" Parsing correct on : "Hello\\" -> should return Hello\

Use of optional parser in spirit qi

我只是一个虾纸丫 提交于 2021-01-28 02:57:16
问题 I'm trying to parse either an additive expression of the form "A+C", or "A" alone. After a few tests I realized that the problem is apparently my use of the optional parser, so to exemplify: qi::rule<string::iterator, string()> Test; Test = ( qi::string("A")[qi::_val= qi::_1] >> -( qi::string("B")[qi::_val += qi::_1] >> qi::string("C")[qi::_val += qi::_1] ) ) ; string s1, s2; s1 = "AB"; bool a= qi::parse(s1.begin(), s1.end(), Test, s2); The idea is to parse 'A' or "ABC", but if the s1 value

Attributes of sequence and list operator in boost.spirit qi?

自作多情 提交于 2021-01-28 02:31:52
问题 I want to parse something like "{xxxx} {xxxx}" which is separated by eol into a vector<vector<wchar_t>> : ({xxxx},{xxxx}) so that "{" and "}" stays with internal characters together. My code is: #define BOOST_SPIRIT_UNICODE #include <iostream> #include<boost/spirit/include/qi.hpp> #include<string> #include<vector> using namespace std; namespace sw=boost::spirit::standard_wide; namespace qi= boost::spirit::qi; using boost::spirit::standard_wide::char_; int main() { wstring s = L"{\"id\":23,\

Attributes of sequence and list operator in boost.spirit qi?

匆匆过客 提交于 2021-01-27 22:51:36
问题 I want to parse something like "{xxxx} {xxxx}" which is separated by eol into a vector<vector<wchar_t>> : ({xxxx},{xxxx}) so that "{" and "}" stays with internal characters together. My code is: #define BOOST_SPIRIT_UNICODE #include <iostream> #include<boost/spirit/include/qi.hpp> #include<string> #include<vector> using namespace std; namespace sw=boost::spirit::standard_wide; namespace qi= boost::spirit::qi; using boost::spirit::standard_wide::char_; int main() { wstring s = L"{\"id\":23,\

Attributes of sequence and list operator in boost.spirit qi?

五迷三道 提交于 2021-01-27 20:52:19
问题 I want to parse something like "{xxxx} {xxxx}" which is separated by eol into a vector<vector<wchar_t>> : ({xxxx},{xxxx}) so that "{" and "}" stays with internal characters together. My code is: #define BOOST_SPIRIT_UNICODE #include <iostream> #include<boost/spirit/include/qi.hpp> #include<string> #include<vector> using namespace std; namespace sw=boost::spirit::standard_wide; namespace qi= boost::spirit::qi; using boost::spirit::standard_wide::char_; int main() { wstring s = L"{\"id\":23,\

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

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

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