2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Parse inline non-template implementation */
17 // We do NOT want to include the complete parser definition into every other compilation unit
18 // (disabled) #include "Parse.ih"
21 #include <senf/Utils/senfassert.hh>
23 #define prefix_ inline
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 // senf::console::Token
29 prefix_ std::string const & senf::console::Token::value()
35 prefix_ senf::console::Token::TokenType senf::console::Token::type()
41 prefix_ unsigned senf::console::Token::line()
47 prefix_ unsigned senf::console::Token::column()
53 prefix_ unsigned senf::console::Token::index()
59 prefix_ bool senf::console::Token::is(unsigned tokens)
62 return tokens & type_;
65 prefix_ bool senf::console::Token::operator==(Token const & other)
68 return type() == other.type() && value() == other.value();
71 prefix_ bool senf::console::Token::operator!=(Token const & other)
74 return ! operator==(other);
77 prefix_ senf::console::Token::Token()
78 : type_ (None), token_ (), line_ (0), column_ (0), index_ (0)
81 prefix_ senf::console::Token::Token(TokenType type, std::string token)
82 : type_ (type), token_ (token), line_ (0), column_ (0), index_ (0)
85 prefix_ senf::console::Token senf::console::NoneToken()
87 return Token(Token::None,"");
90 prefix_ senf::console::Token senf::console::PathSeparatorToken()
92 return Token(Token::PathSeparator,"/");
95 prefix_ senf::console::Token senf::console::ArgumentGroupOpenToken()
97 return Token(Token::ArgumentGroupOpen,"(");
100 prefix_ senf::console::Token senf::console::ArgumentGroupCloseToken()
102 return Token(Token::ArgumentGroupClose,")");
105 prefix_ senf::console::Token senf::console::DirectoryGroupOpenToken()
107 return Token(Token::DirectoryGroupOpen,"{");
110 prefix_ senf::console::Token senf::console::DirectoryGroupCloseToken()
112 return Token(Token::DirectoryGroupClose,"}");
115 prefix_ senf::console::Token senf::console::CommandTerminatorToken()
117 return Token(Token::CommandTerminator,";");
120 prefix_ senf::console::Token senf::console::OtherPunctuationToken(std::string const & value)
122 return Token(Token::OtherPunctuation, value);
125 prefix_ senf::console::Token senf::console::BasicStringToken(std::string const & value)
127 return Token(Token::BasicString, value);
130 prefix_ senf::console::Token senf::console::HexStringToken(std::string const & value)
132 return Token(Token::HexString, value);
135 prefix_ senf::console::Token senf::console::WordToken(std::string const & value)
137 return Token(Token::Word, value);
140 //-/////////////////////////////////////////////////////////////////////////////////////////////////
141 // senf::console::ParseCommandInfo
143 prefix_ senf::console::ParseCommandInfo::ParseCommandInfo()
144 : builtin_ (NoBuiltin)
147 prefix_ senf::console::ParseCommandInfo::BuiltinCommand
148 senf::console::ParseCommandInfo::builtin()
154 prefix_ senf::console::ParseCommandInfo::TokensRange
155 senf::console::ParseCommandInfo::commandPath()
158 return boost::make_iterator_range(commandPath_.begin(), commandPath_.end());
161 prefix_ senf::console::ParseCommandInfo::ArgumentsRange
162 senf::console::ParseCommandInfo::arguments()
165 return boost::make_iterator_range( ArgumentIterator(tokens_.begin()),
166 ArgumentIterator(tokens_.end()) );
169 prefix_ senf::console::ParseCommandInfo::TokensRange senf::console::ParseCommandInfo::tokens()
172 return boost::make_iterator_range(tokens_.begin(), tokens_.end());
175 prefix_ void senf::console::ParseCommandInfo::clear()
177 builtin_ = NoBuiltin;
178 commandPath_.clear();
182 prefix_ bool senf::console::ParseCommandInfo::empty()
184 return builtin_ == NoBuiltin && commandPath_.empty();
187 prefix_ void senf::console::ParseCommandInfo::builtin(BuiltinCommand builtin)
193 senf::console::ParseCommandInfo::command(std::vector<Token> & commandPath)
195 commandPath_.clear();
196 commandPath_.swap(commandPath);
199 prefix_ void senf::console::ParseCommandInfo::addToken(Token const & token)
201 tokens_.push_back(token);
204 //-/////////////////////////////////////////////////////////////////////////////////////////////////
205 // senf::console::ParseCommandInfo::ArgumentIterator
207 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::ArgumentIterator()
210 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::
211 ArgumentIterator(ParseCommandInfo::TokensRange::iterator i)
215 prefix_ senf::console::ParseCommandInfo::ArgumentIterator::reference
216 senf::console::ParseCommandInfo::ArgumentIterator::dereference()
219 if (b_ == e_) setRange();
220 return b_->is(Token::ArgumentGroupOpen)
221 ? boost::make_iterator_range(boost::next(b_), boost::prior(e_))
222 : boost::make_iterator_range(b_, e_);
226 senf::console::ParseCommandInfo::ArgumentIterator::equal(ArgumentIterator const & other)
229 return b_ == other.b_;
232 prefix_ void senf::console::ParseCommandInfo::ArgumentIterator::increment()
234 if (b_ == e_) setRange();
238 //-/////////////////////////////////////////////////////////////////////////////////////////////////
240 prefix_ senf::console::CheckedArgumentIteratorWrapper::
241 CheckedArgumentIteratorWrapper(ParseCommandInfo::ArgumentsRange const & range,
242 std::string const & msg)
243 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
246 prefix_ senf::console::CheckedArgumentIteratorWrapper::
247 CheckedArgumentIteratorWrapper(ParseCommandInfo::TokensRange const & range,
248 std::string const & msg)
249 : i_ (range.begin()), e_ (range.end()), msg_ (msg)
252 prefix_ senf::console::CheckedArgumentIteratorWrapper::~CheckedArgumentIteratorWrapper()
255 if (i_ != e_ && ! std::uncaught_exception())
256 throw SyntaxErrorException(msg_);
259 prefix_ senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::ArgumentIterator()
264 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::boolean_test()
270 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::done()
276 prefix_ void senf::console::CheckedArgumentIteratorWrapper::clear()
281 prefix_ senf::console::CheckedArgumentIteratorWrapper::reference
282 senf::console::CheckedArgumentIteratorWrapper::dereference()
286 throw SyntaxErrorException(msg_);
290 prefix_ void senf::console::CheckedArgumentIteratorWrapper::increment()
293 throw SyntaxErrorException(msg_);
297 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
298 operator==(ParseCommandInfo::ArgumentIterator const & other)
304 prefix_ bool senf::console::CheckedArgumentIteratorWrapper::
305 operator!=(ParseCommandInfo::ArgumentIterator const & other)
311 prefix_ senf::console::ParseCommandInfo::ArgumentIterator
312 senf::console::CheckedArgumentIteratorWrapper::operator++(int)
314 ParseCommandInfo::ArgumentIterator i (i_);
319 //-/////////////////////////////////////////////////////////////////////////////////////////////////
320 // senf::console::SingleCommandParser
322 prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
324 SENF_ASSERT(impl_, "Internal error: PIMPL pointer NULL ??");
328 //-/////////////////////////////////////////////////////////////////////////////////////////////////
335 // comment-column: 40
336 // c-file-style: "senf"
337 // indent-tabs-mode: nil
338 // ispell-local-dictionary: "american"
339 // compile-command: "scons -u test"