diff options
-rw-r--r-- | engines/director/lingo/lingo.cpp | 51 | ||||
-rw-r--r-- | engines/director/lingo/lingo.h | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 761cf74137..161fd275dc 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -151,6 +151,10 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { return; } + // Strip comments for ease of the parser + Common::String codeNorm = stripComments(code); + code = codeNorm.c_str(); + // macros and factories have conflicting grammar. Thus we ease life for the parser. if ((begin = findNextDefinition(code))) { bool first = true; @@ -211,6 +215,53 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { } } +Common::String Lingo::stripComments(const char *s) { + Common::String noComments; + + // Strip comments + while (*s) { + if (*s == '-' && *(s + 1) == '-') { // At the end of the line we will have \0 + while (*s && *s != '\n') + s++; + } + + if (*s) + noComments += *s; + + s++; + } + + // Strip trailing whitespaces + Common::String res; + s = noComments.c_str(); + while (*s) { + if (*s == ' ' || *s == '\t') { // If we see a whitespace + const char *ps = s; // Remember where we saw it + + while (*ps == ' ' || *ps == '\t') // Scan until end of whitespaces + ps++; + + if (*ps) { // Not end of the string + if (*ps == '\n') { // If it is newline, then we continue from it + s = ps; + } else { // It is not a newline + while (s != ps) { // Add all whitespaces + res += *s; + s++; + } + } + } + } + + if (*s) + res += *s; + + s++; + } + + return res; +} + void Lingo::executeScript(ScriptType type, uint16 id, uint16 function) { if (!_scriptContexts[type].contains(id)) { debugC(3, kDebugLingoExec, "Request to execute non-existant script type %d id %d", type, id); diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index 7556e90bc2..b2acdd82f0 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -189,6 +189,7 @@ public: void runTests(); private: + Common::String stripComments(const char *s); const char *findNextDefinition(const char *s); // lingo-events.cpp |