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::Token
38 prefix_ std::string const & senf::console::Token::value()
44 prefix_ senf::console::Token::TokenType senf::console::Token::type()
50 prefix_ bool senf::console::Token::is(unsigned tokens)
53 return tokens & type_;
56 prefix_ bool senf::console::Token::operator==(Token const & other)
59 return type() == other.type() && value() == other.value();
62 prefix_ bool senf::console::Token::operator!=(Token const & other)
65 return ! operator==(other);
68 prefix_ senf::console::Token::Token()
69 : type_(None), token_()
72 prefix_ senf::console::Token::Token(TokenType type, std::string token)
73 : type_(type), token_ (token)
76 ///////////////////////////////////////////////////////////////////////////
77 // senf::console::ParseCommandInfo
79 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
80 senf::console::ParseCommandInfo::builtin()
86 prefix_ senf::console::ParseCommandInfo::TokensRange
87 senf::console::ParseCommandInfo::commandPath()
90 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
93 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
94 senf::console::ParseCommandInfo::arguments()
97 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
98 ArgumentIterator(tokens_.end()) );
101 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
104 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
107 ////////////////////////////////////////
110 prefix_ void senf::console::ParseCommandInfo::init()
112 builtin_ = NoBuiltin;
113 commandPath_.clear();
117 prefix_ void senf::console::ParseCommandInfo::setBuiltin(BuiltinCommand builtin)
123 senf::console::ParseCommandInfo::setCommand(std::vector<Token> & commandPath)
125 commandPath_.clear();
126 commandPath_.swap(commandPath);
129 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
131 tokens_.push_back(token);
134 ///////////////////////////////////////////////////////////////////////////
135 // senf::console::ParseCommandInfo::ArgumentIterator
137 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
140 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
141 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
145 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
146 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
149 if (b_ == e_) setRange();
150 return b_->is(Token::ArgumentGroupOpen)
151 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
152 : boost::make_iterator_range(b_, e_);
156 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
159 return b_ == other.b_;
162 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
164 if (b_ == e_) setRange();
168 ///////////////////////////////////////////////////////////////////////////
170 prefix_ senf::console::CheckedArgumentIteratorWrapper::
171 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
172 std::string const & msg)
173 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
176 prefix_ senf::console::CheckedArgumentIteratorWrapper::
177 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
178 std::string const & msg)
179 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
182 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
184 if (i_ != e_ && ! std::uncaught_exception())
185 throw SyntaxErrorException(msg_);
188 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
193 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
199 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
205 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
210 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
211 senf::console::CheckedArgumentIteratorWrapper::dereference()
215 throw SyntaxErrorException(msg_);
219 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
222 throw SyntaxErrorException(msg_);
226 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
227 operator==(ParseCommandInfo::ArgumentIterator const & other)
233 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
234 operator!=(ParseCommandInfo::ArgumentIterator const & other)
240 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
241 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
243 ParseCommandInfo::ArgumentIterator i (i_);
248 ///////////////////////////////////////////////////////////////////////////
249 // senf::console::SingleCommandParser
251 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
257 ///////////////////////////////cci.e///////////////////////////////////////
264 // comment-column: 40
265 // c-file-style: "senf"
266 // indent-tabs-mode: nil
267 // ispell-local-dictionary: "american"
268 // compile-command: "scons -u test"