Mon, 03 Mar 2014 01:47:39 +0200
- added using statement for specifying the target zandronum version. will be used later
src/Containers.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/Parser.cc | file | annotate | diff | comparison | revisions | |
src/Parser.h | file | annotate | diff | comparison | revisions | |
src/Tokens.h | file | annotate | diff | comparison | revisions |
--- a/src/Containers.h Mon Mar 03 01:04:16 2014 +0200 +++ b/src/Containers.h Mon Mar 03 01:47:39 2014 +0200 @@ -264,9 +264,9 @@ { int i = 0; - for (const ValueType & hay : *this) + for (const ValueType& hay : *this) { - if (&hay == &needle) + if (hay == needle) return i; i++;
--- a/src/Lexer.cc Mon Mar 03 01:04:16 2014 +0200 +++ b/src/Lexer.cc Mon Mar 03 01:47:39 2014 +0200 @@ -333,3 +333,12 @@ { return format ("%1 / %2", m_tokenPosition - m_tokens.begin(), m_tokens.size()); } + +// ============================================================================= +// +void Lexer::mustGetSymbol (const String& a) +{ + mustGetNext (TK_Any); + if (token()->text != a) + error ("expected \"%1\", got \"%2\"", a, token()->text); +}
--- a/src/Lexer.h Mon Mar 03 01:04:16 2014 +0200 +++ b/src/Lexer.h Mon Mar 03 01:47:39 2014 +0200 @@ -55,6 +55,7 @@ bool next (ETokenType req = TK_Any); void mustGetNext (ETokenType tok); void mustGetAnyOf (const List<ETokenType>& toks); + void mustGetSymbol (const String& a); int getOneSymbol (const StringList& syms); void tokenMustBe (ETokenType tok); bool peekNext (TokenInfo* tk = null);
--- a/src/LexerScanner.cc Mon Mar 03 01:04:16 2014 +0200 +++ b/src/LexerScanner.cc Mon Mar 03 01:47:39 2014 +0200 @@ -100,6 +100,7 @@ "state", "switch", "str", + "using", "var", "void", "while",
--- a/src/Parser.cc Mon Mar 03 01:04:16 2014 +0200 +++ b/src/Parser.cc Mon Mar 03 01:47:39 2014 +0200 @@ -37,6 +37,8 @@ #define SCOPE(n) (m_scopeStack[m_scopeCursor - n]) +static const StringList g_validZandronumVersions = {"1.2", "1.3", "2.0"}; + // ============================================================================ // BotscriptParser::BotscriptParser() : @@ -53,7 +55,9 @@ m_scopeCursor (-1), m_isElseAllowed (false), m_highestGlobalVarIndex (0), - m_highestStateVarIndex (0) {} + m_highestStateVarIndex (0), + m_zandronumVersion (10200), // 1.2 + m_defaultZandronumVersion (true) {} // ============================================================================ // @@ -177,6 +181,10 @@ case TK_Semicolon: break; + case TK_Using: + parseUsing(); + break; + default: { // Check if it's a command @@ -217,6 +225,14 @@ if (m_isStateSpawnDefined == false) error ("script must have a state named `stateSpawn`!"); + if (m_defaultZandronumVersion) + { + print ("\n"); + print ("note: use the 'using' directive to define a target Zandronum version\n"); + print ("usage: using zandronum <version>, possible versions: %1\n", g_validZandronumVersions); + print ("\n"); + } + // Dump the last state's onenter and mainloop writeMemberBuffers(); @@ -901,7 +917,34 @@ } // ============================================================================ +// +// Parses a using statement +// +void BotscriptParser::parseUsing() +{ + checkToplevel(); + m_lexer->mustGetSymbol ("zandronum"); + String versionText; + + while (m_lexer->next() && (m_lexer->tokenType() == TK_Number || m_lexer->tokenType() == TK_Dot)) + versionText += getTokenString(); + + // Note: at this point the lexer's pointing at the token after the version. + if (versionText.isEmpty()) + error ("expected version string, got `%1`", getTokenString()); + if (g_validZandronumVersions.contains (versionText) == false) + error ("unknown version string `%2`: valid versions: `%1`\n", g_validZandronumVersions, versionText); + + StringList versionTokens = versionText.split ("."); + m_zandronumVersion = versionTokens[0].toLong() * 10000 + versionTokens[1].toLong() * 100; + m_defaultZandronumVersion = false; + m_lexer->tokenMustBe (TK_Semicolon); +} + +// ============================================================================/ +// // Parses a command call +// DataBuffer* BotscriptParser::parseCommand (CommandInfo* comm) { DataBuffer* r = new DataBuffer (64);
--- a/src/Parser.h Mon Mar 03 01:04:16 2014 +0200 +++ b/src/Parser.h Mon Mar 03 01:47:39 2014 +0200 @@ -224,6 +224,8 @@ int m_highestStateVarIndex; int m_numWrittenBytes; List<ScopeInfo> m_scopeStack; + int m_zandronumVersion; + bool m_defaultZandronumVersion; DataBuffer* currentBuffer(); void parseStateBlock(); @@ -246,6 +248,7 @@ void parseLabel(); void parseEventdef(); void parseFuncdef(); + void parseUsing(); void writeMemberBuffers(); void writeStringTable(); DataBuffer* parseExpression (DataType reqtype, bool fromhere = false);