1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #include <boost/spirit/include/lex_lexertl.hpp>
11 ///////////////////////////////////////////////////////////////////////////////
12 // a simple lexer class
13 template <typename Lexer
>
15 : boost::spirit::lex::lexer
<Lexer
>
17 typedef boost::spirit::lex::token_def
<std::string
> token_def
;
19 static std::size_t const CCOMMENT
= 1;
20 static std::size_t const CPPCOMMENT
= 2;
23 : c_comment("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT
)
24 , cpp_comment("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT
)
26 this->self
= c_comment
;
27 this->self
+= cpp_comment
;
30 token_def c_comment
, cpp_comment
;
33 template <typename Lexer
>
35 : boost::spirit::lex::lexer
<Lexer
>
37 typedef boost::spirit::lex::token_def
<std::basic_string
<wchar_t>, wchar_t>
40 static std::size_t const CCOMMENT
= 1;
41 static std::size_t const CPPCOMMENT
= 2;
44 : c_comment(L
"\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT
)
45 , cpp_comment(L
"\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT
)
47 this->self
= c_comment
;
48 this->self
+= cpp_comment
;
51 token_def c_comment
, cpp_comment
;
54 ///////////////////////////////////////////////////////////////////////////////
57 using namespace boost::spirit
;
58 using namespace spirit_test
;
60 // the following test aims at the low level lexer_ and token_ objects,
61 // normally not visible/used by the user
64 typedef std::string::iterator base_iterator_type
;
65 typedef lex::lexertl::token
<base_iterator_type
> token_type
;
66 typedef lex::lexertl::lexer
<token_type
> lexer_type
;
67 typedef lexertl_test
<lexer_type
> lexer_def
;
69 // test lexer for two different input strings
71 BOOST_TEST(test (lex
, "/* this is a comment */", lexer_def::CCOMMENT
));
72 BOOST_TEST(test (lex
, "// this is a comment as well\n", lexer_def::CPPCOMMENT
));
77 typedef std::basic_string
<wchar_t>::iterator base_iterator_type
;
78 typedef lex::lexertl::token
<base_iterator_type
> token_type
;
79 typedef lex::lexertl::lexer
<token_type
> lexer_type
;
80 typedef wlexertl_test
<lexer_type
> lexer_def
;
82 // test lexer for two different input strings
84 BOOST_TEST(test (lex
, L
"/* this is a comment */", lexer_def::CCOMMENT
));
85 BOOST_TEST(test (lex
, L
"// this is a comment as well\n", lexer_def::CPPCOMMENT
));
88 return boost::report_errors();