// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief Parse inline non-template implementation */ // We do NOT want to include the complete parser definition into every other compilation unit // (disabled) #include "Parse.ih" // Custom includes #include "../../Utils/senfassert.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // senf::console::Token prefix_ std::string const & senf::console::Token::value() const { return token_; } prefix_ senf::console::Token::TokenType senf::console::Token::type() const { return type_; } prefix_ unsigned senf::console::Token::line() const { return line_; } prefix_ unsigned senf::console::Token::column() const { return column_; } prefix_ unsigned senf::console::Token::index() const { return index_; } prefix_ bool senf::console::Token::is(unsigned tokens) const { return tokens & type_; } prefix_ bool senf::console::Token::operator==(Token const & other) const { return type() == other.type() && value() == other.value(); } prefix_ bool senf::console::Token::operator!=(Token const & other) const { return ! operator==(other); } prefix_ senf::console::Token::Token() : type_ (None), token_ () {} prefix_ senf::console::Token::Token(TokenType type, std::string token) : type_ (type), token_ (token), line_ (0), column_ (0), index_ (0) {} prefix_ senf::console::Token senf::console::NoneToken() { return Token(Token::None,""); } prefix_ senf::console::Token senf::console::PathSeparatorToken() { return Token(Token::PathSeparator,"/"); } prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken() { return Token(Token::ArgumentGroupOpen,"("); } prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken() { return Token(Token::ArgumentGroupClose,")"); } prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken() { return Token(Token::DirectoryGroupOpen,"{"); } prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken() { return Token(Token::DirectoryGroupClose,"}"); } prefix_ senf::console::Token senf::console::CommandTerminatorToken() { return Token(Token::CommandTerminator,";"); } prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value) { return Token(Token::OtherPunctuation, value); } prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value) { return Token(Token::BasicString, value); } prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value) { return Token(Token::HexString, value); } prefix_ senf::console::Token senf::console::WordToken(std::string const & value) { return Token(Token::Word, value); } /////////////////////////////////////////////////////////////////////////// // senf::console::ParseCommandInfo prefix_ senf::console::ParseCommandInfo::ParseCommandInfo() : builtin_ (NoBuiltin) {} prefix_ senf::console::ParseCommandInfo::BuiltinCommand senf::console::ParseCommandInfo::builtin() const { return builtin_; } prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::commandPath() const { return boost::make_iterator_range(commandPath_.begin(), commandPath_.end()); } prefix_ senf::console::ParseCommandInfo::ArgumentsRange senf::console::ParseCommandInfo::arguments() const { return boost::make_iterator_range( ArgumentIterator(tokens_.begin()), ArgumentIterator(tokens_.end()) ); } prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens() const { return boost::make_iterator_range(tokens_.begin(), tokens_.end()); } prefix_ void senf::console::ParseCommandInfo::clear() { builtin_ = NoBuiltin; commandPath_.clear(); tokens_.clear(); } prefix_ bool senf::console::ParseCommandInfo::empty() { return builtin_ == NoBuiltin && commandPath_.empty(); } prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin) { builtin_ = builtin; } prefix_ void senf::console::ParseCommandInfo::command(std::vector & commandPath) { commandPath_.clear(); commandPath_.swap(commandPath); } prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token) { tokens_.push_back(token); } /////////////////////////////////////////////////////////////////////////// // senf::console::ParseCommandInfo::ArgumentIterator prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator() {} prefix_ senf::console::ParseCommandInfo::ArgumentIterator:: ArgumentIterator(ParseCommandInfo::TokensRange::iterator i) : b_(i), e_(i) {} prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference senf::console::ParseCommandInfo::ArgumentIterator::dereference() const { if (b_ == e_) setRange(); return b_->is(Token::ArgumentGroupOpen) ? boost::make_iterator_range(boost::next(b_), boost::prior(e_)) : boost::make_iterator_range(b_, e_); } prefix_ bool senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other) const { return b_ == other.b_; } prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment() { if (b_ == e_) setRange(); b_ = e_; } /////////////////////////////////////////////////////////////////////////// prefix_ senf::console::CheckedArgumentIteratorWrapper:: CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range, std::string const & msg) : i_ (range.begin()), e_ (range.end()), msg_ (msg) {} prefix_ senf::console::CheckedArgumentIteratorWrapper:: CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range, std::string const & msg) : i_ (range.begin()), e_ (range.end()), msg_ (msg) {} prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper() { if (i_ != e_ && ! std::uncaught_exception()) throw SyntaxErrorException(msg_); } prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator() { return i_; } prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test() const { return i_ != e_; } prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done() const { return i_ == e_; } prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear() { i_ = e_; } prefix_ senf::console::CheckedArgumentIteratorWrapper::reference senf::console::CheckedArgumentIteratorWrapper::dereference() const { if (i_ == e_) throw SyntaxErrorException(msg_); return *i_; } prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment() { if (i_ == e_) throw SyntaxErrorException(msg_); ++ i_; } prefix_ bool senf::console::CheckedArgumentIteratorWrapper:: operator==(ParseCommandInfo::ArgumentIterator const & other) const { return i_ == other; } prefix_ bool senf::console::CheckedArgumentIteratorWrapper:: operator!=(ParseCommandInfo::ArgumentIterator const & other) const { return i_ != other; } prefix_ senf::console::ParseCommandInfo::ArgumentIterator senf::console::CheckedArgumentIteratorWrapper::operator++(int) { ParseCommandInfo::ArgumentIterator i (i_); increment(); return i; } /////////////////////////////////////////////////////////////////////////// // senf::console::SingleCommandParser prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl() { SENF_ASSERT(impl_); return *impl_; } ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: