]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/example/lex/static_lexer/word_count_lexer_generate.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / example / lex / static_lexer / word_count_lexer_generate.cpp
CommitLineData
7c673cae
FG
1// Copyright (c) 2001-2010 Hartmut Kaiser
2//
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// The purpose of this example is to show, how it is possible to use a lexer
7// token definition for two purposes:
8//
9// . To generate C++ code implementing a static lexical analyzer allowing
10// to recognize all defined tokens (this file)
11// . To integrate the generated C++ lexer into the /Spirit/ framework.
12// (see the file: word_count_lexer_static.cpp)
13
14// #define BOOST_SPIRIT_LEXERTL_DEBUG
15
7c673cae
FG
16#include <boost/spirit/include/lex_lexertl.hpp>
17#include <boost/spirit/include/lex_generate_static_lexertl.hpp>
18
19#include <fstream>
20
21#include "word_count_lexer_tokens.hpp"
22
23using namespace boost::spirit;
24
25///////////////////////////////////////////////////////////////////////////////
26//[wcl_static_generate_main
27int main(int argc, char* argv[])
28{
29 // create the lexer object instance needed to invoke the generator
30 word_count_lexer_tokens<lex::lexertl::actor_lexer<> > word_count; // the token definition
31
32 // open the output file, where the generated tokenizer function will be
33 // written to
34 std::ofstream out(argc < 2 ? "word_count_lexer_static.hpp" : argv[1]);
35
36 // invoke the generator, passing the token definition, the output stream
37 // and the name prefix of the tokenizing function to be generated
38 //
39 // The suffix "wcl" used below results in a type lexertl::static_::lexer_wcl
40 // to be generated, which needs to be passed as a template parameter to the
41 // lexertl::static_lexer template (see word_count_lexer_static.cpp).
42 return lex::lexertl::generate_static_dfa(word_count, out, "wcl") ? 0 : -1;
43}
44//]