4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Parse inline non-template implementation */
31 // We do NOT want to include the complete parser definition into every other compilation unit
32 // (disabled) #include "Parse.ih"
35 #include <senf/Utils/senfassert.hh>
37 #define prefix_ inline
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 // senf::console::Token
43 prefix_ std::string const & senf::console::Token::value()
49 prefix_ senf::console::Token::TokenType senf::console::Token::type()
55 prefix_ unsigned senf::console::Token::line()
61 prefix_ unsigned senf::console::Token::column()
67 prefix_ unsigned senf::console::Token::index()
73 prefix_ bool senf::console::Token::is(unsigned tokens)
76 return tokens & type_;
79 prefix_ bool senf::console::Token::operator==(Token const & other)
82 return type() == other.type() && value() == other.value();
85 prefix_ bool senf::console::Token::operator!=(Token const & other)
88 return ! operator==(other);
91 prefix_ senf::console::Token::Token()
92 : type_ (None), token_ ()
95 prefix_ senf::console::Token::Token(TokenType type, std::string token)
96 : type_ (type), token_ (token), line_ (0), column_ (0), index_ (0)
99 prefix_ senf::console::Token senf::console::NoneToken()
101 return Token(Token::None,"");
104 prefix_ senf::console::Token senf::console::PathSeparatorToken()
106 return Token(Token::PathSeparator,"/");
109 prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken()
111 return Token(Token::ArgumentGroupOpen,"(");
114 prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken()
116 return Token(Token::ArgumentGroupClose,")");
119 prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken()
121 return Token(Token::DirectoryGroupOpen,"{");
124 prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken()
126 return Token(Token::DirectoryGroupClose,"}");
129 prefix_ senf::console::Token senf::console::CommandTerminatorToken()
131 return Token(Token::CommandTerminator,";");
134 prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value)
136 return Token(Token::OtherPunctuation, value);
139 prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value)
141 return Token(Token::BasicString, value);
144 prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value)
146 return Token(Token::HexString, value);
149 prefix_ senf::console::Token senf::console::WordToken(std::string const & value)
151 return Token(Token::Word, value);
154 //-/////////////////////////////////////////////////////////////////////////////////////////////////
155 // senf::console::ParseCommandInfo
157 prefix_ senf::console::ParseCommandInfo::ParseCommandInfo()
158 : builtin_ (NoBuiltin)
161 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
162 senf::console::ParseCommandInfo::builtin()
168 prefix_ senf::console::ParseCommandInfo::TokensRange
169 senf::console::ParseCommandInfo::commandPath()
172 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
175 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
176 senf::console::ParseCommandInfo::arguments()
179 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
180 ArgumentIterator(tokens_.end()) );
183 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
186 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
189 prefix_ void senf::console::ParseCommandInfo::clear()
191 builtin_ = NoBuiltin;
192 commandPath_.clear();
196 prefix_ bool senf::console::ParseCommandInfo::empty()
198 return builtin_ == NoBuiltin && commandPath_.empty();
201 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
207 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
209 commandPath_.clear();
210 commandPath_.swap(commandPath);
213 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
215 tokens_.push_back(token);
218 //-/////////////////////////////////////////////////////////////////////////////////////////////////
219 // senf::console::ParseCommandInfo::ArgumentIterator
221 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
224 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
225 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
229 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
230 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
233 if (b_ == e_) setRange();
234 return b_->is(Token::ArgumentGroupOpen)
235 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
236 : boost::make_iterator_range(b_, e_);
240 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
243 return b_ == other.b_;
246 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
248 if (b_ == e_) setRange();
252 //-/////////////////////////////////////////////////////////////////////////////////////////////////
254 prefix_ senf::console::CheckedArgumentIteratorWrapper::
255 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
256 std::string const & msg)
257 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
260 prefix_ senf::console::CheckedArgumentIteratorWrapper::
261 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
262 std::string const & msg)
263 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
266 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
268 if (i_ != e_ && ! std::uncaught_exception())
269 throw SyntaxErrorException(msg_);
272 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
277 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
283 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
289 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
294 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
295 senf::console::CheckedArgumentIteratorWrapper::dereference()
299 throw SyntaxErrorException(msg_);
303 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
306 throw SyntaxErrorException(msg_);
310 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
311 operator==(ParseCommandInfo::ArgumentIterator const & other)
317 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
318 operator!=(ParseCommandInfo::ArgumentIterator const & other)
324 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
325 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
327 ParseCommandInfo::ArgumentIterator i (i_);
332 //-/////////////////////////////////////////////////////////////////////////////////////////////////
333 // senf::console::SingleCommandParser
335 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
337 SENF_ASSERT(impl_, "Ineral error: PIMPL pointer NULL ??");
341 //-/////////////////////////////////////////////////////////////////////////////////////////////////
348 // comment-column: 40
349 // c-file-style: "senf"
350 // indent-tabs-mode: nil
351 // ispell-local-dictionary: "american"
352 // compile-command: "scons -u test"