Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Parse.cci

Go to the documentation of this file.
00001 // $Id: Parse.cci 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 // We do NOT want to include the complete parser definition into every other compilation unit
00027 // (disabled) #include "Parse.ih"
00028 
00029 // Custom includes
00030 #include <senf/Utils/senfassert.hh>
00031 
00032 #define prefix_ inline
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 // senf::console::Token
00037 
00038 prefix_ std::string const & senf::console::Token::value()
00039     const
00040 {
00041     return token_;
00042 }
00043 
00044 prefix_ senf::console::Token::TokenType senf::console::Token::type()
00045     const
00046 {
00047     return type_;
00048 }
00049 
00050 prefix_ unsigned senf::console::Token::line()
00051     const
00052 {
00053     return line_;
00054 }
00055 
00056 prefix_ unsigned senf::console::Token::column()
00057     const
00058 {
00059     return column_;
00060 }
00061 
00062 prefix_ unsigned senf::console::Token::index()
00063     const
00064 {
00065     return index_;
00066 }
00067 
00068 prefix_ bool senf::console::Token::is(unsigned tokens)
00069     const
00070 {
00071     return tokens & type_;
00072 }
00073 
00074 prefix_ bool senf::console::Token::operator==(Token const & other)
00075     const
00076 {
00077     return type() == other.type() && value() == other.value();
00078 }
00079 
00080 prefix_ bool senf::console::Token::operator!=(Token const & other)
00081     const
00082 {
00083     return ! operator==(other);
00084 }
00085 
00086 prefix_ senf::console::Token::Token()
00087     : type_ (None), token_ ()
00088 {}
00089 
00090 prefix_ senf::console::Token::Token(TokenType type, std::string token)
00091     : type_ (type), token_ (token), line_ (0), column_ (0), index_ (0)
00092 {}
00093 
00094 prefix_ senf::console::Token senf::console::NoneToken()
00095 {
00096     return Token(Token::None,"");
00097 }
00098 
00099 prefix_ senf::console::Token senf::console::PathSeparatorToken()
00100 {
00101     return Token(Token::PathSeparator,"/");
00102 }
00103 
00104 prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken()
00105 {
00106     return Token(Token::ArgumentGroupOpen,"(");
00107 }
00108 
00109 prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken()
00110 {
00111     return Token(Token::ArgumentGroupClose,")");
00112 }
00113 
00114 prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken()
00115 {
00116     return Token(Token::DirectoryGroupOpen,"{");
00117 }
00118 
00119 prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken()
00120 {
00121     return Token(Token::DirectoryGroupClose,"}");
00122 }
00123 
00124 prefix_ senf::console::Token senf::console::CommandTerminatorToken()
00125 {
00126     return Token(Token::CommandTerminator,";");
00127 }
00128 
00129 prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value)
00130 {
00131     return Token(Token::OtherPunctuation, value);
00132 }
00133 
00134 prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value)
00135 {
00136     return Token(Token::BasicString, value);
00137 }
00138 
00139 prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value)
00140 {
00141     return Token(Token::HexString, value);
00142 }
00143 
00144 prefix_ senf::console::Token senf::console::WordToken(std::string const & value)
00145 {
00146     return Token(Token::Word, value);
00147 }
00148 
00149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00150 // senf::console::ParseCommandInfo
00151 
00152 prefix_ senf::console::ParseCommandInfo::ParseCommandInfo()
00153     : builtin_ (NoBuiltin)
00154 {}
00155 
00156 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
00157 senf::console::ParseCommandInfo::builtin()
00158     const
00159 {
00160     return builtin_;
00161 }
00162 
00163 prefix_ senf::console::ParseCommandInfo::TokensRange
00164 senf::console::ParseCommandInfo::commandPath()
00165     const
00166 {
00167     return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
00168 }
00169 
00170 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
00171 senf::console::ParseCommandInfo::arguments()
00172     const
00173 {
00174     return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
00175                                        ArgumentIterator(tokens_.end()) );
00176 }
00177 
00178 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
00179     const
00180 {
00181     return boost::make_iterator_range(tokens_.begin(), tokens_.end());
00182 }
00183 
00184 prefix_ void senf::console::ParseCommandInfo::clear()
00185 {
00186     builtin_ = NoBuiltin;
00187     commandPath_.clear();
00188     tokens_.clear();
00189 }
00190 
00191 prefix_ bool senf::console::ParseCommandInfo::empty()
00192 {
00193     return builtin_ == NoBuiltin && commandPath_.empty();
00194 }
00195 
00196 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
00197 {
00198     builtin_ = builtin;
00199 }
00200 
00201 prefix_ void
00202 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
00203 {
00204     commandPath_.clear();
00205     commandPath_.swap(commandPath);
00206 }
00207 
00208 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
00209 {
00210     tokens_.push_back(token);
00211 }
00212 
00213 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00214 // senf::console::ParseCommandInfo::ArgumentIterator
00215 
00216 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
00217 {}
00218 
00219 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
00220 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
00221     : b_(i), e_(i)
00222 {}
00223 
00224 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
00225 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
00226     const
00227 {
00228     if (b_ == e_) setRange();
00229     return b_->is(Token::ArgumentGroupOpen)
00230         ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
00231         : boost::make_iterator_range(b_, e_);
00232 }
00233 
00234 prefix_ bool
00235 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
00236     const
00237 {
00238     return b_ == other.b_;
00239 }
00240 
00241 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
00242 {
00243     if (b_ == e_) setRange();
00244     b_ = e_;
00245 }
00246 
00247 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00248 
00249 prefix_ senf::console::CheckedArgumentIteratorWrapper::
00250 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
00251                                std::string const & msg)
00252     : i_ (range.begin()), e_ (range.end()), msg_ (msg)
00253 {}
00254 
00255 prefix_ senf::console::CheckedArgumentIteratorWrapper::
00256 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
00257                                std::string const & msg)
00258     : i_ (range.begin()), e_ (range.end()), msg_ (msg)
00259 {}
00260 
00261 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
00262 {
00263     if (i_ != e_ && ! std::uncaught_exception())
00264         throw SyntaxErrorException(msg_);
00265 }
00266 
00267 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
00268 {
00269     return i_;
00270 }
00271 
00272 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
00273     const
00274 {
00275     return i_ != e_;
00276 }
00277 
00278 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
00279     const
00280 {
00281     return i_ == e_;
00282 }
00283 
00284 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
00285 {
00286     i_ = e_;
00287 }
00288 
00289 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
00290 senf::console::CheckedArgumentIteratorWrapper::dereference()
00291     const
00292 {
00293     if (i_ == e_)
00294         throw SyntaxErrorException(msg_);
00295     return *i_;
00296 }
00297 
00298 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
00299 {
00300     if (i_ == e_)
00301         throw SyntaxErrorException(msg_);
00302     ++ i_;
00303 }
00304 
00305 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
00306 operator==(ParseCommandInfo::ArgumentIterator const & other)
00307     const
00308 {
00309     return i_ == other;
00310 }
00311 
00312 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
00313 operator!=(ParseCommandInfo::ArgumentIterator const & other)
00314     const
00315 {
00316     return i_ != other;
00317 }
00318 
00319 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
00320 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
00321 {
00322     ParseCommandInfo::ArgumentIterator i (i_);
00323     increment();
00324     return i;
00325 }
00326 
00327 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00328 // senf::console::SingleCommandParser
00329 
00330 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
00331 {
00332     SENF_ASSERT(impl_, "Ineral error: PIMPL pointer NULL ??");
00333     return *impl_;
00334 }
00335 
00336 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00337 #undef prefix_
00338 
00339 
00340 // Local Variables:
00341 // mode: c++
00342 // fill-column: 100
00343 // comment-column: 40
00344 // c-file-style: "senf"
00345 // indent-tabs-mode: nil
00346 // ispell-local-dictionary: "american"
00347 // compile-command: "scons -u test"
00348 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research