boost-spirit-qi

AST and operator precedence in rule definition

≡放荡痞女 提交于 2019-12-28 19:29:12
问题 Hello [¹] I have a simple parser (see below). It intends to parse conditional expressions (relational arithmetic operations and logic combinations thereof). In the example given there, it parses successfully A>5 but then stops and ignores the rest of the input, and this is consistent with my impl. How do I change the expr_ rule to make it parse the entire input? #include <cstdint> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include

Building a Custom Expression Tree in Spirit:Qi (Without Utree or Boost::Variant)

≯℡__Kan透↙ 提交于 2019-12-28 16:02:48
问题 First of all, if it is much easier using either Boost Variant or Utree, then I will settle with them, and i will try to solve my issues with them in another topic. However, i would very much like to be able to build a tree like i have below. Background, ignore if you would like to go straight to the issue: I would like to be able to build an expression tree which parses something like "({a} == 0) && ({b} > 5)" or a standard mathmatic expression "(2 * a) + b" I will then define what a and b

How can I use polymorphic attributes with boost::spirit::qi parsers?

五迷三道 提交于 2019-12-27 17:45:12
问题 I would like my boost::spirit-based parser to be able to parse a file, convert the parsed rules into different types, and emit a vector containing all of the matches it found. All of the types that are emitted as attributes should be inherited from a base type, for example: #include <boost/spirit/include/qi.hpp> #include <boost/fusion/adapt_struct.hpp> #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> struct CommandBase { virtual void commandAction() { std::cout << "This is a base

No viable conversion error from boost::spirit::unused_type

两盒软妹~` 提交于 2019-12-25 00:37:56
问题 I'm getting this error: include/boost/spirit/home/phoenix/bind/detail/member_function_ptr.hpp:109:35: No viable conversion from 'boost::spirit::unused_type' to 'const std::__1::basic_string' #define BOOST_SPIRIT_USE_PHOENIX_V3 #define spirit boost::spirit #define phoenix boost::phoenix component_ = lit( '-' ) >> string_[ phoenix::bind( &SemanticActionsType::new_component_name, &actions_, spirit::qi::_1 )] Here is the SemanticActions class: template< typename IterType > class SemanticActions {

boost spirit - unable to get attributes

我是研究僧i 提交于 2019-12-24 11:34:37
问题 I have the following code: #define BOOST_SPIRIT_DEBUG #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> #include <vector> struct parameter { std::string type; std::string name; }; BOOST_FUSION_ADAPT_STRUCT( parameter, (std::string, type) (std::string, name) ) inline std::ostream& operator<<(std::ostream& os, const parameter& param) { os << param.type << ' ' << param.name; return

Boost Spirit : something like permutation, but not exactly

Deadly 提交于 2019-12-24 10:52:03
问题 I'm trying to get a grasp of Spirit, meaning I'm a noob at it (hence expect lack of proper terminology in the below). I have to parse this: value1 = 10 value2 = 20 value3 = 30 value4 = 40 Order doesn't matter but each "value1" ... "value4" line must be present exactly once. This would be OK: value1 = 10 value4 = 40 value2 = 20 value3 = 30 but this would not be OK (duplicated "value1"): value1 = 10 value2 = 20 value3 = 30 value4 = 40 value1 = 10000 Nor this (missing "value4"): value1 = 10

Boost.Spirit.Qi - Bounds checking against primitive data types

会有一股神秘感。 提交于 2019-12-24 04:59:10
问题 I need to check that the value of a parsed qi::uint_ is less than 256. I stumbled across an SO post outlining the following syntax to run checks after a primitive type has been parsed ( qi::double_ in this example). raw [ double_ [_val = _1] ] [ _pass = !isnan_(_val) && px::size(_1)<=4 ] Here, raw[...] returns an iterator to the parsed qi::double_ value, and the final semantic action is used to "test" the resulting value. Extrapolating from the previous example, I assumed I could check bounds

Questions about Spirit.Qi sequence operator and semantic actions

喜你入骨 提交于 2019-12-24 03:04:18
问题 I have some questions about the sequence operator and semantic actions in Spirit Qi. I'm trying to define a grammar rule for a floating point number that accepts metric prefixes (u, m, k, M, etc.) as well as the normal exponent form. rule<Iterator, std::string()> sign = char_("+-") [ _val = _1 ]; rule<Iterator, std::string()> exp = char_("eE") >> -sign >> +digit; rule<Iterator, std::string()> suffix = char_("yzafpnumkKMGTPEZY") [ _val = _1 ]; rule<Iterator, std::string()> mantissa = ((*digit

Skipping blank lines when reading line delimited list of strings

心已入冬 提交于 2019-12-24 01:53:46
问题 I'm trying to parse a simple text file using boost::spirit. The text file is a line delimited list of strings. I can get it to mostly work, except for when it comes to blank lines, which I would like to skip. I've tried several approaches, but I either stop parsing at the blank line, or I get the blank line included in my results. Is there a way to tell my grammar to skip blank lines? code std::ifstream ifs("one.txt"); ifs >> std::noskipws; std::vector< std::string > people; if (parse(

Semantic actions runs multiple times in boost::spirit parsing

徘徊边缘 提交于 2019-12-24 01:48:46
问题 I am trying to create AST with semantic rules while parsing with boost::spirit. AST must be built only for piece of the input, another part of the input should be parsed without sintax tree. For example, for such input strings: "self.usedFoo(Bar).filter( self.baz > baz )" or "self.Foo.filter( true )" AST should be build only for bold part. And there is a problem: parser runs multimple times parsing grammar and calling semantic action (instatntiating AST nodes) multimple times too, so I got