17 #ifndef HH_SENF_Utils_Console_Parse_ 18 #define HH_SENF_Utils_Console_Parse_ 1 186 #include <boost/noncopyable.hpp> 187 #include <boost/scoped_ptr.hpp> 188 #include <boost/range/iterator_range.hpp> 189 #include <boost/iterator/iterator_facade.hpp> 190 #include <boost/function.hpp> 200 template <
class Type>
202 template <
class Type>
206 struct FilePositionWithIndex;
208 template <
class ParameterType>
210 template<
class Collection,
class Adder>
212 template <
class Collection>
216 # define SENF_CONSOLE_PARSE_FRIEND( type ) \ 217 friend void senf_console_parse_argument(senf::console::ParseCommandInfo::TokensRange const &, type &); \ 218 friend struct senf::console::detail::ArgumentInfo<type>; \ 219 friend struct senf::console::ArgumentTraits<type>; \ 220 friend struct senf::console::ReturnValueTraits<type>; \ 221 template<class Collection, class Adder> \ 222 friend struct senf::console::detail::CollectionArgumentTraits; \ 223 template <class Collection> \ 224 friend struct senf::console::detail::MapArgumentTraits; 239 PathSeparator = 0x0001,
240 ArgumentGroupOpen = 0x0002,
241 ArgumentGroupClose = 0x0004,
242 DirectoryGroupOpen = 0x0008,
243 DirectoryGroupClose = 0x0010,
244 CommandTerminator = 0x0020,
245 OtherPunctuation = 0x0040,
246 BasicString = 0x0080,
252 ArgumentGrouper = ArgumentGroupOpen
253 | ArgumentGroupClose,
255 DirectoryGrouper = DirectoryGroupOpen
256 | DirectoryGroupClose,
258 Punctuation = DirectoryGroupOpen
259 | DirectoryGroupClose
267 SimpleArgument = Word
275 Token(
TokenType type, std::string token, detail::FilePositionWithIndex
const & pos);
279 std::string
const & value()
const;
284 unsigned line()
const;
285 unsigned column()
const;
286 unsigned index()
const;
288 bool is(
unsigned tokens)
const;
312 Token PathSeparatorToken();
316 Token ArgumentGroupOpenToken();
320 Token ArgumentGroupCloseToken();
324 Token DirectoryGroupOpenToken();
328 Token DirectoryGroupCloseToken();
332 Token CommandTerminatorToken();
336 Token OtherPunctuationToken(std::string
const & value);
340 Token BasicStringToken(std::string
const & value);
344 Token HexStringToken(std::string
const & value);
348 Token WordToken(std::string
const & value);
365 typedef std::vector<Token> Tokens;
366 typedef std::vector<std::string> CommandPath;
396 TokensRange commandPath()
const;
403 ArgumentsRange arguments()
const;
406 TokensRange tokens()
const;
414 void command(std::vector<Token> & commandPath);
416 void addToken(
Token const & token);
427 std::vector<Token> commandPath_;
443 :
public boost::iterator_facade< ParseCommandInfo::ArgumentIterator,
444 ParseCommandInfo::TokensRange,
445 boost::bidirectional_traversal_tag,
446 ParseCommandInfo::TokensRange >
453 reference dereference()
const;
458 mutable ParseCommandInfo::TokensRange::iterator b_;
459 mutable ParseCommandInfo::TokensRange::iterator e_;
461 void setRange()
const;
463 friend class boost::iterator_core_access;
509 : boost::noncopyable,
510 public boost::iterator_facade< CheckedArgumentIteratorWrapper,
511 ParseCommandInfo::TokensRange,
512 boost::forward_traversal_tag,
513 ParseCommandInfo::TokensRange >,
519 boost::forward_traversal_tag,
520 ParseCommandInfo::TokensRange > IteratorFacade;
523 explicit CheckedArgumentIteratorWrapper(
525 std::string
const & msg =
"invalid number of arguments");
531 explicit CheckedArgumentIteratorWrapper(
532 ParseCommandInfo::TokensRange
const & range,
533 std::string
const & msg =
"invalid number of arguments");
542 ~CheckedArgumentIteratorWrapper() noexcept(
false);
555 bool boolean_test()
const;
568 using IteratorFacade::operator++;
572 reference dereference()
const;
579 friend class boost::iterator_core_access;
609 typedef boost::function<void (ParseCommandInfo const &)>
Callback;
621 void parse(std::string
const & command, Callback cb);
622 void parseFile(std::string
const & filename, Callback cb);
626 void parseArguments(std::string
const & arguments,
ParseCommandInfo & info);
638 std::string::size_type parseIncremental(std::string
const & commands, Callback cb);
649 static bool isSpecialChar(
char ch);
650 static bool isPunctuationChar(
char ch);
651 static bool isSpaceChar(
char ch);
652 static bool isInvalidChar(
char ch);
653 static bool isWordChar(
char ch);
663 template <
class Iterator>
664 Iterator parseLoop(Iterator b, Iterator e, std::string
const & source, Callback cb);
668 boost::scoped_ptr<Impl> impl_;
Exception thrown when the parser detects an error.
boost::iterator_range< argument_iterator > ArgumentsRange
Tokens::size_type size_type
Tokens::const_iterator token_iterator
boost::function< void(ParseCommandInfo const &)> Callback
Iterator parsing argument groups.
Syntax error parsing command arguments exception.
boost::iterator_range< path_iterator > CommandPathRange
Customize return value formating.
bool operator==(ArrayValueParserBase< Parser, ValueType > const &parser, ValueType const &value)
ParserErrorException(std::string const &msg)
std::ostream & operator<<(std::ostream &os, Token const &token)
Single parsed console command.
Wrapper checking argument iterator access for validityOutput ParseCommandInfo instance.
void parse(ParseCommandInfo::TokensRange const &tokens, Type &out)
Parse token range.
SyntaxErrorException(std::string const &msg="syntax error")
bool operator!=(ArrayValueParserBase< Parser, ValueType > const &parser, ValueType const &value)
boost::iterator_range< token_iterator > TokensRange
ArgumentIterator argument_iterator
CommandPath::const_iterator path_iterator
Customize argument parsing.
::phoenix::function< detail::clear > const clear