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 <senf/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_ unsigned senf::console::Token::line()
56 prefix_ unsigned senf::console::Token::column()
62 prefix_ unsigned senf::console::Token::index()
68 prefix_ bool senf::console::Token::is(unsigned tokens)
71 return tokens & type_;
74 prefix_ bool senf::console::Token::operator==(Token const & other)
77 return type() == other.type() && value() == other.value();
80 prefix_ bool senf::console::Token::operator!=(Token const & other)
83 return ! operator==(other);
86 prefix_ senf::console::Token::Token()
87 : type_ (None), token_ ()
90 prefix_ senf::console::Token::Token(TokenType type, std::string token)
91 : type_ (type), token_ (token), line_ (0), column_ (0), index_ (0)
94 prefix_ senf::console::Token senf::console::NoneToken()
96 return Token(Token::None,"");
99 prefix_ senf::console::Token senf::console::PathSeparatorToken()
101 return Token(Token::PathSeparator,"/");
104 prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken()
106 return Token(Token::ArgumentGroupOpen,"(");
109 prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken()
111 return Token(Token::ArgumentGroupClose,")");
114 prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken()
116 return Token(Token::DirectoryGroupOpen,"{");
119 prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken()
121 return Token(Token::DirectoryGroupClose,"}");
124 prefix_ senf::console::Token senf::console::CommandTerminatorToken()
126 return Token(Token::CommandTerminator,";");
129 prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value)
131 return Token(Token::OtherPunctuation, value);
134 prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value)
136 return Token(Token::BasicString, value);
139 prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value)
141 return Token(Token::HexString, value);
144 prefix_ senf::console::Token senf::console::WordToken(std::string const & value)
146 return Token(Token::Word, value);
149 ///////////////////////////////////////////////////////////////////////////
150 // senf::console::ParseCommandInfo
152 prefix_ senf::console::ParseCommandInfo::ParseCommandInfo()
153 : builtin_ (NoBuiltin)
156 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
157 senf::console::ParseCommandInfo::builtin()
163 prefix_ senf::console::ParseCommandInfo::TokensRange
164 senf::console::ParseCommandInfo::commandPath()
167 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
170 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
171 senf::console::ParseCommandInfo::arguments()
174 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
175 ArgumentIterator(tokens_.end()) );
178 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
181 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
184 prefix_ void senf::console::ParseCommandInfo::clear()
186 builtin_ = NoBuiltin;
187 commandPath_.clear();
191 prefix_ bool senf::console::ParseCommandInfo::empty()
193 return builtin_ == NoBuiltin && commandPath_.empty();
196 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
202 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
204 commandPath_.clear();
205 commandPath_.swap(commandPath);
208 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
210 tokens_.push_back(token);
213 ///////////////////////////////////////////////////////////////////////////
214 // senf::console::ParseCommandInfo::ArgumentIterator
216 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
219 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
220 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
224 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
225 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
228 if (b_ == e_) setRange();
229 return b_->is(Token::ArgumentGroupOpen)
230 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
231 : boost::make_iterator_range(b_, e_);
235 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
238 return b_ == other.b_;
241 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
243 if (b_ == e_) setRange();
247 ///////////////////////////////////////////////////////////////////////////
249 prefix_ senf::console::CheckedArgumentIteratorWrapper::
250 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
251 std::string const & msg)
252 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
255 prefix_ senf::console::CheckedArgumentIteratorWrapper::
256 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
257 std::string const & msg)
258 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
261 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
263 if (i_ != e_ && ! std::uncaught_exception())
264 throw SyntaxErrorException(msg_);
267 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
272 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
278 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
284 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
289 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
290 senf::console::CheckedArgumentIteratorWrapper::dereference()
294 throw SyntaxErrorException(msg_);
298 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
301 throw SyntaxErrorException(msg_);
305 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
306 operator==(ParseCommandInfo::ArgumentIterator const & other)
312 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
313 operator!=(ParseCommandInfo::ArgumentIterator const & other)
319 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
320 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
322 ParseCommandInfo::ArgumentIterator i (i_);
327 ///////////////////////////////////////////////////////////////////////////
328 // senf::console::SingleCommandParser
330 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
336 ///////////////////////////////cci.e///////////////////////////////////////
343 // comment-column: 40
344 // c-file-style: "senf"
345 // indent-tabs-mode: nil
346 // ispell-local-dictionary: "american"
347 // compile-command: "scons -u test"