boost-spirit-lex

Spirit Lex: Which token definition generated this token?

时光怂恿深爱的人放手 提交于 2019-11-30 23:36:06
Sorry if this is a newbie question, but I need to know which token definition produced a certain token. When I print the token ID, I just get an integer. I need to know which regex generated this token. Edit: Here's how I define my tokens: template <typename LexerT> class Tokens: public lex::lexer<LexerT> { public: Tokens(const std::string& input): lineNo_(1) { using boost::spirit::lex::_start; using boost::spirit::lex::_end; using boost::spirit::lex::_pass; using boost::phoenix::ref; using boost::phoenix::construct; // macros this->self.add_pattern ("EXP", "(e|E)(\\+|-)?\\d+") ("SUFFIX", "

Boost Spirit Signals Successful Parsing Despite Token Being Incomplete

谁说我不能喝 提交于 2019-11-29 14:50:11
I have a very simple path construct that I am trying to parse with boost spirit.lex. We have the following grammar: token := [a-z]+ path := (token : path) | (token) So we're just talking about colon separated lower-case ASCII strings here. I have three examples "xyz", "abc:xyz", "abc:xyz:". The first two should be deemed valid. The third one, which has a trailing colon, should not be deemed valid. Unfortunately the parser I have recognizes all three as being valid. The grammar should not allow an empty token, but apparently spirit is doing just that. What am I missing to get the third one

Using lexer token attributes in grammar rules with Lex and Qi from Boost.Spirit

强颜欢笑 提交于 2019-11-29 07:57:17
Let's consider following code: #include <boost/phoenix.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/qi.hpp> #include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> namespace lex = boost::spirit::lex; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; struct operation { enum type { add, sub, mul, div }; }; template<typename Lexer> class expression_lexer : public lex::lexer<Lexer> { public: typedef lex::token_def<operation::type> operator_token_type; typedef lex::token_def<double> value_token_type;

Whitespace skipper when using Boost.Spirit Qi and Lex

我的未来我决定 提交于 2019-11-28 09:08:04
问题 Let's consider following code: #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/qi.hpp> #include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> namespace lex = boost::spirit::lex; namespace qi = boost::spirit::qi; template<typename Lexer> class expression_lexer : public lex::lexer<Lexer> { public: typedef lex::token_def<> operator_token_type; typedef lex::token_def<> value_token_type; typedef lex::token_def<> variable_token

Boost Spirit Signals Successful Parsing Despite Token Being Incomplete

一世执手 提交于 2019-11-28 08:55:00
问题 I have a very simple path construct that I am trying to parse with boost spirit.lex. We have the following grammar: token := [a-z]+ path := (token : path) | (token) So we're just talking about colon separated lower-case ASCII strings here. I have three examples "xyz", "abc:xyz", "abc:xyz:". The first two should be deemed valid. The third one, which has a trailing colon, should not be deemed valid. Unfortunately the parser I have recognizes all three as being valid. The grammar should not

Cannot get Boost Spirit grammar to use known keys for std::map<>

梦想的初衷 提交于 2019-11-28 06:26:04
问题 I seem to be experiencing some mental block with Boost Spirit I just cannot get by. I have a fairly simple grammar I need to handle, where I would like to put the values into a struct, that contains a std::map<> as one of it's members. The key names for the pairs are known up front, so that only those are allowed. There could be one to many keys in the map, in any order with each key name validated via qi. The grammar looks something like this, as an example. test .|*|<hostname> add|modify

Using lexer token attributes in grammar rules with Lex and Qi from Boost.Spirit

 ̄綄美尐妖づ 提交于 2019-11-28 01:25:59
问题 Let's consider following code: #include <boost/phoenix.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/qi.hpp> #include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> namespace lex = boost::spirit::lex; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; struct operation { enum type { add, sub, mul, div }; }; template<typename Lexer> class expression_lexer : public lex::lexer<Lexer> { public: typedef

How to benchmark Boost Spirit Parser?

拥有回忆 提交于 2019-11-27 21:21:12
I'm working on a compiler and I would like to improve its performances. I found that about 50% of the time is spent parsing the source files. As the source file are quite small and I do quite a lot of transformations after that, it seems to me that it is perfectible. My parser is a Boost Spirit parser with a lexer (with lexer::pos_iterator) and I have a middle sized grammar. I'm parsing the source into an AST. My problem is that I have no idea what takes the most time during the parsing: copies of AST nodes, lexer, parser rules or memory. I don't think that it is I/O problem since I'm working

Troubles with boost::spirit::lex & whitespace

久未见 提交于 2019-11-27 15:42:27
I try learning to use boost::spirit. To do that, I wanted to create some simple lexer, combine them and then start parsing using spirit. I tried modifying the example, but it doesn't run as expected (the result r isn't true). Here's the lexer: #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct lexer_identifier : lex::lexer<Lexer> { lexer_identifier() : identifier("[a-zA-Z_][a-zA-Z0-9_]*") , white_space("[ \\t\\n]+") { using boost::spirit::lex::_start; using boost::spirit::lex::_end; this->self = identifier; this->self("WS") =

Troubles with boost::spirit::lex & whitespace

。_饼干妹妹 提交于 2019-11-26 17:16:22
问题 I try learning to use boost::spirit. To do that, I wanted to create some simple lexer, combine them and then start parsing using spirit. I tried modifying the example, but it doesn't run as expected (the result r isn't true). Here's the lexer: #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct lexer_identifier : lex::lexer<Lexer> { lexer_identifier() : identifier("[a-zA-Z_][a-zA-Z0-9_]*") , white_space("[ \\t\\n]+") { using