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 inline non-template implementation */
26 // We do NOT want to include the complete parser definition into every other compilation unit
27 // (disabled) #include "Parse.ih"
30 #include "../Utils/senfassert.hh"
32 #define prefix_ inline
33 ///////////////////////////////cci.p///////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::console::ArgumentToken
38 prefix_ std::string const & senf::console::ArgumentToken::value()
44 prefix_ senf::console::ArgumentToken::TokenType senf::console::ArgumentToken::type()
50 prefix_ bool senf::console::ArgumentToken::is(unsigned tokens)
53 return tokens & type_;
56 prefix_ senf::console::ArgumentToken::ArgumentToken(TokenType type, std::string token)
57 : type_(type), token_ (token)
60 ///////////////////////////////////////////////////////////////////////////
61 // senf::console::ParseCommandInfo
63 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
64 senf::console::ParseCommandInfo::builtin()
70 prefix_ senf::console::ParseCommandInfo::CommandPathRange
71 senf::console::ParseCommandInfo::commandPath()
74 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
77 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
78 senf::console::ParseCommandInfo::arguments()
81 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
82 ArgumentIterator(tokens_.end()) );
85 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
88 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
91 ////////////////////////////////////////
94 prefix_ void senf::console::ParseCommandInfo::init()
101 prefix_ void senf::console::ParseCommandInfo::setBuiltin(BuiltinCommand builtin)
107 senf::console::ParseCommandInfo::setCommand(std::vector<std::string> & commandPath)
109 commandPath_.clear();
110 commandPath_.swap(commandPath);
113 prefix_ void senf::console::ParseCommandInfo::addToken(ArgumentToken const & token)
115 tokens_.push_back(token);
118 ///////////////////////////////////////////////////////////////////////////
119 // senf::console::ParseCommandInfo::ArgumentIterator
121 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
124 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
125 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
129 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
130 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
133 if (b_ == e_) setRange();
134 return b_->is(ArgumentToken::ArgumentGroupOpen)
135 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
136 : boost::make_iterator_range(b_, e_);
140 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
143 return b_ == other.b_;
146 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
148 if (b_ == e_) setRange();
152 ///////////////////////////////////////////////////////////////////////////
154 prefix_ senf::console::CheckedArgumentIteratorWrapper::
155 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
156 std::string const & msg)
157 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
160 prefix_ senf::console::CheckedArgumentIteratorWrapper::
161 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
162 std::string const & msg)
163 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
166 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
168 if (i_ != e_ && ! std::uncaught_exception())
169 throw SyntaxErrorException(msg_);
172 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
177 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
183 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
189 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
194 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
195 senf::console::CheckedArgumentIteratorWrapper::dereference()
199 throw SyntaxErrorException(msg_);
203 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
206 throw SyntaxErrorException(msg_);
210 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
211 operator==(ParseCommandInfo::ArgumentIterator const & other)
217 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
218 operator!=(ParseCommandInfo::ArgumentIterator const & other)
224 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
225 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
227 ParseCommandInfo::ArgumentIterator i (i_);
232 ///////////////////////////////////////////////////////////////////////////
233 // senf::console::SingleCommandParser
235 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
241 ///////////////////////////////cci.e///////////////////////////////////////
248 // comment-column: 40
249 // c-file-style: "senf"
250 // indent-tabs-mode: nil
251 // ispell-local-dictionary: "american"
252 // compile-command: "scons -u test"