- extended refactor to EToken (now TokenType)

Wed, 12 Feb 2014 06:50:13 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 12 Feb 2014 06:50:13 +0200
changeset 110
7a7a53f1d51b
parent 109
6572803cd0ca
child 111
87d9ebd3ef34

- extended refactor to EToken (now TokenType)

namedenums/NamedEnumerations.cc file | annotate | diff | comparison | revisions
src/Expression.cc file | annotate | diff | comparison | revisions
src/Format.h file | annotate | diff | comparison | revisions
src/Lexer.cc file | annotate | diff | comparison | revisions
src/Lexer.h file | annotate | diff | comparison | revisions
src/LexerScanner.cc file | annotate | diff | comparison | revisions
src/LexerScanner.h file | annotate | diff | comparison | revisions
src/Main.cc file | annotate | diff | comparison | revisions
src/Parser.cc file | annotate | diff | comparison | revisions
src/Parser.h file | annotate | diff | comparison | revisions
src/Tokens.h file | annotate | diff | comparison | revisions
--- a/namedenums/NamedEnumerations.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/namedenums/NamedEnumerations.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -231,7 +231,7 @@
 
 			fprintf (fp, "};\n\n");
 
-			fprintf (fp, "inline const char* Get%sString( %s a )\n"
+			fprintf (fp, "inline const char* Get%sString (%s a)\n"
 				"{\n"
 				"\treturn g%sNames[a];\n"
 				"}\n",
--- a/src/Expression.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Expression.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -4,7 +4,7 @@
 
 struct OperatorInfo
 {
-	EToken		token;
+	TokenType	token;
 	int			priority;
 	int			numoperands;
 	DataHeader	header;
@@ -12,27 +12,27 @@
 
 static const OperatorInfo gOperators[] =
 {
-	{ tkExclamationMark,	0,		1,	DH_NegateLogical,	},
-	{ tkMinus,				0,		1,	DH_UnaryMinus,		},
-	{ tkMultiply,			10,		2,	DH_Multiply,		},
-	{ tkDivide,				10,		2,	DH_Divide,			},
-	{ tkModulus,			10,		2,	DH_Modulus,			},
-	{ tkPlus,				20,		2,	DH_Add,				},
-	{ tkMinus,				20,		2,	DH_Subtract,		},
-	{ tkLeftShift,			30,		2,	DH_LeftShift,		},
-	{ tkRightShift,			30,		2,	DH_RightShift,		},
-	{ tkLesser,				40,		2,	DH_LessThan,		},
-	{ tkGreater,			40,		2,	DH_GreaterThan,		},
-	{ tkAtLeast,			40,		2,	DH_AtLeast,			},
-	{ tkAtMost,				40,		2,	DH_AtMost,			},
-	{ tkEquals,				50,		2,	DH_Equals			},
-	{ tkNotEquals,			50,		2,	DH_NotEquals		},
-	{ tkAmperstand,			60,		2,	DH_AndBitwise		},
-	{ tkCaret,				70,		2,	DH_EorBitwise		},
-	{ tkBar,				80,		2,	DH_OrBitwise		},
-	{ tkDoubleAmperstand,	90,		2,	DH_AndLogical		},
-	{ tkDoubleBar,			100,	2,	DH_OrLogical		},
-	{ tkQuMARK_stion,		110,	3,	(DataHeader) 0		},
+	{TK_ExclamationMark,	0,		1,	DH_NegateLogical,	},
+	{TK_Minus,				0,		1,	DH_UnaryMinus,		},
+	{TK_Multiply,			10,		2,	DH_Multiply,		},
+	{TK_Divide,				10,		2,	DH_Divide,			},
+	{TK_Modulus,			10,		2,	DH_Modulus,			},
+	{TK_Plus,				20,		2,	DH_Add,				},
+	{TK_Minus,				20,		2,	DH_Subtract,		},
+	{TK_LeftShift,			30,		2,	DH_LeftShift,		},
+	{TK_RightShift,			30,		2,	DH_RightShift,		},
+	{TK_Lesser,				40,		2,	DH_LessThan,		},
+	{TK_Greater,			40,		2,	DH_GreaterThan,		},
+	{TK_AtLeast,			40,		2,	DH_AtLeast,			},
+	{TK_AtMost,				40,		2,	DH_AtMost,			},
+	{TK_Equals,				50,		2,	DH_Equals			},
+	{TK_NotEquals,			50,		2,	DH_NotEquals		},
+	{TK_Amperstand,			60,		2,	DH_AndBitwise		},
+	{TK_Caret,				70,		2,	DH_EorBitwise		},
+	{TK_Bar,				80,		2,	DH_OrBitwise		},
+	{TK_DoubleAmperstand,	90,		2,	DH_AndLogical		},
+	{TK_DoubleBar,			100,	2,	DH_OrLogical		},
+	{TK_QuestionMark,		110,	3,	(DataHeader) 0		},
 };
 
 // =============================================================================
@@ -76,7 +76,7 @@
 	int pos = mLexer->GetPosition();
 	ExpressionValue* op = null;
 
-	if (mLexer->GetNext (tkColon))
+	if (mLexer->GetNext (TK_Colon))
 		return new ExpressionColon;
 
 	// Check for OPER_erator
@@ -85,10 +85,10 @@
 			return new ExpressionOperator ((ExpressionOperatorType) (&op - &gOperators[0]));
 
 	// Check sub-expression
-	if (mLexer->GetNext (tkParenStart))
+	if (mLexer->GetNext (TK_ParenStart))
 	{
 		Expression expr (mParser, mLexer, mType);
-		mLexer->MustGetNext (tkParenEnd);
+		mLexer->MustGetNext (TK_ParenEnd);
 		return expr.GetResult()->Clone();
 	}
 
@@ -107,9 +107,9 @@
 	}
 
 	// Check for variables
-	if (mLexer->GetNext (tkDollarSign))
+	if (mLexer->GetNext (TK_DollarSign))
 	{
-		mLexer->MustGetNext (tkSymbol);
+		mLexer->MustGetNext (TK_Symbol);
 		Variable* var = mParser->FindVariable (GetTokenString());
 
 		if (var == null)
@@ -121,14 +121,14 @@
 
 		if (var->isarray)
 		{
-			mLexer->MustGetNext (tkBracketStart);
+			mLexer->MustGetNext (TK_BracketStart);
 			Expression expr (mParser, mLexer, TYPE_Int);
 			expr.GetResult()->ConvertToBuffer();
 			DataBuffer* buf = expr.GetResult()->GetBuffer()->Clone();
 			buf->WriteDWord (DH_PushGlobalArray);
 			buf->WriteDWord (var->index);
 			op->SetBuffer (buf);
-			mLexer->MustGetNext (tkBracketEnd);
+			mLexer->MustGetNext (TK_BracketEnd);
 		}
 		elif (var->writelevel == WRITE_Constexpr)
 			op->SetValue (var->value);
@@ -160,17 +160,17 @@
 
 		case TYPE_Bool:
 		{
-			if (mLexer->GetNext (tkTrue) || mLexer->GetNext (tkFalse))
+			if (mLexer->GetNext (TK_True) || mLexer->GetNext (TK_False))
 			{
-				EToken tt = mLexer->GetTokenType();
-				op->SetValue (tt == tkTrue ? 1 : 0);
+				TokenType tt = mLexer->GetTokenType();
+				op->SetValue (tt ==TK_True ? 1 : 0);
 				return op;
 			}
 		}
 
 		case TYPE_Int:
 		{
-			if (mLexer->GetNext (tkNumber))
+			if (mLexer->GetNext (TK_Number))
 			{
 				op->SetValue (GetTokenString().ToLong());
 				return op;
@@ -179,7 +179,7 @@
 
 		case TYPE_String:
 		{
-			if (mLexer->GetNext (tkString))
+			if (mLexer->GetNext (TK_String))
 			{
 				op->SetValue (GetStringTableIndex (GetTokenString()));
 				return op;
@@ -197,7 +197,7 @@
 //
 // The symbol parsing process only does token-based checking for OPER_erators. Thus
 // ALL minus OPER_erators are actually unary minuses simply because both have
-// tkMinus as their token and the unary minus is prior to the binary minus in
+//TK_Minus as their token and the unary minus is prior to the binary minus in
 // the OPER_erator table. Now that we have all symbols present, we can correct
 // cases like this.
 //
--- a/src/Format.h	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Format.h	Wed Feb 12 06:50:13 2014 +0200
@@ -115,8 +115,8 @@
 
 #ifndef IN_IDE_PARSER
 # ifdef DEBUG
-#  define devf(...) fprint (stderr, __VA_ARGS__)
-#  define dvalof( A ) fprint (stderr, "value of '%1' = %2\n", #A, A)
+#  define devf(...) PrintTo (stderr, __VA_ARGS__)
+#  define dvalof( A ) PrintTo (stderr, "value of '%1' = %2\n", #A, A)
 # else
 #  define devf(...)
 #  define dvalof( A )
--- a/src/Lexer.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Lexer.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -63,13 +63,13 @@
 	while (sc.GetNextToken())
 	{
 		// Preprocessor commands:
-		if (sc.GetTokenType() == tkHash)
+		if (sc.GetTokenType() ==TK_Hash)
 		{
-			MustGetFromScanner (sc, tkSymbol);
+			MustGetFromScanner (sc,TK_Symbol);
 
 			if (sc.GetTokenText() == "include")
 			{
-				MustGetFromScanner (sc, tkString);
+				MustGetFromScanner (sc,TK_String);
 				String fileName = sc.GetTokenText();
 
 				if (gFileNameStack.Contains (fileName))
@@ -89,8 +89,9 @@
 			tok.type = sc.GetTokenType();
 			tok.text = sc.GetTokenText();
 
-			// devf ("Token #%1: %2:%3:%4: %5 (%6)\n", mTokens.size(),
-			//	tok.file, tok.line, tok.column, DescribeToken (&tok), DescribeTokenType (tok.type));
+			// devf ("Token #%1: %2:%3:%4: %5 (%6)\n", mTokens.Size(),
+			// 	tok.file, tok.line, tok.column, DescribeToken (&tok),
+			// 	GetTokenTypeString (tok.type));
 
 			mTokens << tok;
 		}
@@ -144,7 +145,7 @@
 
 // =============================================================================
 //
-bool Lexer::GetNext (EToken req)
+bool Lexer::GetNext (TokenType req)
 {
 	Iterator pos = mTokenPosition;
 
@@ -153,7 +154,7 @@
 
 	mTokenPosition++;
 
-	if (IsAtEnd() || (req != tkAny && GetTokenType() != req))
+	if (IsAtEnd() || (req !=TK_Any && GetTokenType() != req))
 	{
 		mTokenPosition = pos;
 		return false;
@@ -164,24 +165,24 @@
 
 // =============================================================================
 //
-void Lexer::MustGetNext (EToken tok)
+void Lexer::MustGetNext (TokenType tok)
 {
 	if (!GetNext())
 		Error ("unexpected EOF");
 
-	if (tok != tkAny)
+	if (tok !=TK_Any)
 		TokenMustBe (tok);
 }
 
 // =============================================================================
 // eugh..
 //
-void Lexer::MustGetFromScanner (LexerScanner& sc, EToken tt)
+void Lexer::MustGetFromScanner (LexerScanner& sc, TokenType tt)
 {
 	if (!sc.GetNextToken())
 		Error ("unexpected EOF");
 
-	if (tt != tkAny && sc.GetTokenType() != tt)
+	if (tt !=TK_Any && sc.GetTokenType() != tt)
 	{
 		// TODO
 		Token tok;
@@ -198,18 +199,18 @@
 
 // =============================================================================
 //
-void Lexer::MustGetAnyOf (const List<EToken>& toks)
+void Lexer::MustGetAnyOf (const List<TokenType>& toks)
 {
 	if (!GetNext())
 		Error ("unexpected EOF");
 
-	for (EToken tok : toks)
+	for (TokenType tok : toks)
 		if (GetTokenType() == tok)
 			return;
 
 	String toknames;
 
-	for (const EToken& tokType : toks)
+	for (const TokenType& tokType : toks)
 	{
 		if (&tokType == &toks.Last())
 			toknames += " or ";
@@ -224,12 +225,12 @@
 
 // =============================================================================
 //
-int Lexer::GEXPRSYM_tOne (const StringList& syms)
+int Lexer::GetOneSymbol (const StringList& syms)
 {
 	if (!GetNext())
 		Error ("unexpected EOF");
 
-	if (GetTokenType() == tkSymbol)
+	if (GetTokenType() ==TK_Symbol)
 	{
 		for (int i = 0; i < syms.Size(); ++i)
 		{
@@ -244,7 +245,7 @@
 
 // =============================================================================
 //
-void Lexer::TokenMustBe (EToken tok)
+void Lexer::TokenMustBe (TokenType tok)
 {
 	if (GetTokenType() != tok)
 		Error ("expected %1, got %2", DescribeTokenType (tok),
@@ -253,17 +254,17 @@
 
 // =============================================================================
 //
-String Lexer::DescribeTokenPrivate (EToken tokType, Lexer::Token* tok)
+String Lexer::DescribeTokenPrivate (TokenType tokType, Lexer::Token* tok)
 {
-	if (tokType < tkLastNamedToken)
+	if (tokType <gLastNamedToken)
 		return "\"" + LexerScanner::GetTokenString (tokType) + "\"";
 
 	switch (tokType)
 	{
-		case tkSymbol:	return tok ? tok->text : "a symbol";
-		case tkNumber:	return tok ? tok->text : "a number";
-		case tkString:	return tok ? ("\"" + tok->text + "\"") : "a string";
-		case tkAny:	return tok ? tok->text : "any token";
+		case TK_Symbol:	return tok ? tok->text : "a symbol";
+		case TK_Number:	return tok ? tok->text : "a number";
+		case TK_String:	return tok ? ("\"" + tok->text + "\"") : "a string";
+		case TK_Any:	return tok ? tok->text : "any token";
 		default: break;
 	}
 
@@ -286,7 +287,7 @@
 
 // =============================================================================
 //
-bool Lexer::PeekNextType (EToken req)
+bool Lexer::PeekNextType (TokenType req)
 {
 	Iterator pos = mTokenPosition;
 	bool result = false;
--- a/src/Lexer.h	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Lexer.h	Wed Feb 12 06:50:13 2014 +0200
@@ -37,7 +37,7 @@
 types:
 	struct Token
 	{
-		EToken		type;
+		TokenType	type;
 		String		text;
 		String		file;
 		int			line;
@@ -52,13 +52,13 @@
 	~Lexer();
 
 	void	ProcessFile (String file_name);
-	bool	GetNext (EToken req = tkAny);
-	void	MustGetNext (EToken tok);
-	void	MustGetAnyOf (const List<EToken>& toks);
-	int		GEXPRSYM_tOne (const StringList& syms);
-	void	TokenMustBe (EToken tok);
+	bool	GetNext (TokenType req = TK_Any);
+	void	MustGetNext (TokenType tok);
+	void	MustGetAnyOf (const List<TokenType>& toks);
+	int		GetOneSymbol (const StringList& syms);
+	void	TokenMustBe (TokenType tok);
 	bool	PeekNext (Token* tk = null);
-	bool	PeekNextType (EToken req);
+	bool	PeekNextType (TokenType req);
 	String	PeekNextString (int a = 1);
 	String	DescribeCurrentPosition();
 	String	DescribeTokenPosition();
@@ -81,7 +81,7 @@
 		return mTokenPosition == mTokens.end();
 	}
 
-	inline EToken GetTokenType() const
+	inline TokenType GetTokenType() const
 	{
 		return GetToken()->type;
 	}
@@ -102,7 +102,7 @@
 	}
 
 	// If @tok is given, describes the token. If not, describes @tok_type.
-	static inline String DescribeTokenType (EToken toktype)
+	static inline String DescribeTokenType (TokenType toktype)
 	{
 		return DescribeTokenPrivate (toktype, null);
 	}
@@ -117,10 +117,10 @@
 	Iterator		mTokenPosition;
 
 	// read a mandatory token from scanner
-	void MustGetFromScanner (LexerScanner& sc, EToken tt = tkAny);
+	void MustGetFromScanner (LexerScanner& sc, TokenType tt =TK_Any);
 	void CheckFileHeader (LexerScanner& sc);
 
-	static String DescribeTokenPrivate (EToken tok_type, Token* tok);
+	static String DescribeTokenPrivate (TokenType tok_type, Token* tok);
 };
 
 #endif // BOTC_LEXER_H
--- a/src/LexerScanner.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/LexerScanner.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -111,7 +111,7 @@
 	"return",
 };
 
-static_assert (countof (gTokenStrings) == (int) tkLastNamedToken + 1,
+static_assert (countof (gTokenStrings) == (int)gLastNamedToken + 1,
 	"Count of gTokenStrings is not the same as the amount of named token identifiers.");
 
 // =============================================================================
@@ -192,13 +192,13 @@
 	{
 		int flags = 0;
 
-		if (i >= tkFirstNamedToken)
+		if (i >= gFirstNamedToken)
 			flags |= FCheckWord;
 
 		if (CheckString (gTokenStrings[i], flags))
 		{
 			mTokenText = gTokenStrings[i];
-			mTokenType = (EToken) i;
+			mTokenType = (TokenType) i;
 			return true;
 		}
 	}
@@ -232,7 +232,7 @@
 			mTokenText += *mPosition++;
 		}
 
-		mTokenType = tkString;
+		mTokenType =TK_String;
 		Skip(); // skip the final quote
 		return true;
 	}
@@ -242,13 +242,13 @@
 		while (isdigit (*mPosition))
 			mTokenText += *mPosition++;
 
-		mTokenType = tkNumber;
+		mTokenType =TK_Number;
 		return true;
 	}
 
 	if (IsSymbolChar (*mPosition, false))
 	{
-		mTokenType = tkSymbol;
+		mTokenType =TK_Symbol;
 
 		do
 		{
@@ -288,9 +288,9 @@
 
 // =============================================================================
 //
-String LexerScanner::GetTokenString (EToken a)
+String LexerScanner::GetTokenString (TokenType a)
 {
-	assert ((int) a <= tkLastNamedToken);
+	assert ((int) a <= gLastNamedToken);
 	return gTokenStrings[a];
 }
 
--- a/src/LexerScanner.h	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/LexerScanner.h	Wed Feb 12 06:50:13 2014 +0200
@@ -80,12 +80,12 @@
 			return mPosition - mLineBreakPosition;
 		}
 
-		inline EToken GetTokenType() const
+		inline TokenType GetTokenType() const
 		{
 			return mTokenType;
 		}
 
-		static String GetTokenString (EToken a);
+		static String GetTokenString (TokenType a);
 
 	private:
 		char*			mData;
@@ -93,7 +93,7 @@
 		char*			mLineBreakPosition;
 		String			mTokenText,
 						mLastToken;
-		EToken			mTokenType;
+		TokenType		mTokenType;
 		int				mLine;
 
 		bool			CheckString (const char* c, int flags = 0);
--- a/src/Main.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Main.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -34,7 +34,6 @@
 #include "Parser.h"
 #include "Lexer.h"
 #include "GitInformation.h"
-#include "EnumStrings.h"
 
 int main (int argc, char** argv)
 {
--- a/src/Parser.cc	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Parser.cc	Wed Feb 12 06:50:13 2014 +0200
@@ -93,92 +93,92 @@
 	while (mLexer->GetNext())
 	{
 		// Check if else is potentically valid
-		if (TokenIs (tkElse) && mCanElse == false)
+		if (TokenIs (TK_Else) && mCanElse == false)
 			Error ("else without preceding if");
 
-		if (TokenIs (tkElse) == false)
+		if (TokenIs (TK_Else) == false)
 			mCanElse = false;
 
 		switch (mLexer->GetToken()->type)
 		{
-			case tkState:
+			case TK_State:
 				ParseStateBlock();
 				break;
 
-			case tkEvent:
+			case TK_Event:
 				ParseEventBlock();
 				break;
 
-			case tkMainloop:
+			case TK_Mainloop:
 				ParseMainloop();
 				break;
 
-			case tkOnenter:
-			case tkOnexit:
+			case TK_Onenter:
+			case TK_Onexit:
 				ParseOnEnterExit();
 				break;
 
-			case tkVar:
+			case TK_Var:
 				ParseVar();
 				break;
 
-			case tkGoto:
+			case TK_Goto:
 				ParseGoto();
 				break;
 
-			case tkIf:
+			case TK_If:
 				ParseIf();
 				break;
 
-			case tkElse:
+			case TK_Else:
 				ParseElse();
 				break;
 
-			case tkWhile:
+			case TK_While:
 				ParseWhileBlock();
 				break;
 
-			case tkFor:
+			case TK_For:
 				ParseForBlock();
 				break;
 
-			case tkDo:
+			case TK_Do:
 				ParseDoBlock();
 				break;
 
-			case tkSwitch:
+			case TK_Switch:
 				ParseSwitchBlock();
 				break;
 
-			case tkCase:
+			case TK_Case:
 				ParseSwitchCase();
 				break;
 
-			case tkDefault:
+			case TK_Default:
 				ParseSwitchDefault();
 				break;
 
-			case tkBreak:
+			case TK_Break:
 				ParseBreak();
 				break;
 
-			case tkContinue:
+			case TK_Continue:
 				ParseContinue();
 				break;
 
-			case tkBraceEnd:
+			case TK_BraceEnd:
 				ParseBlockEnd();
 				break;
 
-			case tkEventdef:
+			case TK_Eventdef:
 				ParseEventdef();
 				break;
 
-			case tkFuncdef:
+			case TK_Funcdef:
 				ParseFuncdef();
 				break;
 
-			case tkSemicolon:
+			case TK_Semicolon:
 				break;
 
 			default:
@@ -186,9 +186,9 @@
 				// Check for labels
 				Lexer::Token next;
 
-				if (TokenIs (tkSymbol) &&
+				if (TokenIs (TK_Symbol) &&
 					mLexer->PeekNext (&next) &&
-					next.type == tkColon)
+					next.type ==TK_Colon)
 				{
 					ParseLabel();
 					break;
@@ -200,7 +200,7 @@
 				if (comm)
 				{
 					buffer()->MergeAndDestroy (ParseCommand (comm));
-					mLexer->MustGetNext (tkSemicolon);
+					mLexer->MustGetNext (TK_Semicolon);
 					continue;
 				}
 
@@ -215,7 +215,7 @@
 				}
 
 				buffer()->MergeAndDestroy (b);
-				mLexer->MustGetNext (tkSemicolon);
+				mLexer->MustGetNext (TK_Semicolon);
 				break;
 			}
 		}
@@ -256,7 +256,7 @@
 void BotscriptParser::ParseStateBlock()
 {
 	CheckToplevel();
-	mLexer->MustGetNext (tkString);
+	mLexer->MustGetNext (TK_String);
 	String statename = GetTokenString();
 
 	// State name must be a word.
@@ -269,7 +269,7 @@
 		mStateSpawnDefined = true;
 
 	// Must end in a colon
-	mLexer->MustGetNext (tkColon);
+	mLexer->MustGetNext (TK_Colon);
 
 	// write the previous state's onenter and
 	// mainloop buffers to file now
@@ -291,14 +291,14 @@
 void BotscriptParser::ParseEventBlock()
 {
 	CheckToplevel();
-	mLexer->MustGetNext (tkString);
+	mLexer->MustGetNext (TK_String);
 
 	EventDefinition* e = FindEventByName (GetTokenString());
 
 	if (e == null)
 		Error ("bad event, got `%1`\n", GetTokenString());
 
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_BraceStart);
 	mCurrentMode = PARSERMODE_Event;
 	buffer()->WriteDWord (DH_Event);
 	buffer()->WriteDWord (e->number);
@@ -310,7 +310,7 @@
 void BotscriptParser::ParseMainloop()
 {
 	CheckToplevel();
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_BraceStart);
 
 	mCurrentMode = PARSERMODE_MainLoop;
 	mMainLoopBuffer->WriteDWord (DH_MainLoop);
@@ -321,8 +321,8 @@
 void BotscriptParser::ParseOnEnterExit()
 {
 	CheckToplevel();
-	bool onenter = (TokenIs (tkOnenter));
-	mLexer->MustGetNext (tkBraceStart);
+	bool onenter = (TokenIs (TK_Onenter));
+	mLexer->MustGetNext (TK_BraceStart);
 
 	mCurrentMode = onenter ? PARSERMODE_Onenter : PARSERMODE_Onexit;
 	buffer()->WriteDWord (onenter ? DH_OnEnter : DH_OnExit);
@@ -335,19 +335,19 @@
 	Variable* var = new Variable;
 	var->origin = mLexer->DescribeCurrentPosition();
 	var->isarray = false;
-	const bool isconst = mLexer->GetNext (tkConst);
-	mLexer->MustGetAnyOf ({tkInt, tkStr, tkVoid});
+	const bool isconst = mLexer->GetNext (TK_Const);
+	mLexer->MustGetAnyOf ({TK_Int,TK_Str,TK_Void});
 
-	DataType vartype =	(TokenIs (tkInt)) ? TYPE_Int :
-					(TokenIs (tkStr)) ? TYPE_String :
+	DataType vartype =	(TokenIs (TK_Int)) ? TYPE_Int :
+					(TokenIs (TK_Str)) ? TYPE_String :
 					TYPE_Bool;
 
-	mLexer->MustGetNext (tkSymbol);
+	mLexer->MustGetNext (TK_Symbol);
 	String name = GetTokenString();
 
-	if (mLexer->GetNext (tkBracketStart))
+	if (mLexer->GetNext (TK_BracketStart))
 	{
-		mLexer->MustGetNext (tkBracketEnd);
+		mLexer->MustGetNext (TK_BracketEnd);
 		var->isarray = true;
 
 		if (isconst)
@@ -371,7 +371,7 @@
 	}
 	else
 	{
-		mLexer->MustGetNext (tkAssign);
+		mLexer->MustGetNext (TK_Assign);
 		Expression expr (this, mLexer, vartype);
 
 		// If the expression was constexpr, we know its value and thus
@@ -409,7 +409,7 @@
 		SCOPE(0).localVariables << var;
 
 	SuggestHighestVarIndex (IsInGlobalState(), var->index);
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 	Print ("Declared %3 variable #%1 $%2\n", var->index, var->name, IsInGlobalState() ? "global" : "state-local");
 }
 
@@ -420,7 +420,7 @@
 	CheckNotToplevel();
 
 	// Get the name of the label
-	mLexer->MustGetNext (tkSymbol);
+	mLexer->MustGetNext (TK_Symbol);
 
 	// Find the mark this goto statement points to
 	String target = GetTokenString();
@@ -438,7 +438,7 @@
 	// Add a reference to the mark.
 	buffer()->WriteDWord (DH_Goto);
 	buffer()->AddReference (mark);
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 }
 
 // ============================================================================
@@ -449,14 +449,14 @@
 	PushScope();
 
 	// Condition
-	mLexer->MustGetNext (tkParenStart);
+	mLexer->MustGetNext (TK_ParenStart);
 
 	// Read the expression and write it.
 	DataBuffer* c = ParseExpression (TYPE_Int);
 	buffer()->MergeAndDestroy (c);
 
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_BraceStart);
 
 	// Add a mark - to here temporarily - and add a reference to it.
 	// Upon a closing brace, the mark will be adjusted.
@@ -477,7 +477,7 @@
 void BotscriptParser::ParseElse()
 {
 	CheckNotToplevel();
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_BraceStart);
 	PushScope (eNoReset);
 
 	if (SCOPE (0).type != SCOPE_If)
@@ -511,10 +511,10 @@
 	ByteMark* mark2 = buffer()->AddMark (""); // end
 
 	// Condition
-	mLexer->MustGetNext (tkParenStart);
+	mLexer->MustGetNext (TK_ParenStart);
 	DataBuffer* expr = ParseExpression (TYPE_Int);
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_BraceStart);
 
 	// write condition
 	buffer()->MergeAndDestroy (expr);
@@ -537,13 +537,13 @@
 	PushScope();
 
 	// Initializer
-	mLexer->MustGetNext (tkParenStart);
+	mLexer->MustGetNext (TK_ParenStart);
 	DataBuffer* init = ParseStatement();
 
 	if (init == null)
 		Error ("bad statement for initializer of for");
 
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 
 	// Condition
 	DataBuffer* cond = ParseExpression (TYPE_Int);
@@ -551,7 +551,7 @@
 	if (cond == null)
 		Error ("bad statement for condition of for");
 
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 
 	// Incrementor
 	DataBuffer* incr = ParseStatement();
@@ -559,8 +559,8 @@
 	if (incr == null)
 		Error ("bad statement for incrementor of for");
 
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_BraceStart);
 
 	// First, write out the initializer
 	buffer()->MergeAndDestroy (init);
@@ -587,7 +587,7 @@
 {
 	CheckNotToplevel();
 	PushScope();
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_BraceStart);
 	SCOPE (0).mark1 = buffer()->AddMark ("");
 	SCOPE (0).type = SCOPE_Do;
 }
@@ -611,10 +611,10 @@
 
 	CheckNotToplevel();
 	PushScope();
-	mLexer->MustGetNext (tkParenStart);
+	mLexer->MustGetNext (TK_ParenStart);
 	buffer()->MergeAndDestroy (ParseExpression (TYPE_Int));
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkBraceStart);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_BraceStart);
 	SCOPE (0).type = SCOPE_Switch;
 	SCOPE (0).mark1 = buffer()->AddMark (""); // end mark
 	SCOPE (0).buffer1 = null; // default header
@@ -630,9 +630,9 @@
 
 	// Get a literal value for the case block. Zandronum does not support
 	// expressions here.
-	mLexer->MustGetNext (tkNumber);
+	mLexer->MustGetNext (TK_Number);
 	int num = mLexer->GetToken()->text.ToLong();
-	mLexer->MustGetNext (tkColon);
+	mLexer->MustGetNext (TK_Colon);
 
 	for (const CaseInfo& info : SCOPE(0).cases)
 		if (info.number == num)
@@ -665,7 +665,7 @@
 	if (SCOPE (0).buffer1 != null)
 		Error ("multiple default labels in one switch");
 
-	mLexer->MustGetNext (tkColon);
+	mLexer->MustGetNext (TK_Colon);
 
 	// The default header is buffered into buffer1, since
 	// it has to be the last of the case headers
@@ -712,14 +712,14 @@
 		} break;
 	}
 
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 }
 
 // ============================================================================
 //
 void BotscriptParser::ParseContinue()
 {
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_Semicolon);
 
 	int curs;
 	bool found = false;
@@ -792,11 +792,11 @@
 
 			case SCOPE_Do:
 			{
-				mLexer->MustGetNext (tkWhile);
-				mLexer->MustGetNext (tkParenStart);
+				mLexer->MustGetNext (TK_While);
+				mLexer->MustGetNext (TK_ParenStart);
 				DataBuffer* expr = ParseExpression (TYPE_Int);
-				mLexer->MustGetNext (tkParenEnd);
-				mLexer->MustGetNext (tkSemicolon);
+				mLexer->MustGetNext (TK_ParenEnd);
+				mLexer->MustGetNext (TK_Semicolon);
 
 				// If the condition runs true, go back to the start.
 				buffer()->MergeAndDestroy (expr);
@@ -861,7 +861,7 @@
 	// the closing data headers into said buffers too.
 	buffer()->WriteDWord (dataheader);
 	mCurrentMode = PARSERMODE_TopLevel;
-	mLexer->GetNext (tkSemicolon);
+	mLexer->GetNext (TK_Semicolon);
 }
 
 // ============================================================================
@@ -890,7 +890,7 @@
 	if (mark == null)
 		buffer()->AddMark (labelName);
 
-	mLexer->MustGetNext (tkColon);
+	mLexer->MustGetNext (TK_Colon);
 }
 
 // =============================================================================
@@ -899,14 +899,14 @@
 {
 	EventDefinition* e = new EventDefinition;
 
-	mLexer->MustGetNext (tkNumber);
+	mLexer->MustGetNext (TK_Number);
 	e->number = GetTokenString().ToLong();
-	mLexer->MustGetNext (tkColon);
-	mLexer->MustGetNext (tkSymbol);
+	mLexer->MustGetNext (TK_Colon);
+	mLexer->MustGetNext (TK_Symbol);
 	e->name = mLexer->GetToken()->text;
-	mLexer->MustGetNext (tkParenStart);
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_ParenStart);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_Semicolon);
 	AddEvent (e);
 }
 
@@ -918,47 +918,47 @@
 	comm->origin = mLexer->DescribeCurrentPosition();
 
 	// Return value
-	mLexer->MustGetAnyOf ({tkInt, tkVoid, tkBool, tkStr});
+	mLexer->MustGetAnyOf ({TK_Int,TK_Void,TK_Bool,TK_Str});
 	comm->returnvalue = GetTypeByName (mLexer->GetToken()->text); // TODO
 	assert (comm->returnvalue != -1);
 
 	// Number
-	mLexer->MustGetNext (tkNumber);
+	mLexer->MustGetNext (TK_Number);
 	comm->number = mLexer->GetToken()->text.ToLong();
-	mLexer->MustGetNext (tkColon);
+	mLexer->MustGetNext (TK_Colon);
 
 	// Name
-	mLexer->MustGetNext (tkSymbol);
+	mLexer->MustGetNext (TK_Symbol);
 	comm->name = mLexer->GetToken()->text;
 
 	// Arguments
-	mLexer->MustGetNext (tkParenStart);
+	mLexer->MustGetNext (TK_ParenStart);
 	comm->minargs = 0;
 
-	while (mLexer->PeekNextType (tkParenEnd) == false)
+	while (mLexer->PeekNextType (TK_ParenEnd) == false)
 	{
 		if (comm->args.IsEmpty() == false)
-			mLexer->MustGetNext (tkComma);
+			mLexer->MustGetNext (TK_Comma);
 
 		CommandArgument arg;
-		mLexer->MustGetAnyOf ({tkInt, tkBool, tkStr});
+		mLexer->MustGetAnyOf ({TK_Int,TK_Bool,TK_Str});
 		DataType type = GetTypeByName (mLexer->GetToken()->text); // TODO
 		assert (type != -1 && type != TYPE_Void);
 		arg.type = type;
 
-		mLexer->MustGetNext (tkSymbol);
+		mLexer->MustGetNext (TK_Symbol);
 		arg.name = mLexer->GetToken()->text;
 
 		// If this is an optional parameter, we need the default value.
-		if (comm->minargs < comm->args.Size() || mLexer->PeekNextType (tkAssign))
+		if (comm->minargs < comm->args.Size() || mLexer->PeekNextType (TK_Assign))
 		{
-			mLexer->MustGetNext (tkAssign);
+			mLexer->MustGetNext (TK_Assign);
 
 			switch (type)
 			{
 				case TYPE_Int:
 				case TYPE_Bool:
-					mLexer->MustGetNext (tkNumber);
+					mLexer->MustGetNext (TK_Number);
 					break;
 
 				case TYPE_String:
@@ -977,8 +977,8 @@
 		comm->args << arg;
 	}
 
-	mLexer->MustGetNext (tkParenEnd);
-	mLexer->MustGetNext (tkSemicolon);
+	mLexer->MustGetNext (TK_ParenEnd);
+	mLexer->MustGetNext (TK_Semicolon);
 	AddCommandDefinition (comm);
 }
 
@@ -991,14 +991,14 @@
 	if (mCurrentMode == PARSERMODE_TopLevel && comm->returnvalue == TYPE_Void)
 		Error ("command call at top level");
 
-	mLexer->MustGetNext (tkParenStart);
-	mLexer->MustGetNext (tkAny);
+	mLexer->MustGetNext (TK_ParenStart);
+	mLexer->MustGetNext (TK_Any);
 
 	int curarg = 0;
 
 	for (;;)
 	{
-		if (TokenIs (tkParenEnd))
+		if (TokenIs (TK_ParenEnd))
 		{
 			if (curarg < comm->minargs)
 				Error ("too few arguments passed to %1\n\tusage is: %2",
@@ -1012,25 +1012,25 @@
 				comm->name, comm->GetSignature());
 
 		r->MergeAndDestroy (ParseExpression (comm->args[curarg].type, true));
-		mLexer->MustGetNext (tkAny);
+		mLexer->MustGetNext (TK_Any);
 
 		if (curarg < comm->minargs - 1)
 		{
-			mLexer->TokenMustBe (tkComma);
-			mLexer->MustGetNext (tkAny);
+			mLexer->TokenMustBe (TK_Comma);
+			mLexer->MustGetNext (TK_Any);
 		}
 		else if (curarg < comm->args.Size() - 1)
 		{
 			// Can continue, but can terminate as well.
-			if (TokenIs (tkParenEnd))
+			if (TokenIs (TK_ParenEnd))
 			{
 				curarg++;
 				break;
 			}
 			else
 			{
-				mLexer->TokenMustBe (tkComma);
-				mLexer->MustGetNext (tkAny);
+				mLexer->TokenMustBe (TK_Comma);
+				mLexer->MustGetNext (TK_Any);
 			}
 		}
 
@@ -1056,15 +1056,15 @@
 //
 String BotscriptParser::ParseFloat()
 {
-	mLexer->TokenMustBe (tkNumber);
+	mLexer->TokenMustBe (TK_Number);
 	String floatstring = GetTokenString();
 	Lexer::Token tok;
 
 	// Go after the decimal point
-	if (mLexer->PeekNext (&tok) && tok.type == tkDot)
+	if (mLexer->PeekNext (&tok) && tok.type ==TK_Dot)
 	{
 		mLexer->Skip();
-		mLexer->MustGetNext (tkNumber);
+		mLexer->MustGetNext (TK_Number);
 		floatstring += ".";
 		floatstring += GetTokenString();
 	}
@@ -1078,30 +1078,30 @@
 //
 AssignmentOperator BotscriptParser::ParseAssignmentOperator()
 {
-	const List<EToken> tokens =
+	const List<TokenType> tokens =
 	{
-		tkAssign,
-		tkAddAssign,
-		tkSubAssign,
-		tkMultiplyAssign,
-		tkDivideAssign,
-		tkModulusAssign,
-		tkDoublePlus,
-		tkDoubleMinus,
+		TK_Assign,
+		TK_AddAssign,
+		TK_SubAssign,
+		TK_MultiplyAssign,
+		TK_DivideAssign,
+		TK_ModulusAssign,
+		TK_DoublePlus,
+		TK_DoubleMinus,
 	};
 
 	mLexer->MustGetAnyOf (tokens);
 
 	switch (mLexer->GetTokenType())
 	{
-		case tkAssign:			return ASSIGNOP_Assign;
-		case tkAddAssign:		return ASSIGNOP_Add;
-		case tkSubAssign:		return ASSIGNOP_Subtract;
-		case tkMultiplyAssign:	return ASSIGNOP_Multiply;
-		case tkDivideAssign:	return ASSIGNOP_Divide;
-		case tkModulusAssign:	return ASSIGNOP_Modulus;
-		case tkDoublePlus:		return ASSIGNOP_Increase;
-		case tkDoubleMinus:		return ASSIGNOP_Decrease;
+		case TK_Assign:			return ASSIGNOP_Assign;
+		case TK_AddAssign:		return ASSIGNOP_Add;
+		case TK_SubAssign:		return ASSIGNOP_Subtract;
+		case TK_MultiplyAssign:	return ASSIGNOP_Multiply;
+		case TK_DivideAssign:	return ASSIGNOP_Divide;
+		case TK_ModulusAssign:	return ASSIGNOP_Modulus;
+		case TK_DoublePlus:		return ASSIGNOP_Increase;
+		case TK_DoubleMinus:	return ASSIGNOP_Decrease;
 		default: break;
 	}
 
@@ -1167,11 +1167,11 @@
 
 	if (var->isarray)
 	{
-		mLexer->MustGetNext (tkBracketStart);
+		mLexer->MustGetNext (TK_BracketStart);
 		Expression expr (this, mLexer, TYPE_Int);
 		expr.GetResult()->ConvertToBuffer();
 		arrayindex = expr.GetResult()->GetBuffer()->Clone();
-		mLexer->MustGetNext (tkBracketEnd);
+		mLexer->MustGetNext (TK_BracketEnd);
 	}
 
 	// Get an operator
@@ -1264,9 +1264,9 @@
 DataBuffer* BotscriptParser::ParseStatement()
 {
 	// If it's a variable, expect assignment.
-	if (mLexer->GetNext (tkDollarSign))
+	if (mLexer->GetNext (TK_DollarSign))
 	{
-		mLexer->MustGetNext (tkSymbol);
+		mLexer->MustGetNext (TK_Symbol);
 		Variable* var = FindVariable (GetTokenString());
 
 		if (var == null)
@@ -1305,7 +1305,7 @@
 
 // ============================================================================
 //
-bool BotscriptParser::TokenIs (EToken a)
+bool BotscriptParser::TokenIs (TokenType a)
 {
 	return (mLexer->GetTokenType() == a);
 }
--- a/src/Parser.h	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Parser.h	Wed Feb 12 06:50:13 2014 +0200
@@ -184,7 +184,7 @@
 		void					AddSwitchCase (DataBuffer* b);
 		void					CheckToplevel();
 		void					CheckNotToplevel();
-		bool					TokenIs (EToken a);
+		bool					TokenIs (TokenType a);
 		String					GetTokenString();
 		String					DescribePosition() const;
 		void					WriteToFile (String outfile);
--- a/src/Tokens.h	Wed Feb 12 06:33:16 2014 +0200
+++ b/src/Tokens.h	Wed Feb 12 06:50:13 2014 +0200
@@ -30,100 +30,101 @@
 #define TOKENS_H
 
 #include <climits>
+#include "Macros.h"
 
 // =======================================================
-enum EToken
+named_enum TokenType
 {
 	// Non-word tokens
-	tkLeftShiftAssign,
-	tkRightShiftAssign,
-	tkEquals,
-	tkNotEquals,
-	tkAddAssign,
-	tkSubAssign,
-	tkMultiplyAssign,
-	tkDivideAssign,
-	tkModulusAssign,
-	tkLeftShift,
-	tkRightShift,
-	tkAtLeast,
-	tkAtMost,
-	tkDoubleAmperstand,
-	tkDoubleBar,
-	tkDoublePlus,
-	tkDoubleMinus,
-	tkSingleQuote,
-	tkDollarSign,
-	tkParenStart,
-	tkParenEnd,
-	tkBracketStart,
-	tkBracketEnd,
-	tkBraceStart,
-	tkBraceEnd,
-	tkAssign,
-	tkPlus,
-	tkMinus,
-	tkMultiply,
-	tkDivide,
-	tkModulus,
-	tkComma,
-	tkLesser,
-	tkGreater,
-	tkDot,
-	tkColon,
-	tkSemicolon,
-	tkHash,
-	tkExclamationMark,
-	tkAmperstand,
-	tkBar,
-	tkCaret,
-	tkQuMARK_stion,
-	tkArrow,
+	TK_LeftShiftAssign,
+	TK_RightShiftAssign,
+	TK_Equals,
+	TK_NotEquals,
+	TK_AddAssign,
+	TK_SubAssign,
+	TK_MultiplyAssign,
+	TK_DivideAssign,
+	TK_ModulusAssign,
+	TK_LeftShift,
+	TK_RightShift,
+	TK_AtLeast,
+	TK_AtMost,
+	TK_DoubleAmperstand,
+	TK_DoubleBar,
+	TK_DoublePlus,
+	TK_DoubleMinus,
+	TK_SingleQuote,
+	TK_DollarSign,
+	TK_ParenStart,
+	TK_ParenEnd,
+	TK_BracketStart,
+	TK_BracketEnd,
+	TK_BraceStart,
+	TK_BraceEnd,
+	TK_Assign,
+	TK_Plus,
+	TK_Minus,
+	TK_Multiply,
+	TK_Divide,
+	TK_Modulus,
+	TK_Comma,
+	TK_Lesser,
+	TK_Greater,
+	TK_Dot,
+	TK_Colon,
+	TK_Semicolon,
+	TK_Hash,
+	TK_ExclamationMark,
+	TK_Amperstand,
+	TK_Bar,
+	TK_Caret,
+	TK_QuestionMark,
+	TK_Arrow,
 
 	// --------------
 	// Named tokens
-	tkBool,
-	tkBreak,
-	tkCase,
-	tkContinue,
-	tkConst,
-	tkDefault,
-	tkDo,
-	tkElse,
-	tkEvent,
-	tkEventdef,
-	tkFor,
-	tkFuncdef,
-	tkGoto,
-	tkIf,
-	tkInt,
-	tkMainloop,
-	tkOnenter,
-	tkOnexit,
-	tkState,
-	tkSwitch,
-	tkStr,
-	tkVar,
-	tkVoid,
-	tkWhile,
-	tkTrue,
-	tkFalse,
+	TK_Bool,
+	TK_Break,
+	TK_Case,
+	TK_Continue,
+	TK_Const,
+	TK_Default,
+	TK_Do,
+	TK_Else,
+	TK_Event,
+	TK_Eventdef,
+	TK_For,
+	TK_Funcdef,
+	TK_Goto,
+	TK_If,
+	TK_Int,
+	TK_Mainloop,
+	TK_Onenter,
+	TK_Onexit,
+	TK_State,
+	TK_Switch,
+	TK_Str,
+	TK_Var,
+	TK_Void,
+	TK_While,
+	TK_True,
+	TK_False,
 
 	// These ones aren't implemented yet but I plan to do so, thus they are
 	// reserved. Also serves as a to-do list of sorts for me. >:F
-	tkEnum,
-	tkFunc,
-	tkReturn,
+	TK_Enum,
+	TK_Func,
+	TK_Return,
 
 	// --------------
 	// Generic tokens
-	tkSymbol,
-	tkNumber,
-	tkString,
-
-	tkFirstNamedToken		= tkBool,
-	tkLastNamedToken		= (int) tkSymbol - 1,
-	tkAny					= INT_MAX
+	TK_Symbol,
+	TK_Number,
+	TK_String,
+	TK_Any,
 };
 
+static const int gFirstNamedToken		= TK_Bool;
+static const int gLastNamedToken		= (int) TK_Symbol - 1;
+
 #endif

mercurial