Console: Documentation of the configuration support
[senf.git] / Console / Parse.hh
index a40bd74..c246ce1 100644 (file)
@@ -251,8 +251,9 @@ namespace console {
                                 | HexString
         };
         
-        Token();
-        Token(TokenType type, std::string token);
+        Token();                        ///< Create empty token
+        Token(TokenType type, std::string token); ///< Create token with given type and value
+
 
         std::string const & value() const; ///< String value of token
                                         /**< This value is properly unquoted */
@@ -274,6 +275,50 @@ namespace console {
 
     std::ostream & operator<<(std::ostream & os, Token const & token);
 
+    /** \brief Create a \c None token
+        \related Token */
+    Token NoneToken();
+
+    /** \brief Create a \c PathSeparator ['/'] token
+        \related Token */
+    Token PathSeparatorToken();
+
+    /** \brief Create an \c ArgumentGroupOpen ['('] token
+        \related Token */
+    Token ArgumentGroupOpenToken();
+
+    /** \brief Create a \c ArgumentGroupClose [')'] token
+        \related Token */
+    Token ArgumentGroupCloseToken();
+
+    /** \brief Create a \c DirectoryGroupOpen ['{'] token
+        \related Token */
+    Token DirectoryGroupOpenToken();
+
+    /** \brief Create a \c DirectoryGroupClose ['}'] token
+        \related Token */
+    Token DirectoryGroupCloseToken();
+
+    /** \brief Create a \c CommandTerminator [';'] token
+        \related Token */
+    Token CommandTerminatorToken();
+
+    /** \brief Create a \c OtherPunctuation ['=', ','] token with the given \a value
+        \related Token */
+    Token OtherPunctuationToken(std::string const & value);
+
+    /** \brief Create a \c BasicString token with the given \a value
+        \related Token */
+    Token BasicStringToken(std::string const & value);
+
+    /** \brief Create a \c HexString token with the given \a value
+        \related Token */
+    Token HexStringToken(std::string const & value);
+
+    /** \brief Create a \c Word token with the given \a value
+        \related Token */
+    Token WordToken(std::string const & value);
+
     /** \brief Single parsed console command
 
         Every command parsed is returned in a ParseCommandInfo instance. This information is purely
@@ -312,6 +357,8 @@ namespace console {
                               BuiltinEXIT,
                               BuiltinHELP };
 
+        ParseCommandInfo();
+
         BuiltinCommand builtin() const; ///< Command type
                                         /**< \returns \c NoBuiltin, if the command is an ordinary
                                              command, otherwise the id of the built-in command */
@@ -328,21 +375,26 @@ namespace console {
         TokensRange tokens() const;     ///< All argument tokens
                                         /**< The returned range contains \e all argument tokens in a
                                              single range not divided into separate arguments. */
+
+        void clear();                   ///< Clear all data members
+
+        void builtin(BuiltinCommand builtin); ///< Assign builtin command 
+        void command(std::vector<Token> & commandPath); ///< Assign non-builtin command
+
+        void addToken(Token const & token); ///< Add argument token
+                                        /**< You \e must ensure, that the resulting argument tokens
+                                             are properly nested regarding '()' groups, otherwise
+                                             interpreting arguments using the arguments() call will
+                                             crash the program. */
+
     protected:
 
     private:
-        void init();
-        void setBuiltin(BuiltinCommand builtin);
-        void setCommand(std::vector<Token> & commandPath);
-        void addToken(Token const & token);
-
         struct MakeRange;
 
         std::vector<Token> commandPath_;
         BuiltinCommand builtin_;
         Tokens tokens_;
-
-        friend class detail::ParserAccess;
     };
 
     /** \brief Iterator parsing argument groups
@@ -548,6 +600,13 @@ namespace console {
                                         /**< \throws SystemException if the file cannot be
                                              read. */
 
+        bool parseArguments(std::string arguments, ParseCommandInfo & info);
+                                        ///< Parse \a argumtns
+                                        /**< parseArguments() parses the string \a arguments which
+                                             contains arbitrary command arguments (without the name
+                                             of the command). The argument tokens are written into
+                                             \a info. */
+
     private:
         struct Impl;