[Scummvm-git-logs] scummvm master -> ba42af45db156ae8a334c3d1275b3070e2077e37

sev- sev at scummvm.org
Sat Dec 7 10:09:39 UTC 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
65a1856ab0 DIRECTOR: LINGO: Added debug output to preprocessor
cf5fb4e4ef DIRECTOR: LINGO: Fix incorrect nesting in 'if' preprocessor
ba42af45db DIRECTOR: LINGO: Give better name to the code preprocessor


Commit: 65a1856ab0de76c3759aad8ae83506322a76c2fb
    https://github.com/scummvm/scummvm/commit/65a1856ab0de76c3759aad8ae83506322a76c2fb
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2019-12-07T11:09:11+01:00

Commit Message:
DIRECTOR: LINGO: Added debug output to preprocessor

Changed paths:
    engines/director/lingo/lingo.cpp


diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index 8dde6db..ac725e5 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -318,29 +318,37 @@ Common::String Lingo::stripComments(const char *s) {
 				line += tolower(*s++);
 			}
 		}
+		debugC(2, kDebugLingoParse, "line: %d                         '%s'", iflevel, line.c_str());
 
 		if (line.size() < 4) { // If line is too small, then skip it
 			if (*s)	// copy newline symbol
 				res += *s++;
 
+			debugC(2, kDebugLingoParse, "too small");
+
 			continue;
 		}
 
 		tok = nexttok(line.c_str(), &lineStart);
 		if (tok.equals("if")) {
 			tok = prevtok(&line.c_str()[line.size() - 1], lineStart, &prevEnd);
+			debugC(2, kDebugLingoParse, "start-if <%s>", tok.c_str());
 
 			if (tok.equals("if")) {
+				debugC(2, kDebugLingoParse, "end-if");
 				tok = prevtok(prevEnd, lineStart);
 
 				if (tok.equals("end")) {
 					// do nothing, we open and close same line
+					debugC(2, kDebugLingoParse, "end-end");
 				} else {
 					iflevel++;
 				}
 			} else if (tok.equals("then")) {
+				debugC(2, kDebugLingoParse, "last-then");
 				iflevel++;
 			} else if (tok.equals("else")) {
+				debugC(2, kDebugLingoParse, "last-else");
 				iflevel++;
 			} else { // other token
 				// Now check if we have tNLELSE
@@ -355,35 +363,46 @@ Common::String Lingo::stripComments(const char *s) {
 				tok = nexttok(s1);
 
 				if (tok.equalsIgnoreCase("else")) { // ignore case because it is look-ahead
+					debugC(2, kDebugLingoParse, "tNLELSE");
 					iflevel++;
 				} else {
+					debugC(2, kDebugLingoParse, "++++ end if (no nlelse after single liner)");
 					res += " end if";
 					iflevel--;
 				}
 			}
 		} else if (tok.equals("else")) {
+			debugC(2, kDebugLingoParse, "start-else");
 			bool elseif = false;
 
 			tok = nexttok(lineStart);
 			if (tok.equals("if")) {
+				debugC(2, kDebugLingoParse, "second-if");
 				elseif = true;
 			} else if (tok.empty()) {
+				debugC(2, kDebugLingoParse, "lonely-else");
 				continue;
 			}
 
 			tok = prevtok(&line.c_str()[line.size() - 1], lineStart, &prevEnd);
+			debugC(2, kDebugLingoParse, "last: '%s'", tok.c_str());
 
 			if (tok.equals("if")) {
+				debugC(2, kDebugLingoParse, "end-if");
 				tok = prevtok(prevEnd, lineStart);
 
 				if (tok.equals("end")) {
+					debugC(2, kDebugLingoParse, "end-end");
 					iflevel--;
 				}
 			} else if (tok.equals("then")) {
+				debugC(2, kDebugLingoParse, "last-then");
+
 				if (elseif == false) {
 					warning("Badly nested then");
 				}
 			} else if (tok.equals("else")) {
+				debugC(2, kDebugLingoParse, "last-else");
 				if (elseif == false) {
 					warning("Badly nested else");
 				}
@@ -399,23 +418,32 @@ Common::String Lingo::stripComments(const char *s) {
 
 				if (tok.equalsIgnoreCase("else")) {
 					// Nothing to do here, same level
+					debugC(2, kDebugLingoParse, "tNLELSE");
 				} else {
+					debugC(2, kDebugLingoParse, "++++ end if (no tNLELSE)");
 					res += " end if";
 					iflevel--;
 				}
 			}
 		} else if (tok.equals("end")) {
+			debugC(2, kDebugLingoParse, "start-end");
+
 			tok = nexttok(lineStart);
 			if (tok.equals("if")) {
+				debugC(2, kDebugLingoParse, "second-if");
 				iflevel--;
 			}
 		}
 	}
 
 	for (int i = 0; i < iflevel; i++) {
+		debugC(2, kDebugLingoParse, "++++ end if (unclosed)");
 		res += "\nend if";
 	}
 
+
+	debugC(2, kDebugLingoParse, "#############\n%s\n#############", res.c_str());
+
 	return res;
 }
 


Commit: cf5fb4e4ef6923f27c2a3a575a654eabe2be654b
    https://github.com/scummvm/scummvm/commit/cf5fb4e4ef6923f27c2a3a575a654eabe2be654b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2019-12-07T11:09:11+01:00

Commit Message:
DIRECTOR: LINGO: Fix incorrect nesting in 'if' preprocessor

Changed paths:
    engines/director/lingo/lingo.cpp


diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index ac725e5..a09f227 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -368,7 +368,6 @@ Common::String Lingo::stripComments(const char *s) {
 				} else {
 					debugC(2, kDebugLingoParse, "++++ end if (no nlelse after single liner)");
 					res += " end if";
-					iflevel--;
 				}
 			}
 		} else if (tok.equals("else")) {


Commit: ba42af45db156ae8a334c3d1275b3070e2077e37
    https://github.com/scummvm/scummvm/commit/ba42af45db156ae8a334c3d1275b3070e2077e37
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2019-12-07T11:09:22+01:00

Commit Message:
DIRECTOR: LINGO: Give better name to the code preprocessor

Changed paths:
    engines/director/lingo/lingo.cpp
    engines/director/lingo/lingo.h


diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index a09f227..cb6bd87 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -154,7 +154,7 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
 	}
 
 	// Strip comments for ease of the parser
-	Common::String codeNorm = stripComments(code);
+	Common::String codeNorm = codePreprocessor(code);
 	code = codeNorm.c_str();
 	begin = code;
 
@@ -247,7 +247,7 @@ static Common::String prevtok(const char *s, const char *lineStart, const char *
 	return res;
 }
 
-Common::String Lingo::stripComments(const char *s) {
+Common::String Lingo::codePreprocessor(const char *s) {
 	Common::String res;
 
 	// Strip comments
@@ -298,6 +298,8 @@ Common::String Lingo::stripComments(const char *s) {
 	res.clear();
 
 	// Preprocess if statements
+	// Here we add ' end if' at end of each statement, which lets us
+	// make the grammar very straightforward
 	Common::String line, tok;
 	const char *lineStart, *prevEnd;
 	int iflevel = 0;
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index d15ade5..9cd0c21 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -183,7 +183,7 @@ public:
 	void runTests();
 
 private:
-	Common::String stripComments(const char *s);
+	Common::String codePreprocessor(const char *s);
 	const char *findNextDefinition(const char *s);
 
 	// lingo-events.cpp




More information about the Scummvm-git-logs mailing list