1 | /*============================================================================= |
---|
2 | Copyright (c) 2001-2003 Daniel Nuffer |
---|
3 | Copyright (c) 2001-2003 Hartmut Kaiser |
---|
4 | http://spirit.sourceforge.net/ |
---|
5 | |
---|
6 | Use, modification and distribution is subject to the Boost Software |
---|
7 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
8 | http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | =============================================================================*/ |
---|
10 | |
---|
11 | #if !defined(TREE_TO_XML_HPP) |
---|
12 | #define TREE_TO_XML_HPP |
---|
13 | |
---|
14 | namespace boost { namespace spirit { |
---|
15 | |
---|
16 | namespace impl { |
---|
17 | template <typename CharT> struct default_string; |
---|
18 | } |
---|
19 | |
---|
20 | /////////////////////////////////////////////////////////////////////////////// |
---|
21 | // |
---|
22 | // Dump a parse tree as a xml stream |
---|
23 | // |
---|
24 | // The functions 'tree_to_xml' can be used to output a parse tree as a xml |
---|
25 | // stream into the given ostream. The parameters have the following |
---|
26 | // meaning: |
---|
27 | // |
---|
28 | // mandatory parameters: |
---|
29 | // ostrm The output stream used for streaming the parse tree. |
---|
30 | // tree The parse tree to output. |
---|
31 | // |
---|
32 | // optional parameters: |
---|
33 | // input_line The input line from which the parse tree was |
---|
34 | // generated (if given, it is used to output a comment |
---|
35 | // containing this line). |
---|
36 | // id_to_name A map, which is used for converting the rule id's contained |
---|
37 | // in the parse tree to readable strings. Here a auxiliary |
---|
38 | // associative container can be used, which maps a rule_id to |
---|
39 | // a std::string (i.e. a std::map<rule_id, std::string>). |
---|
40 | // get_token_id |
---|
41 | // A function or functor, which takes an instance of a token |
---|
42 | // and which should return a token id (i.e. something like |
---|
43 | // 'int f(char const c)'). |
---|
44 | // get_token_value |
---|
45 | // A function or functor, which takes an instance of a token |
---|
46 | // and which should return a readable representation of this |
---|
47 | // token (i.e. something like 'std::string f(char const c)'). |
---|
48 | // |
---|
49 | // The structure of the generated xml stream conforms to the DTD given in the |
---|
50 | // file 'parsetree.dtd'. This file is located in the spirit/tree directory. |
---|
51 | // |
---|
52 | /////////////////////////////////////////////////////////////////////////////// |
---|
53 | |
---|
54 | template < |
---|
55 | typename CharT, typename TreeNodeT, typename AssocContainerT, |
---|
56 | typename GetIdT, typename GetValueT |
---|
57 | > |
---|
58 | inline void |
---|
59 | basic_tree_to_xml (std::basic_ostream<CharT> &ostrm, TreeNodeT const &tree, |
---|
60 | std::basic_string<CharT> const &input_line, |
---|
61 | AssocContainerT const& id_to_name, GetIdT const &get_token_id, |
---|
62 | GetValueT const &get_token_value); |
---|
63 | |
---|
64 | template <typename CharT, typename TreeNodeT, typename AssocContainerT> |
---|
65 | inline void |
---|
66 | basic_tree_to_xml (std::basic_ostream<CharT> &ostrm, TreeNodeT const &tree, |
---|
67 | std::basic_string<CharT> const &input_line, |
---|
68 | AssocContainerT const& id_to_name); |
---|
69 | |
---|
70 | template <typename CharT, typename TreeNodeT> |
---|
71 | inline void |
---|
72 | basic_tree_to_xml (std::basic_ostream<CharT> &ostrm, TreeNodeT const &tree, |
---|
73 | std::basic_string<CharT> const &input_line = |
---|
74 | impl::default_string<CharT>::get()); |
---|
75 | |
---|
76 | /////////////////////////////////////////////////////////////////////////// |
---|
77 | template < |
---|
78 | typename TreeNodeT, typename AssocContainerT, |
---|
79 | typename GetIdT, typename GetValueT |
---|
80 | > |
---|
81 | inline void |
---|
82 | tree_to_xml (std::ostream &ostrm, TreeNodeT const &tree, |
---|
83 | std::string const &input_line, AssocContainerT const& id_to_name, |
---|
84 | GetIdT const &get_token_id, GetValueT const &get_token_value) |
---|
85 | { |
---|
86 | basic_tree_to_xml<char>(ostrm, tree, input_line, id_to_name, |
---|
87 | get_token_id, get_token_value); |
---|
88 | } |
---|
89 | |
---|
90 | template <typename TreeNodeT, typename AssocContainerT> |
---|
91 | inline void |
---|
92 | tree_to_xml (std::ostream &ostrm, TreeNodeT const &tree, |
---|
93 | std::string const &input_line, AssocContainerT const& id_to_name) |
---|
94 | { |
---|
95 | basic_tree_to_xml<char>(ostrm, tree, input_line, id_to_name); |
---|
96 | } |
---|
97 | |
---|
98 | template <typename TreeNodeT> |
---|
99 | inline void |
---|
100 | tree_to_xml (std::ostream &ostrm, TreeNodeT const &tree, |
---|
101 | std::string const &input_line = "") |
---|
102 | { |
---|
103 | basic_tree_to_xml<char>(ostrm, tree, input_line); |
---|
104 | } |
---|
105 | |
---|
106 | }} // namespace boost::spirit |
---|
107 | |
---|
108 | #include <boost/spirit/tree/impl/tree_to_xml.ipp> |
---|
109 | |
---|
110 | #endif // !defined(TREE_TO_XML_HPP) |
---|
111 | |
---|