boost-spirit-qi

trigger warning from boost spirit parser

给你一囗甜甜゛ 提交于 2019-12-11 07:52:22
问题 How I can add warnings in boost spirit parser. Edit: ... that could report the issue with position For example if I have an integer parser: ('0' >> oct) | int_ I would like to be able to do something like this: ('0' >> oct) | "-0" --> trigger warning("negative octal values are not supported, it will be interpreted as negative decimal value and the leading 0 will be ignored") | int_ 回答1: Q. Can I create my own callback? How? A. Sure. Any way you'd normally do it in C++ (or look at Boost

Boost.Spirit qi value sequence vector

与世无争的帅哥 提交于 2019-12-11 05:23:25
问题 Following code does not compile with error: /usr/include/boost/spirit/home/qi/detail/assign_to.hpp:153:20: error: no matching conversion for static_cast from 'const char' to 'boost::fusion::vector<char, std::vector<double, std::allocator<double> > >' attr = static_cast<Attribute>(val); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ I can't figute out why, because it works as expected with change to auto grammar = boost::spirit::no_skip[drawto_commands]; . Types of what moveto and lineto parses are same. Qi

Boost Spirit Qi Attribute Propagation

本小妞迷上赌 提交于 2019-12-11 04:03:53
问题 I have an issue with a Boost Spirit Qi grammar that is emitting an undesired type, resulting in this compilation error: error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'unsigned int' Here is the grammar that is causing the issue: qi::rule<Iterator, qi::unused_type()> gr_newline; // asmast::label() just

What is the correct way to use boost::qi::rule with BOOST_FUSION_ADAPT_STRUCT?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:46:00
问题 I am attempting to get a qi::rule<> to emit a struct with BOOST_FUSION_ADAPT_STRUCT based on the boost employee example. I have the following struct and its associated fusion macro: struct LineOnCommand { int lineNum; std::vector<char> humpType; }; BOOST_FUSION_ADAPT_STRUCT( LineOnCommand, (int, lineNum) (std::vector<char>, humpType) ) The associated parsing rules are: qi::rule<Iterator, std::vector<char> ascii::space_type> humpIdentifer = qi::lit("BH") | qi::lit("DH"); qi::rule<Iterator,

Flipping the order of subrules inside a rule in a boost::spirit grammar results in segfault

冷暖自知 提交于 2019-12-11 02:58:17
问题 Warning; while I tried to shorten the code down, to a minimum. I still had to include quite a bit, to ensure that the required information was present. This code, compiles files, and runs resulting in a syntax error; name = simple_name [ qi::_val = qi::_1 ] | qualified_name [ qi::_val = qi::_1 ] ; While this; name = qualified_name [ qi::_val = qi::_1 ] | simple_name [ qi::_val = qi::_1 ] ; Results in a SIGSEGV , Segmentation fault; boost::detail::function::function_obj_invoker4<boost::spirit:

How do I use a class with only one attribute in a AST with Boost Spirit?

﹥>﹥吖頭↗ 提交于 2019-12-11 01:42:40
问题 I want to parse a file into an AST using Boost Spirit. The root of my AST is a class with only one attribute : typedef boost::variant<FunctionDeclaration, GlobalVariableDeclaration> FirstLevelBlock; struct Program { std::vector<FirstLevelBlock> blocks; }; BOOST_FUSION_ADAPT_STRUCT( ::Program, (std::vector<eddic::FirstLevelBlock>, blocks) ) If I parse using a single rule : program %= *(function | globalDeclaration); it doesn't compiles, but if I add a single string name to Program, it works

Boost Spirit Qi Expectation

a 夏天 提交于 2019-12-11 00:47:41
问题 I am relatively new to Spirit Qi, and am trying to parse an assembler-like language. For example, I'd like to parse: Func Ident{ Mov name, "hello" Push 5 Exit } So far, so good. I can parse it properly. However, the error handler sometimes comes up with strange error locations. Take for example the following faulty code: Func Ident{ Mov name "hello" ; <-- comma is missing here Push 5 Exit } Here are the rules involved in this parsing: gr_function = lexeme["Func" >> !(alnum | '_')] // Ensure

strange error with boost::spirit::position_iterator2

假装没事ソ 提交于 2019-12-11 00:26:26
问题 So what I am trying to do is to parse a list of strings: namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; std::string TEST = "aa\nbbbb\nccc\n"; std::istringstream INPUT (TEST); std::noskipws(INPUT); typedef std::istreambuf_iterator<char> base_iterator; typedef boost::spirit::multi_pass<base_iterator> multi_pass_iter; typedef boost::spirit::classic::position_iterator2<multi_pass_iter> pos_iterator; base_iterator base_begin(INPUT); multi_pass_iter first = boost::spirit:

Boost.spirit: parsing number char and string

∥☆過路亽.° 提交于 2019-12-10 22:22:48
问题 I need to parse a line containing an unsigned int, the character X that is to be discarded, and a string, all separated by one or more spaces. e.g., 1234 X abcd bool a = qi::phrase_parse(first, last, uint_[ref(num) = _1] >> lit('X') >> lexeme[+(char_ - ' ')], space, parsed_str); The above code parses the three parts, but the string ends up containing a junk character ( �abcd ) and having a size of 5 and not 4. What is wrong with my parser? and why is there junk in the string? 回答1: What you

Store values in a std::map<std::string, std::string> using boost::spirit::qi::phrase_parse

心不动则不痛 提交于 2019-12-10 19:40:21
问题 I'm currently trying to get some work done using boost::spirit::qi::phrase_parse but I'm not able to figure this out by myself. Worth mentioning: I'm totally new to boost and so to boost::spirit. I'm getting an input of the form "{A [B C] -> F [D E], C ->E,B->Z}" I'd like to parse this type of input into a std::map<std::string, std::string> . The key should hold every std::string before the "->" and the value every std::string after the "->" until the ',' occurs. Furthermore the '[' and ']'