// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \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 #define prefix_ inline //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // 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_, "Ineral error: PIMPL pointer NULL ??"); return *impl_; } //-///////////////////////////////////////////////////////////////////////////////////////////////// #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: