boost-spirit-lex

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

how to get rid of escape character in a token with spirit::lex?

独自空忆成欢 提交于 2019-12-06 10:01:24
问题 I want to tokenize my own extension of SQL syntax. This involves recognizing an escaped double quote inside a double quoted string. E.g. in MySQL these two string tokens are equivalent: """" (the second double quote acts as an escape character) and '"' . I have tried different things but I am stuck at how to replace a token's value. #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct sql_tokens : lex::lexer<Lexer> { sql_tokens()

Is there a way to match the content of a spirit::lex string token as a literal in a spirit::qi grammar

对着背影说爱祢 提交于 2019-12-05 20:49:34
I'm writing a DSL and using a Boost Spirit lexer to tokenize my input. In my grammar, I want a rule similar to this (where tok is the lexer): header_block = tok.name >> ':' >> tok.stringval > ';' >> tok.description >> ':' >> tok.stringval > ';' ; Rather than specifying reserved words for the language (e.g. "name", "description") and deal with synchronizing these between the lexer and grammar, I want to just tokenize everything that matches [a-zA-Z_]\w* as a single token type (e.g. tok.symbol ), and let the grammar sort it out. If I weren't using a lexer, I might do something like this:

Boost spirit lex write token value back to input stream

橙三吉。 提交于 2019-12-05 20:01:21
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! 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(' Parsed as: '(abc' Input '(abc' Parsed as: '(abc' Code #include <boost/spirit/include/qi.hpp> #include <boost

I can't get the string value of a token

╄→гoц情女王★ 提交于 2019-12-04 18:32:20
问题 I try to implement a Lexer for a little programming language with Boost Spirit. I have to get the value of a token and I get a bad_get exception : terminate called after throwing an instance of 'boost::bad_get' what(): boost::bad_get: failed value get using boost::get Aborted I obtain this exception when doing : std::string contents = "void"; base_iterator_type first = contents.begin(); base_iterator_type last = contents.end(); SimpleLexer<lexer_type> lexer; iter = lexer.begin(first, last);

how to get rid of escape character in a token with spirit::lex?

妖精的绣舞 提交于 2019-12-04 14:23:53
I want to tokenize my own extension of SQL syntax. This involves recognizing an escaped double quote inside a double quoted string. E.g. in MySQL these two string tokens are equivalent: """" (the second double quote acts as an escape character) and '"' . I have tried different things but I am stuck at how to replace a token's value. #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct sql_tokens : lex::lexer<Lexer> { sql_tokens() { string_quote_double = "\\\""; // '"' this->self("INITIAL") = string_quote_double [ lex::_state =

I can't get the string value of a token

不问归期 提交于 2019-12-03 11:57:10
I try to implement a Lexer for a little programming language with Boost Spirit. I have to get the value of a token and I get a bad_get exception : terminate called after throwing an instance of 'boost::bad_get' what(): boost::bad_get: failed value get using boost::get Aborted I obtain this exception when doing : std::string contents = "void"; base_iterator_type first = contents.begin(); base_iterator_type last = contents.end(); SimpleLexer<lexer_type> lexer; iter = lexer.begin(first, last); end = lexer.end(); std::cout << "Value = " << boost::get<std::string>(iter->value()) << std::endl; My

How to make Boost.Spirit.Lex token value be a substring of matched sequence (preferably by regex matching group)

爱⌒轻易说出口 提交于 2019-12-01 09:43:03
I'm writing a simple expressions parser. It is build on a Boost.Spirit.Qi grammar based on Boost.Spirit.Lex tokens (Boost in version 1.56). The tokens are defined as follows: using namespace boost::spirit; template< typename lexer_t > struct tokens : lex::lexer<lexer_t> { tokens() : /* ... */, variable("%(\\w+)") { this->self = /* ... */ | variable; } /* ... */ lex::token_def<std::string> variable; }; Now I would like the variable token value to be just the name (the matching group (\\w+) ) without prefix % symbol. How do I do that? Using a matching group by itself doesn't help. Still value is

cannot get boost::spirit parser&lexer working for token types other than std::string or int or double

。_饼干妹妹 提交于 2019-12-01 09:27:07
This does not compile (code below). There was another question here with the same error. But I don't understand the answer. I already tried inserting qi::eps in places -- but without success. I also tried already adding meta functions (boost::spirit::raits::is_container) for the types used -- but this also does not help. I also tried using the same variant containing all types I need to use everywhere. Same problem. Has anybody gotten this working for a lexer returning something else than double or int or string? And for the parser also returning non-trivial objects? I've tried implementing

How to make Boost.Spirit.Lex token value be a substring of matched sequence (preferably by regex matching group)

不羁岁月 提交于 2019-12-01 08:07:47
问题 I'm writing a simple expressions parser. It is build on a Boost.Spirit.Qi grammar based on Boost.Spirit.Lex tokens (Boost in version 1.56). The tokens are defined as follows: using namespace boost::spirit; template< typename lexer_t > struct tokens : lex::lexer<lexer_t> { tokens() : /* ... */, variable("%(\\w+)") { this->self = /* ... */ | variable; } /* ... */ lex::token_def<std::string> variable; }; Now I would like the variable token value to be just the name (the matching group (\\w+) )