]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/lex/plain_token.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / spirit / test / lex / plain_token.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2016 Jeffrey E. Trull
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // #define BOOST_SPIRIT_LEXERTL_DEBUG
7 #define BOOST_VARIANT_MINIMIZE_SIZE
8
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/config/warning_disable.hpp>
11
12 #include <boost/spirit/include/qi.hpp>
13 #include <boost/spirit/include/lex_lexertl.hpp>
14
15 #include <string>
16
17 namespace qi = boost::spirit::qi;
18 namespace lex = boost::spirit::lex;
19
20 enum tokenids
21 {
22 // left tokens
23 IDLPAREN = lex::min_token_id,
24 IDLANGLE,
25 IDLBRACE,
26 IDLSQUARE,
27 // right tokens
28 IDRPAREN,
29 IDRANGLE,
30 IDRBRACE,
31 IDRSQUARE,
32 IDANY
33 };
34
35 template <typename Lexer>
36 struct delimiter_tokens : lex::lexer<Lexer>
37 {
38 delimiter_tokens()
39 {
40 this->self =
41 lex::char_('(', IDLPAREN)
42 | lex::char_(')', IDRPAREN)
43 | lex::char_('<', IDLANGLE)
44 | lex::char_('>', IDRANGLE)
45 | lex::char_('{', IDLBRACE)
46 | lex::char_('}', IDRBRACE)
47 | lex::char_('[', IDLSQUARE)
48 | lex::char_(']', IDRSQUARE)
49 | lex::string(".", IDANY)
50 ;
51 }
52 };
53
54 int main()
55 {
56 typedef lex::lexertl::token<
57 std::string::iterator, boost::mpl::vector<std::string>
58 > token_type;
59
60 typedef lex::lexertl::lexer<token_type> lexer_type;
61 delimiter_tokens<lexer_type> delims;
62
63 // two test cases for the token range
64 std::string angled_delimiter_str("<canvas>");
65
66 using qi::token;
67 // angle brackets
68 std::string::iterator beg = angled_delimiter_str.begin();
69 BOOST_TEST(lex::tokenize_and_parse(
70 beg, angled_delimiter_str.end(),
71 delims,
72 token(IDLPAREN, IDLSQUARE)
73 >> +token(IDANY)
74 >> token(IDRPAREN, IDRSQUARE)));
75
76 std::string paren_delimiter_str("(setq foo nil)");
77 beg = paren_delimiter_str.begin();
78 BOOST_TEST(lex::tokenize_and_parse(
79 beg, paren_delimiter_str.end(),
80 delims,
81 token(IDLPAREN, IDLSQUARE)
82 >> +token(IDANY)
83 >> token(IDRPAREN, IDRSQUARE)));
84
85 // reset and use a regular plain token
86 beg = paren_delimiter_str.begin();
87 BOOST_TEST(lex::tokenize_and_parse(
88 beg, paren_delimiter_str.end(),
89 delims,
90 token(IDLPAREN) >> +token(IDANY) >> token(IDRPAREN)));
91
92 return boost::report_errors();
93 }