X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParse.hh;h=8c2ab32d6050bc403de18279786cfda089387512;hb=e879290346fe5242d7df2d70ee552d264081492f;hp=295f4a66b9e8230e2671662f7d6e8a4e7500c228;hpb=63c40810b93b4d8f3d6dad5f987adc5f2bf5b5ed;p=senf.git diff --git a/Console/Parse.hh b/Console/Parse.hh index 295f4a6..8c2ab32 100644 --- a/Console/Parse.hh +++ b/Console/Parse.hh @@ -194,6 +194,7 @@ #include #include #include +#include #include //#include "Parse.mpp" @@ -214,14 +215,54 @@ namespace console { class ArgumentToken { public: + enum TokenType { + PathSeparator = 0x0001, + ArgumentGroupOpen = 0x0002, + ArgumentGroupClose = 0x0004, + DirectoryGroupOpen = 0x0008, + DirectoryGroupClose = 0x0010, + CommandTerminator = 0x0020, + OtherPunctuation = 0x0040, + BasicString = 0x0080, + HexString = 0x0100, + Word = 0x0200 + }; + + enum TokenGroup { + ArgumentGrouper = ArgumentGroupOpen + | ArgumentGroupClose, + + DirectoryGrouper = DirectoryGroupOpen + | DirectoryGroupClose, + + Punctuation = DirectoryGroupOpen + | DirectoryGroupClose + | PathSeparator + | CommandTerminator + | OtherPunctuation, + + String = BasicString + | HexString, + + SimpleArgument = Word + | BasicString + | HexString + }; + std::string const & value() const; ///< String value of token /**< This value is properly unquoted */ + TokenType type() const; ///< Token type + + bool is(unsigned tokens) const; ///< Check, whether tokens type matches \a tokens + /**< \a tokens is a bit-mask of token types to check. */ + protected: private: - explicit ArgumentToken(std::string token); + ArgumentToken(TokenType type, std::string token); + TokenType type_; std::string token_; friend class detail::ParserAccess; @@ -244,19 +285,13 @@ namespace console { { typedef std::vector Tokens; typedef std::vector CommandPath; - + class ArgumentIterator; + public: typedef CommandPath::const_iterator path_iterator; typedef Tokens::const_iterator token_iterator; - typedef boost::iterator_range argument_value_type; - - - private: - typedef std::vector Arguments; - - public: - typedef Arguments::const_iterator argument_iterator; - typedef Arguments::size_type size_type; + typedef ArgumentIterator argument_iterator; + typedef Tokens::size_type size_type; typedef boost::iterator_range CommandPathRange; typedef boost::iterator_range ArgumentsRange; @@ -292,26 +327,42 @@ namespace console { void init(); void setBuiltin(BuiltinCommand builtin); void setCommand(std::vector & commandPath); - void startArgument(); - void endArgument(); void addToken(ArgumentToken const & token); - void finalize(); struct MakeRange; std::vector commandPath_; - - typedef std::pair TempArgumentRange; - typedef std::vector TempArguments; - BuiltinCommand builtin_; Tokens tokens_; - Arguments arguments_; - TempArguments tempArguments_; friend class detail::ParserAccess; }; + class ParseCommandInfo::ArgumentIterator + : public boost::iterator_facade< ParseCommandInfo::ArgumentIterator, + ParseCommandInfo::TokensRange, + boost::bidirectional_traversal_tag, + ParseCommandInfo::TokensRange > + { + ArgumentIterator(); + + private: + ArgumentIterator(ParseCommandInfo::TokensRange::iterator i); + + reference dereference() const; + bool equal(ArgumentIterator const & other) const; + void increment(); + void decrement(); + + mutable ParseCommandInfo::TokensRange::iterator b_; + mutable ParseCommandInfo::TokensRange::iterator e_; + + void setRange() const; + + friend class boost::iterator_core_access; + friend class ParseCommandInfo; + }; + /**< \brief Output ParseCommandInfo instance \related ParseCommandInfo */