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 prefix_ senf::console::Token senf::console::NoneToken()
78 return Token(Token::None,"");
81 prefix_ senf::console::Token senf::console::PathSeparatorToken()
83 return Token(Token::PathSeparator,"/");
86 prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken()
88 return Token(Token::ArgumentGroupOpen,"(");
91 prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken()
93 return Token(Token::ArgumentGroupClose,")");
96 prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken()
98 return Token(Token::DirectoryGroupOpen,"{");
101 prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken()
103 return Token(Token::DirectoryGroupClose,"}");
106 prefix_ senf::console::Token senf::console::CommandTerminatorToken()
108 return Token(Token::CommandTerminator,";");
111 prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value)
113 return Token(Token::OtherPunctuation, value);
116 prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value)
118 return Token(Token::BasicString, value);
121 prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value)
123 return Token(Token::HexString, value);
126 prefix_ senf::console::Token senf::console::WordToken(std::string const & value)
128 return Token(Token::Word, value);
131 ///////////////////////////////////////////////////////////////////////////
132 // senf::console::ParseCommandInfo
134 prefix_ senf::console::ParseCommandInfo::ParseCommandInfo()
135 : builtin_ (NoBuiltin)
138 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
139 senf::console::ParseCommandInfo::builtin()
145 prefix_ senf::console::ParseCommandInfo::TokensRange
146 senf::console::ParseCommandInfo::commandPath()
149 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
152 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
153 senf::console::ParseCommandInfo::arguments()
156 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
157 ArgumentIterator(tokens_.end()) );
160 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
163 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
166 prefix_ void senf::console::ParseCommandInfo::clear()
168 builtin_ = NoBuiltin;
169 commandPath_.clear();
173 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
176 commandPath_.clear();
180 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
182 commandPath_.clear();
183 commandPath_.swap(commandPath);
184 builtin_ = NoBuiltin;
187 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
189 tokens_.push_back(token);
192 ///////////////////////////////////////////////////////////////////////////
193 // senf::console::ParseCommandInfo::ArgumentIterator
195 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
198 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
199 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
203 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
204 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
207 if (b_ == e_) setRange();
208 return b_->is(Token::ArgumentGroupOpen)
209 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
210 : boost::make_iterator_range(b_, e_);
214 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
217 return b_ == other.b_;
220 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
222 if (b_ == e_) setRange();
226 ///////////////////////////////////////////////////////////////////////////
227 // senf::console::SyntaxErrorException
229 prefix_ senf::console::SyntaxErrorException::SyntaxErrorException(std::string const & msg)
233 prefix_ senf::console::SyntaxErrorException::~SyntaxErrorException()
237 prefix_ std::string const & senf::console::SyntaxErrorException::message()
243 ///////////////////////////////////////////////////////////////////////////
245 prefix_ senf::console::CheckedArgumentIteratorWrapper::
246 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
247 std::string const & msg)
248 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
251 prefix_ senf::console::CheckedArgumentIteratorWrapper::
252 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
253 std::string const & msg)
254 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
257 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
259 if (i_ != e_ && ! std::uncaught_exception())
260 throw SyntaxErrorException(msg_);
263 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
268 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
274 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
280 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
285 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
286 senf::console::CheckedArgumentIteratorWrapper::dereference()
290 throw SyntaxErrorException(msg_);
294 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
297 throw SyntaxErrorException(msg_);
301 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
302 operator==(ParseCommandInfo::ArgumentIterator const & other)
308 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
309 operator!=(ParseCommandInfo::ArgumentIterator const & other)
315 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
316 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
318 ParseCommandInfo::ArgumentIterator i (i_);
323 ///////////////////////////////////////////////////////////////////////////
324 // senf::console::SingleCommandParser
326 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
332 ///////////////////////////////cci.e///////////////////////////////////////
339 // comment-column: 40
340 // c-file-style: "senf"
341 // indent-tabs-mode: nil
342 // ispell-local-dictionary: "american"
343 // compile-command: "scons -u test"