4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Parse public header */
32 #include <boost/utility.hpp>
33 #include <boost/scoped_ptr.hpp>
34 #include <boost/range/iterator_range.hpp>
35 #include <boost/function.hpp>
37 //#include "Parse.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
43 namespace detail { struct ParserAccess; }
50 std::string const & value() const;
55 explicit ArgumentToken(std::string token);
59 friend class detail::ParserAccess;
65 class ParseCommandInfo
67 typedef std::vector<ArgumentToken> Tokens;
68 typedef std::vector<std::string> CommandPath;
71 typedef CommandPath::const_iterator path_iterator;
72 typedef Tokens::const_iterator token_iterator;
73 typedef boost::iterator_range<token_iterator> argument_value_type;
77 typedef std::vector<argument_value_type> Arguments;
80 typedef Arguments::const_iterator argument_iterator;
81 typedef Arguments::size_type size_type;
83 typedef boost::iterator_range<path_iterator> CommandPathRange;
84 typedef boost::iterator_range<argument_iterator> ArgumentsRange;
85 typedef boost::iterator_range<token_iterator> TokensRange;
87 enum BuiltinCommand { NoBuiltin,
95 BuiltinCommand builtin() const;
96 CommandPathRange commandPath() const;
97 ArgumentsRange arguments() const;
98 TokensRange tokens() const;
104 void setBuiltin(BuiltinCommand builtin);
105 void setCommand(std::vector<std::string> & commandPath);
106 void startArgument();
108 void addToken(ArgumentToken const & token);
113 std::vector<std::string> commandPath_;
115 typedef std::pair<Tokens::size_type, Tokens::size_type> TempArgumentRange;
116 typedef std::vector<TempArgumentRange> TempArguments;
118 BuiltinCommand builtin_;
120 Arguments arguments_;
121 TempArguments tempArguments_;
123 friend class detail::ParserAccess;
126 std::ostream & operator<<(std::ostream & stream, ParseCommandInfo const & info);
134 ///////////////////////////////////////////////////////////////////////////
137 typedef boost::function<void (ParseCommandInfo const &)> Callback;
139 ///////////////////////////////////////////////////////////////////////////
140 ///\name Structors and default members
147 ///////////////////////////////////////////////////////////////////////////
149 bool parse(std::string command, Callback cb);
150 bool parseFile(std::string filename, Callback cb);
157 boost::scoped_ptr<Impl> impl_;
162 ///////////////////////////////hh.e////////////////////////////////////////
164 //#include "Parse.ct"
165 //#include "Parse.cti"
172 // comment-column: 40
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"