boost-spirit

Compiler error when adapting struct with BOOST_FUSION_ADAPT_STRUCT [duplicate]

天涯浪子 提交于 2019-12-11 02:22:42
问题 This question already has an answer here : Spirit Qi attribute propagation issue with single-member struct (1 answer) Closed 5 years ago . #include <iostream> #include <vector> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> namespace qi = boost::spirit::qi; struct VectorWrapper { std::vector<std::string> data; }; BOOST_FUSION_ADAPT_STRUCT( VectorWrapper, (std::vector<std::string>, data) ) int

C++ boost::spirit parsing embedded languages

耗尽温柔 提交于 2019-12-11 01:59:42
问题 my question is quite simple in fact. I'm currently working on a language parser that can parse a meta language with embedded DSLs. This is quite interesting for me because it may parse websites with HTML and embedded JavaScript / CSS. I wanted to design some similar system with minimal DSLs for a specific use case. Is boost::spirit capable of doing something similar? I just don't know how boost::spirit handles lexer generation or if it even is a scannerless parser. Thanks in advance! 回答1:

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

How to extract trimmed text using Boost Spirit?

元气小坏坏 提交于 2019-12-11 01:31:27
问题 Using boost spirit, I'd like to extract a string that is followed by some data in parentheses. The relevant string is separated by a space from the opening parenthesis. Unfortunately, the string itself may contain spaces. I'm looking for a concise solution that returns the string without a trailing space. The following code illustrates the problem: #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <string> #include <iostream> namespace qi =

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

Stop X3 symbols from matching substrings

假装没事ソ 提交于 2019-12-10 22:19:36
问题 How does one prevent X3 symbol parsers from matching partial tokens? In the example below, I want to match "foo", but not "foobar". I tried throwing the symbol parser in a lexeme directive as one would for an identifier, but then nothing matches. Thanks for any insights! #include <string> #include <iostream> #include <iomanip> #include <boost/spirit/home/x3.hpp> int main() { boost::spirit::x3::symbols<int> sym; sym.add("foo", 1); for (std::string const input : { "foo", "foobar", "barfoo" }) {

boost spirit 2 : is there a way to know what is the parser progression percentage?

南笙酒味 提交于 2019-12-10 21:22:29
问题 I managed to parse a pgn file into several games mainly thanks to this forum. However, as the files I have to deal with have so many games, the process can take two minutes on my recent computer. That's why I would like to animate a progress bar on the GUI application using this parser. I think the easiest way would be to "ask" spirit how many characters he has already processed, and how many characters remain. (Or how many lines remain and have been processed). Is it possible ? If so, how do

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 ']'