[colobot] 176/377: TokenType enum

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:13 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 9b4a6e0131b3ab012b196e396911a0bda4194d56
Author: krzys-h <krzys_h at interia.pl>
Date:   Wed Dec 23 14:05:29 2015 +0100

    TokenType enum
---
 src/CBot/CBotEnums.h            | 21 +++++++++++--
 src/CBot/CBotKeywordStrings.cpp |  4 +--
 src/CBot/CBotKeywordStrings.h   |  2 +-
 src/CBot/CBotToken.cpp          | 20 ++++---------
 src/CBot/CBotToken.h            | 65 +++++++++++++++++++++--------------------
 src/script/script.cpp           |  4 ---
 6 files changed, 62 insertions(+), 54 deletions(-)

diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h
index ee218f7..6569a93 100644
--- a/src/CBot/CBotEnums.h
+++ b/src/CBot/CBotEnums.h
@@ -65,11 +65,12 @@ enum CBotGet
 };
 
 /**
- * \enum EID
+ * \enum TokenId
  * \brief This enum contains possible token types
  */
-enum EID
+enum TokenId
 {
+    TokenKeyWord = 2000, //!< keywords
     ID_IF = 2000,
     ID_ELSE,
     ID_WHILE,
@@ -104,11 +105,13 @@ enum EID
     ID_VOID,
     ID_BOOL,
 
+    TokenKeyVal = 2200, //!< keywords that represent values (true, false, null, nan)
     ID_TRUE = 2200,
     ID_FALSE,
     ID_NULL,
     ID_NAN,
 
+    TokenKeyOp = 2300, //!< operators
     ID_OPENPAR = 2300,
     ID_CLOSEPAR,
     ID_OPBLK,
@@ -157,11 +160,25 @@ enum EID
     ID_MODULO,
     ID_POWER,
     ID_ASSMODULO,
+
     TX_UNDEF = 4000,
     TX_NAN
 };
 
 /**
+ * \enum TokenType
+ * \brief Types of tokens
+ */
+enum TokenType {
+    TokenTypNone = 0,
+    TokenTypKeyWord = 1, //!< keyword of the language (see TokenKeyWord)
+    TokenTypNum = 2,     //!< number
+    TokenTypString = 3,  //!< string
+    TokenTypVar = 4,     //!< a variable name
+    TokenTypDef = 5      //!< value according DefineNum
+};
+
+/**
  * \enum CBotError
  * \brief This enum contains possible CBot error values. Values in range 5000-5999 are compile errors, 6000-6999 are runtime errors
  *
diff --git a/src/CBot/CBotKeywordStrings.cpp b/src/CBot/CBotKeywordStrings.cpp
index 2af5eb0..75e52ad 100644
--- a/src/CBot/CBotKeywordStrings.cpp
+++ b/src/CBot/CBotKeywordStrings.cpp
@@ -4,7 +4,7 @@
 
 //! \brief Keeps the string corresponding to keyword ID
 // Map is filled with id-string pars that are needed for CBot language parsing
-static const std::map<EID, const std::string> s_keywordString = {
+static const std::map<TokenId, const std::string> s_keywordString = {
     {ID_IF,         "if"},
     {ID_ELSE,       "else"},
     {ID_WHILE,      "while"},
@@ -95,7 +95,7 @@ static const std::map<EID, const std::string> s_keywordString = {
 };
 
 static const std::string emptyString = "";
-const std::string& LoadString(EID id)
+const std::string& LoadString(TokenId id)
 {
     if (s_keywordString.find(id) != s_keywordString.end())
     {
diff --git a/src/CBot/CBotKeywordStrings.h b/src/CBot/CBotKeywordStrings.h
index e652a20..6cdb0cf 100644
--- a/src/CBot/CBotKeywordStrings.h
+++ b/src/CBot/CBotKeywordStrings.h
@@ -9,4 +9,4 @@
  * \param id            Provided identifier.
  * \return              String if found, else NullString.
  */
-const std::string& LoadString(EID id);
+const std::string& LoadString(TokenId id);
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index 914a54e..ad4469c 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -50,7 +50,7 @@ CBotToken::CBotToken(const CBotToken* pSrc)
     m_Text.clear();
     m_Sep.clear();
 
-    m_type      = 0;
+    m_type      = TokenTypNone;
     m_IdKeyWord = 0;
 
     m_start     = 0;
@@ -350,7 +350,7 @@ bis:
 
             if (CharInList( mot[0], num )) token->m_type = TokenTypNum;
             if (mot[0] == '\"')  token->m_type = TokenTypString;
-            if (first) token->m_type = 0;
+            if (first) token->m_type = TokenTypNone;
 
             token->m_IdKeyWord = GetKeyWords(mot);
             if (token->m_IdKeyWord > 0) token->m_type = TokenTypKeyWord;
@@ -400,7 +400,7 @@ CBotToken* CBotToken::CompileTokens(const std::string& program, int& error)
     // adds a token as a terminator
     // ( useful for the previous )
     nxt = new CBotToken();
-    nxt->m_type = 0;
+    nxt->m_type = TokenTypNone;
     prv->m_next = nxt;              // added after
     nxt->m_prev = prv;
 
@@ -459,14 +459,7 @@ void CBotToken::LoadKeyWords()
     int             i, n = 0;
 
     i = TokenKeyWord; //start with keywords of the language
-    while (!(s = LoadString(static_cast<EID>(i))).empty())
-    {
-        m_ListKeyWords.push_back(s);
-        m_ListIdKeyWords[n++] = i++;
-    }
-
-    i = TokenKeyDeclare; //keywords of declarations
-    while (!(s = LoadString(static_cast<EID>(i))).empty())
+    while (!(s = LoadString(static_cast<TokenId>(i))).empty())
     {
         m_ListKeyWords.push_back(s);
         m_ListIdKeyWords[n++] = i++;
@@ -474,14 +467,14 @@ void CBotToken::LoadKeyWords()
 
 
     i = TokenKeyVal;  //keywords of values
-    while (!(s = LoadString(static_cast<EID>(i))).empty())
+    while (!(s = LoadString(static_cast<TokenId>(i))).empty())
     {
         m_ListKeyWords.push_back(s);
         m_ListIdKeyWords[n++] = i++;
     }
 
     i = TokenKeyOp; //operators
-    while (!(s = LoadString(static_cast<EID>(i))).empty())
+    while (!(s = LoadString(static_cast<TokenId>(i))).empty())
     {
         m_ListKeyWords.push_back(s);
         m_ListIdKeyWords[n++] = i++;
@@ -542,4 +535,3 @@ bool IsOfTypeList(CBotToken* &p, int type1, ...)
         }
     }
 }
-
diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h
index 4a0e2d6..2cdada3 100644
--- a/src/CBot/CBotToken.h
+++ b/src/CBot/CBotToken.h
@@ -22,40 +22,43 @@
 #include <vector>
 #include <string>
 
-/////////////////////////////////////////////////////////////////////////////////////
-// Token management (tokens)
-
-#define TokenTypKeyWord 1    // a keyword of the language (see TokenKeyWord)
-#define TokenTypNum     2    // number
-#define TokenTypString  3    // string
-#define TokenTypVar     4    // a variable name
-#define TokenTypDef     5    // value according DefineNum
-
-#define TokenKeyWord    2000 // keywords of the language
-#define TokenKeyDeclare 2100 // keywords of declarations (int, float,..)
-#define TokenKeyVal     2200 // keywords representing the value (true, false, null, nan)
-#define TokenKeyOp      2300 // operators
+#include "CBot/CBotEnums.h"
 
 #define MAXDEFNUM 1000 // limited number of DefineNum
 
 /**
- * \class CBotToken
- * Responsible for token management. A CBot program is a text string. This string
- * is first transformed into a list of token. It will only treat the case as an
- * error where there is an illegal character in a string.
- * For example :
- *     int var = 3 * ( pos.y + x )
- *  is decomposed into (each line is a token)
- *      int
- *      var
- *      =
- *      3
- *      *
- *      (
- *      pos.y
- *      +
- *      x
- *      )
+ * \brief Class representing one token of a program.
+ *
+ * A CBot program starts as a text string. This string is first transformed into a list of tokens.
+ *
+ * \section Example Example
+ * This code:
+ * \code
+ *     int var = 3 * ( pos.y + x );
+ *     string test = "Hello world";
+ * \endcode
+ *
+ * Is decomposed into (each line is a token, separate CBotToken instance):
+ * \code
+ *     int
+ *     var
+ *     =
+ *     3
+ *     *
+ *     (
+ *     pos
+ *     .
+ *     y
+ *     +
+ *     x
+ *     )
+ *     ;
+ *     string
+ *     test
+ *     =
+ *     "Hello world"
+ *     ;
+ * \endcode
  */
 
 class CBotToken
@@ -204,7 +207,7 @@ private:
     //! The previous token in the linked list
     CBotToken* m_prev;
     //! The token type
-    int m_type; // type of Token
+    TokenType m_type; // type of Token
     //! The id of the keyword
     long m_IdKeyWord;
 
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 0a8b79e..0627be1 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -667,10 +667,6 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
         {
             color = Gfx::FONT_HIGHLIGHT_KEYWORD;
         }
-        else if (type >= TokenKeyDeclare && type < TokenKeyDeclare+100) // TODO: no idea :P seems to never happen
-        {
-            color = Gfx::FONT_HIGHLIGHT_TYPE;
-        }
         else if (type >= TokenKeyVal && type < TokenKeyVal+100) // true, false, null, nan
         {
             color = Gfx::FONT_HIGHLIGHT_CONST;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list