Skip extra text after variable declaration (bug #4867)

pull/2178/head
Capostrophic 5 years ago
parent 5e12073b47
commit af47ec7756

@ -37,6 +37,7 @@
Bug #4828: Potion looping effects VFX are not shown for NPCs
Bug #4837: CTD when a mesh with NiLODNode root node with particles is loaded
Bug #4860: Actors outside of processing range visible for one frame after spawning
Bug #4867: Arbitrary text after local variable declarations breaks script compilation
Bug #4876: AI ratings handling inconsistencies
Bug #4877: Startup script executes only on a new game start
Bug #4888: Global variable stray explicit reference calls break script compilation

@ -22,20 +22,20 @@ bool Compiler::DeclarationParser::parseName (const std::string& name, const Toke
char type = mLocals.getType (name2);
if (type!=' ')
{
/// \todo add option to make re-declared local variables an error
getErrorHandler().warning ("ignoring local variable re-declaration",
loc);
mState = State_End;
return true;
}
mLocals.declare (mType, name2);
getErrorHandler().warning ("ignoring local variable re-declaration", loc);
else
mLocals.declare (mType, name2);
mState = State_End;
return true;
}
else if (mState==State_End)
{
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return false;
}
return Parser::parseName (name, loc, scanner);
}
@ -61,17 +61,31 @@ bool Compiler::DeclarationParser::parseKeyword (int keyword, const TokenLoc& loc
else if (mState==State_Name)
{
// allow keywords to be used as local variable names. MW script compiler, you suck!
/// \todo option to disable this atrocity.
return parseName (loc.mLiteral, loc, scanner);
}
else if (mState==State_End)
{
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return false;
}
return Parser::parseKeyword (keyword, loc, scanner);
}
bool Compiler::DeclarationParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{
if (code==Scanner::S_newline && mState==State_End)
if (mState==State_End)
{
if (code!=Scanner::S_newline)
{
getErrorHandler().warning ("Ignoring extra text after local variable declaration", loc);
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
}
return false;
}
return Parser::parseSpecial (code, loc, scanner);
}

Loading…
Cancel
Save