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_ bool senf::console::ParseCommandInfo::empty()
175 return builtin_ == NoBuiltin && commandPath_.empty();
178 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
181 commandPath_.clear();
185 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
187 commandPath_.clear();
188 commandPath_.swap(commandPath);
189 builtin_ = NoBuiltin;
192 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
194 tokens_.push_back(token);
197 ///////////////////////////////////////////////////////////////////////////
198 // senf::console::ParseCommandInfo::ArgumentIterator
200 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
203 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
204 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
208 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
209 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
212 if (b_ == e_) setRange();
213 return b_->is(Token::ArgumentGroupOpen)
214 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
215 : boost::make_iterator_range(b_, e_);
219 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
222 return b_ == other.b_;
225 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
227 if (b_ == e_) setRange();
231 ///////////////////////////////////////////////////////////////////////////
232 // senf::console::SyntaxErrorException
234 prefix_ senf::console::SyntaxErrorException::SyntaxErrorException(std::string const & msg)
238 prefix_ senf::console::SyntaxErrorException::~SyntaxErrorException()
242 prefix_ std::string const & senf::console::SyntaxErrorException::message()
248 ///////////////////////////////////////////////////////////////////////////
250 prefix_ senf::console::CheckedArgumentIteratorWrapper::
251 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
252 std::string const & msg)
253 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
256 prefix_ senf::console::CheckedArgumentIteratorWrapper::
257 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
258 std::string const & msg)
259 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
262 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
264 if (i_ != e_ && ! std::uncaught_exception())
265 throw SyntaxErrorException(msg_);
268 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
273 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
279 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
285 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
290 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
291 senf::console::CheckedArgumentIteratorWrapper::dereference()
295 throw SyntaxErrorException(msg_);
299 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
302 throw SyntaxErrorException(msg_);
306 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
307 operator==(ParseCommandInfo::ArgumentIterator const & other)
313 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
314 operator!=(ParseCommandInfo::ArgumentIterator const & other)
320 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
321 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
323 ParseCommandInfo::ArgumentIterator i (i_);
328 ///////////////////////////////////////////////////////////////////////////
329 // senf::console::SingleCommandParser
331 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
337 ///////////////////////////////cci.e///////////////////////////////////////
344 // comment-column: 40
345 // c-file-style: "senf"
346 // indent-tabs-mode: nil
347 // ispell-local-dictionary: "american"
348 // compile-command: "scons -u test"