From ad54fc546fc38efdbb42dd3aa2302fb6ac3ff3b5 Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Wed, 29 Jul 2026 16:01:54 -0500 Subject: [PATCH] Add a warning for strings containing ] and } It's rare to need to type these characters. More often than not, as happened this morning, people write things in the CCScriptWriter style of "shove all the commands into a string" and occasionally have copy- paste mistakes like this: "{goto_if_true(0xc5e1d6)}]{load_registers}" ^~this right square bracket Not sure how many beginners' scripts have errors like this, or scripts on the wiki for that matter, so... yet another warning it is --- src/stringparser.cpp | 15 +++++++++++++++ src/stringparser.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/stringparser.cpp b/src/stringparser.cpp index b8cbf4f..92c98f7 100644 --- a/src/stringparser.cpp +++ b/src/stringparser.cpp @@ -21,6 +21,11 @@ void StringParser::Warning(const string &msg, int line_unused, int col) error->Warning(msg + " inside string", this->line, col); } +void StringParser::Deprecated(const string &msg, const string &suggestion, int line_unused, int col) +{ + error->Warning(msg + " inside string, which may stop working in the future; " + suggestion, this->line, col); +} + int StringParser::acceptbyte() { string s = ""; @@ -92,6 +97,16 @@ Value StringParser::Evaluate(SymbolTable* scope, EvalContext& context) docodes = true; } else { + if(current == ']') { + Deprecated(string("lone \"]\" character"), + string("if this was intentional, please replace it with [8D]"), + 0,0); + } + else if(current == '}') { + Deprecated(string("lone \"}\" character"), + string("if this was intentional, please replace it with [AD]"), + 0,0); + } // Default: output->Char(current); } diff --git a/src/stringparser.h b/src/stringparser.h index 6766182..01531e9 100644 --- a/src/stringparser.h +++ b/src/stringparser.h @@ -36,6 +36,8 @@ class StringParser : public ErrorReceiver void Warning(const std::string& msg, int line, int col); private: + // One-off warning method because `Warning` adds " inside string" to the end of the string every time + void Deprecated(const std::string& msg, const std::string& suggestion, int line, int col); int acceptbyte(); bool expect(char c); void next();