boost-spirit

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>

Parse time_period expression with Boost::Spirit

人盡茶涼 提交于 2019-12-10 17:48:43
问题 I need to parse following EBNF expression with Boost::Spirit. period ::= date_part [time_part] , date_part [time_part] time_part ::= hours:minutes[:seconds] date_part ::= day.month.year For example, 10.06.2014 10:00:15, 11.07.2014 . I made my grammar in two ways, but can't exactly get working example. 1) First attempt struct Parser: grammar<std::string::const_iterator, space_type> { Parser(): Parser::base_type(datetime_) { using boost::spirit::int_; using boost::spirit::qi::_1; using boost:

How do I grok boost spirit compiler errors

你离开我真会死。 提交于 2019-12-10 17:21:57
问题 I am trying to use the no_skip directive to parse input of the form: state PASS <tab> state FAIL I am using ascii::blank as my skipper. I get an compile error when I wrap no_skip[ trans_assign_expr ] to parse for the tab. How do I fix this error, and in general, how do I understand these errors so that I can fix future ones? The boost spirit documentation never covers this aspect of using spirit :( This is the error In file included from /usr/include/boost/spirit/home/qi/nonterminal/grammar

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

build error with boost spirit grammar (boost 1.43 and g++ 4.4.1) part II

空扰寡人 提交于 2019-12-10 17:19:00
问题 I'm having issues getting a small spirit/qi grammar to compile. i am using boost 1.43 and g++ 4.4.1. the input grammar header: the build error seems to be pointing to the definition of the 'instruction' rule, maybe it is the '[sp::_val = sp::_1]' that somehow brokes it but this is more or less based on what the spirit documentation tutorials are doing with the xml node parser inputGrammar.h #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost

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

Using Boost.Spirit.Lex and stream iterators

六月ゝ 毕业季﹏ 提交于 2019-12-10 15:16:21
问题 I want use Boost.Spirit.Lex to lex a binary file; for this purpose I wrote the following program (here is an extract): #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/support_multi_pass.hpp> #include <boost/bind.hpp> #include <boost/ref.hpp> #include <fstream> #include <iterator> #include <string> namespace spirit = boost::spirit; namespace lex = spirit::lex; #define X 1 #define Y 2 #define Z 3 template<typename L> class word_count_tokens : public lex::lexer<L>

Boost Spirit X3: “Attribute does not have the expected size,” but why does it care?

半腔热情 提交于 2019-12-10 14:23:04
问题 I am trying to write a parser with Spirit X3, but I haven't gotten very far because I'm running into a compilation error that I can't figure out. I think I know what the compiler is complaining about, but what I don't understand is why it cares. The following code compiles (clang 3.9, Boost 1.62.0) and works. (I realize it's structured poorly and that there are built-in parsers for constants; I'm just trying to demonstrate the issue.) #define BOOST_SPIRIT_X3_DEBUG #include <iostream> #include

How do I implement include directives using boost::spirit::lex?

旧时模样 提交于 2019-12-10 13:22:10
问题 I have a simple configuration file parser built from spirit::lex and spirit::qi. When the lexer reaches the pattern include "path" I want the text of the file to be included. As you may know, spirit::lexer::begin() starts the scanning process: // Read file contents into a std::string ... // _first and _last are const char* _first = _contents.c_str(); _last = &_first[_input.size()]; // _token is a lexer::iterator_type for the current token _token = _lexer.begin(_first, _last); My idea is to