boost-spirit-qi

How can I track my input position with multiple inputs using Boost::Spirit::Qi?

徘徊边缘 提交于 2019-12-10 19:27:45
问题 I'd like to support something like C++'s #include mechanism in a boost spirit parser. Essentially, I have a script command that asks my parser to load a sub script from a file. I'd like to be able to report error messages as described in the tracking input position while parsing post, but they don't cover parsing for multiple inputs. Can this be reasonably accomplished using boost::spirit::qi ? I've worked around getting the differing inputs in using a smarter iterator type. I'd still like to

Grammar balancing issue

末鹿安然 提交于 2019-12-10 19:13:15
问题 Is it possible to force Boost.Spirit Qi to behave in such way, that generated grammar would be adjustable in compliance with some runtime-calculable conditions/rules/rates? For example, the input consists of language constructs, that cause the different alternatives during parsing, some more frequently, others -- less. But the order of the alternatives affects on the efficiency, i.e. runtime optimality of the grammar. In some cases it is impossible to determine in advance which alternative

making a vector of shared pointers from Spirit Qi

那年仲夏 提交于 2019-12-10 18:16:51
问题 This is a followup question from a previous question. I can parse into vectors of strings from my grammar, but I cannot seem to parse into a vector of shared pointers to strings ; i.e. std::vector<std::shared_ptr<std::string> > , and need a bit of help. My compiling header: #define BOOST_SPIRIT_USE_PHOENIX_V3 1 #include <boost/spirit/include/qi_core.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp>

Why does Boost.Spirit correctly parse an identifier into a std::string, but not into an adapted struct consisting solely of std::string?

三世轮回 提交于 2019-12-10 17:20:03
问题 I have defined a rule for an identifier: start with an alpha character, followed by any number of alpha-numeric characters. I have differing results when I parse directly into a std::string versus an adapted struct containing a single std::string . If the attribute for my grammar is std::string , Qi will correctly adapt the sequence of characters into it. But with the struct, only the first character is stored. I'm not quite sure why this is. (Note that it makes no difference if the struct is

How to skip line/block/nested-block comments in Boost.Spirit?

爱⌒轻易说出口 提交于 2019-12-10 16:19:26
问题 When parsing a language using Boost.Spirit, how can I ensure that I skip // line comments /* block comments */ and /* /* nested block */ comments */ when reading in the code? At the moment, I just do a phrase_parse into a predefined qi::grammar . I guess what I need is some sort of skipping lexer, right? 回答1: No lexers required. Here's a sample grammar that implements it: Cross-platform way to get line number of an INI file where given option was found, but regardless you can use a skipper

recursive BNF rule using boost spirit

荒凉一梦 提交于 2019-12-10 15:29:33
问题 I'm trying to write a parser for the following BNF rules using boost spirit (Boost v1.64) The rules are: <numeric-literal>::= integer <type-name> ::= "in" | "out" | "in_out" <array-type-spec> ::= <type-spec> "[" [<numeric-literal>] "]" <tuple-type-spec> ::= "(" <type-spec> ("," <type-spec>)+ ")" <type-spec> ::= <type-name> | <array-type-spec> | <tuple-type-spec> Below is my attempt, using boost::make_recursive_variant It seems to work ok on the string in But it fails on in[2] . Where is my

Using simple Boost::Spirit grammars?

早过忘川 提交于 2019-12-10 13:46:37
问题 I couldn't get a grammar to work so I simplified it till it only parses an integer. Still can't get it to work. It is the following grammar: template<typename Iterator> struct rangeGrammar : qi::grammar<Iterator, int()> { rangeGrammar() : rangeGrammar::base_type(number) { using qi::int_; using qi::_1; using qi::_val; number = int_[_val = _1]; } qi::rule<Iterator, int()> number; }; It is supposed to just parse an integer (I know I could just tell the parse function to use int_ as the grammar,

Parsing imperial values using boost spirit (qi)

て烟熏妆下的殇ゞ 提交于 2019-12-08 17:51:25
I'm a spirit beginner I'd like to parse an imperial string value into a struct using spirit. The input should accept following syntaxes: 5'3"1/2 5'1/2 3"1/2 the struct imp_constant looks like this, please note stream operator below, I'll print results as this operator does: struct imp_constant { explicit imp_constant(unsigned int feet=0 ,unsigned int inch=0 ,unsigned int fracn=0 ,unsigned int fracd=1) :feet_(feet),inches_(inch),fracn_(fracn),fracd_(fracd){} unsigned int feet_,inches_,fracn_,fracd_; }; std::ostream& operator<<(std::ostream& os, imp_constant const& cst) { if (cst.feet_) os <<

128 bit string to array using boost::spirit::*

牧云@^-^@ 提交于 2019-12-08 16:27:31
I am currently starting with boost::spirit::*. I try to parse a 128 bit string into a simple c array with corresponding size. I created a short test which does the job: boost::spirit::qi::int_parser< boost::uint8_t, 16, 2, 2 > uint8_hex; std::string src( "00112233445566778899aabbccddeeff" ); boost::uint8_t dst[ 16 ]; bool r; for( std::size_t i = 0; i < 16; ++i ) { r = boost::spirit::qi::parse( src.begin( ) + 2 * i, src.begin( ) + 2 * i + 2, uint8_hex, dst[ i ] ); } I have the feeling that this is not the smartest way to do it :) Any ideas how to define a rule so I can avoid the loop ? Update:

Boost Spirit grammar eol

浪子不回头ぞ 提交于 2019-12-08 13:43:30
I am trying to parse files of the following form: // comment bla bla [sectionname] key = value key2=value2 // comment key = value [anothersection] ... using the following code. Unfortunately, it reports the last eol as an error although all eols at the end should be accepted by: (*qi::eol > -(sectionGrammar > *(+qi::eol > sectionGrammar)) > *qi::eol), Besides I really don't know how to parse comments properly without taking the eol which is required for the next key-value pair which is the reason I didn't placed in in the Skipper (only ascii::blank). The last issue I have is that I don't know