boost-spirit

Boost Spirit: Error C2664, Cannot convert 'const boost::phoenix::actor<Eval>' to 'char'

落花浮王杯 提交于 2019-12-07 16:40:56
问题 I'm new to Boost Spirit and trying to write JSON parser using Boost Spirit 2.4.2 (Boost 1.46.1). For the code below, I get the error when trying to execute semantic action/attribute: Error 1 error C2664: 'void (char)' : cannot convert parameter 1 from 'const boost::phoenix::actor<Eval>' to 'char' I saw some questions but they don't really apply to my case. Please kindly help. Thank you! #include <map> #include <string> #include <vector> #include <iostream> #include <boost/config/warning

How might I assume a “default value” when parsing using boost::spirit?

微笑、不失礼 提交于 2019-12-07 16:19:57
问题 Let's say I have a grammar defined to something like: some_rule := a b [c [d]] where c , and d are optional and default to a certain value (let's say 14) if not given. Can I get it to default to the 14 if the value isn't given? I want the produced std::vector to always be of size 4. The closest I've come is like the following: qi::rule<Iterator, std::vector<int>(), ascii::space_type> some_rule; some_rule %= int_ >> int_ >> -int_ >> -int_; // ... some_other_rule = some_rule[&some_callback_for

boost spirit parsing CSV with columns in variable order

不想你离开。 提交于 2019-12-07 14:52:49
问题 I'm trying to parse a CSV file (with header line) using boost spirit. The csv is not in a constant format. Sometimes there is some extra column or the order of the column is mixed. I'm interested in few columns, whose header name is well known. For instance my CSV may look like: Name,Surname,Age John,Doe,32 Or: Age,Name 32,John I want to parse only the content of Name and Age (N.B. Age is integer type). At the moment i come out with a very ugly solution where Spirit parses the first line and

Boost spirit lex write token value back to input stream

北战南征 提交于 2019-12-07 13:59:55
问题 I'm wondering if there's a way in boost::spirit::lex to write a token value back to the input stream (possibly after editing) and rescanning again. What I'm basically looking for is a functionality like that offered by unput() in Flex. Thanks! 回答1: Sounds like you just want to accept tokens in different orders but with the same meaning. Without further ado, here is a complete sample that shows how this would be done, exposing the identifier regardless of input order. Output: Input 'abc('

Using Boost Spirit to parse a text file while skipping large parts of it

僤鯓⒐⒋嵵緔 提交于 2019-12-07 12:59:45
问题 I have the following std::string : <lots of text not including "label A" or "label B"> label A: 34 <lots of text not including "label A" or "label B"> label B: 45 <lots of text not including "label A" or "label B"> ... I want extract single integral numbers following all occurrences of label A or label B and place them in corresponding vector<int> a, b . A simple, but not elegant way of doing it is using find("label A") and find("label B") and parsing whichever is first. Is there a succinct

boost::Spirit Grammar for unsorted schema

怎甘沉沦 提交于 2019-12-07 10:46:30
问题 I have a section of a schema for a model that I need to parse. Lets say it looks like the following. { type = "Standard"; hostname="x.y.z"; port="123"; } The properties are: The elements may appear unordered. All elements that are part of the schema must appear, and no other. All of the elements' synthesised attributes go into a struct. (optional) The schema might in the future depend on the type field -- i.e., different fields based on type -- however I am not concerned about this at the

Boost Spirit X3 AST not working with semantic actions when using separate rule definition and instantiation

谁说我不能喝 提交于 2019-12-07 04:44:16
问题 I am trying to use Boost Spirit X3 with semantic actions while parsing the structure to an AST. If I use a rule without separate definition and instantiation it works just fine, for example: #include <vector> #include <string> #include <iostream> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/home/x3.hpp> namespace ast { struct ast_struct { int number; std::vector<int> numbers; }; } BOOST_FUSION_ADAPT_STRUCT( ast::ast_struct, (int, number) (std::vector<int>, numbers)

Parsing a number of named sets of other named sets

你说的曾经没有我的故事 提交于 2019-12-07 03:17:46
问题 So I want to write a... well... not-so-simple parser with boost::spirit::qi. I know the bare basics of boost spirit, having gotten acquainted with it for the first time in the past couple of hours. Basically I need to parse this: # comment # other comment set "Myset A" { figure "AF 1" { i 0 0 0 i 1 2 5 i 1 1 1 f 3.1 45.11 5.3 i 3 1 5 f 1.1 2.33 5.166 } figure "AF 2" { i 25 5 1 i 3 1 3 } } # comment set "Myset B" { figure "BF 1" { f 23.1 4.3 5.11 } } set "Myset C" { include "Myset A" #

boost::optional to bool, inside boost::spirit::qi grammar

断了今生、忘了曾经 提交于 2019-12-07 02:30:26
问题 In my boost::spirit grammar I have the following snippet; implicit_method_declaration = (-(qi::token(ABSTRACT)) >> ...) The type of -(qi::token(ABSTRACT) is boost::optional<boost::iterator_range<std::string::iterator>> however I'm only using this construct to check if the abstract keyword, is actually present, that is, I'd rather have -(qi::token(ABSTRACT) have the type bool with the value boost::optional<...> operator bool() const . How would I go about achieving this? 回答1: I think you're

How to use boost::tuple as attribute in a boost::spirit rule?

人走茶凉 提交于 2019-12-07 02:11:46
问题 I have the following rule in boost::spirit : typedef boost::tuple<int, int> Entry; qi::rule<Iterator, Entry(), Skipper> entry; entry = qi::int_ >> qi::int_; But the second int is not written into the tuple. Is there a way to make it work without having to use boost::fusion::tuple ? It works if I use std::pair , so why can't I use boost::tuple ? Here is a full compiling example: #include <iostream> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/tuple.hpp> #include <boost