Ignore special characters preceding script commands

iwyu_full
Evil Eye 2 years ago
parent cdd6a8c007
commit b19ad079c2

@ -14,6 +14,7 @@
Bug #6427: Enemy health bar disappears before damaging effect ends
Bug #6645: Enemy block sounds align with animation instead of blocked hits
Bug #6661: Saved games that have no preview screenshot cause issues or crashes
Bug #6807: Ultimate Galleon is not working properly
Bug #6939: OpenMW-CS: ID columns are too short
Bug #6949: Sun Damage effect doesn't work in quasi exteriors
Bug #6964: Nerasa Dralor Won't Follow

@ -441,6 +441,28 @@ messagebox,"this is a %g",a
,End,)mwscript";
const std::string sIssue6807 = R"mwscript(---Begin issue6807
short a
----------------------
+++++++++++
***************
/////////////////////
?????????
@@@@@@@@
~~~~~~~~~~~~~~~~~~
set a to 1
;-------------------------------------------------------------------------------------------------------------------------------------------------------------
; Collision Detection Check
-------------------------------------------------------------------------------------------------------------------------------------------------------------
-+'\/.,><$@---!=\/?--------(){}------ show a
End)mwscript";
TEST_F(MWScriptTest, mwscript_test_invalid)
{
EXPECT_THROW(compile("this is not a valid script", true), Compiler::SourceException);
@ -859,4 +881,10 @@ messagebox,"this is a %g",a
{
EXPECT_FALSE(!compile(sIssue6380));
}
TEST_F(MWScriptTest, mwscript_test_6807)
{
registerExtensions();
EXPECT_FALSE(!compile(sIssue6807));
}
}

@ -94,16 +94,10 @@ namespace Compiler
bool FileParser::parseSpecial(int code, const TokenLoc& loc, Scanner& scanner)
{
// Ignore any junk special characters
if (mState == BeginState)
{
if (code != Scanner::S_newline)
reportWarning("Stray special character before begin statement", loc);
return true;
}
if (code == Scanner::S_newline)
{
if (mState == BeginState)
return true;
if (mState == BeginCompleteState)
{
// parse the script body

@ -27,6 +27,7 @@ namespace Compiler
mLoc.mColumn = 0;
++mLoc.mLine;
mLoc.mLiteral.clear();
mIgnoreSpecial = true;
}
else
{
@ -119,6 +120,7 @@ namespace Compiler
}
else if (c.isAlpha() || c == '_' || c == '"')
{
mIgnoreSpecial = false;
bool cont = false;
if (scanName(c, parser, cont))
@ -129,6 +131,7 @@ namespace Compiler
}
else if (c.isDigit())
{
mIgnoreSpecial = false;
bool cont = false;
bool scanned = mExpectName ? scanName(c, parser, cont) : scanInt(c, parser, cont);
@ -402,6 +405,23 @@ namespace Compiler
if (c == '\n')
special = S_newline;
else if (mIgnoreSpecial)
{
// Ignore junk special characters
TokenLoc loc = mLoc;
while (get(c))
{
if (c.isAlpha() || c == '_' || c == '"' || c.isDigit() || c == ';' || c == '\n')
{
putback(c);
break;
}
c.appendTo(loc.mLiteral);
}
mErrorHandler.warning("Stray special character at start of line", loc);
cont = true;
return true;
}
else if (c == '(' || c == '[') /// \todo option to disable the use of [ as alias for (
special = S_open;
else if (c == ')' || c == ']') /// \todo option to disable the use of ] as alias for )
@ -598,6 +618,7 @@ namespace Compiler
, mTolerantNames(false)
, mIgnoreNewline(false)
, mExpectName(false)
, mIgnoreSpecial(true)
{
}

@ -195,6 +195,7 @@ namespace Compiler
bool mTolerantNames;
bool mIgnoreNewline;
bool mExpectName;
bool mIgnoreSpecial;
public:
enum keyword

Loading…
Cancel
Save