[Scummvm-cvs-logs] SF.net SVN: scummvm: [32691] scummvm/branches/gsoc2008-gui/gui

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Fri Jun 13 11:39:13 CEST 2008


Revision: 32691
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32691&view=rev
Author:   Tanoku
Date:     2008-06-13 02:39:13 -0700 (Fri, 13 Jun 2008)

Log Message:
-----------
Parser cleanup.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.h

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-13 09:24:41 UTC (rev 32690)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-13 09:39:13 UTC (rev 32691)
@@ -100,8 +100,7 @@
 		return;
 	}
 
-	while (isspace(_text[_pos]))
-		_pos++;
+	skipSpaces();
 
 	Common::String data;
 
@@ -131,19 +130,9 @@
 		if (_state == kParserError)
 			break;
 
-		while (isspace(_text[_pos]))
-			_pos++;
+		skipSpaces();
+		skipComments();
 
-		// comment handling: skip everything between /* and */
-		if (_text[_pos] == '/' && _text[_pos + 1] == '*') {
-			_pos += 2;
-			while (_text[_pos++]) {
-				if (_text[_pos - 2] == '*' && _text[_pos - 1] == '/')
-					break;
-			}
-			continue;
-		}
-
 		switch (_state) {
 			case kParserNeedKey:
 				if (_text[_pos++] != '<') {
@@ -157,25 +146,26 @@
 					while (isValidNameChar(_text[_pos]))
 						_token += _text[_pos++];
 
-					if (!_activeKey.empty() && _token == _activeKey.top()) {
+					if (_activeKey.empty() || _token != _activeKey.top())
+						parserError("Unexpected closure.");
+					else {
 						_activeKey.pop();
 						_keyValues.pop();
 
-						while (isspace(_text[_pos]) || _text[_pos] == '>')
-							_pos++;
+						skipSpaces();
 
-						break;
-					} else {
-						parserError("Unexpected closure.");
-						break;
+						if (_text[_pos++] != '>')
+							parserError("Malformed tag closure.");
 					}
+	
+					break;
 				}
 
 				_keyValues.push(Common::StringMap());
-				_state = kParserKeyNeedName;
+				_state = kParserNeedKeyName;
 				break;
 
-			case kParserKeyNeedName:
+			case kParserNeedKeyName:
 				_token.clear();
 				while (isValidNameChar(_text[_pos]))
 					_token += _text[_pos++];
@@ -185,11 +175,11 @@
 					break;
 				}
 
-				_state = kParserKeyNeedToken;
+				_state = kParserNeedKeyValues;
 				_activeKey.push(_token);
 				break;
 
-			case kParserKeyNeedToken:
+			case kParserNeedKeyValues:
 				_token.clear();
 
 				if ((_text[_pos] == '/' && _text[_pos + 1] == '>') || _text[_pos] == '>') {
@@ -203,8 +193,7 @@
 				while (isValidNameChar(_text[_pos]))
 					_token += _text[_pos++];
 
-				while (isspace(_text[_pos]))
-					_pos++;
+				skipSpaces();
 
 				if (_text[_pos] != '=') {
 					parserError("Unexpected character after key name.");

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-13 09:24:41 UTC (rev 32690)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-13 09:39:13 UTC (rev 32691)
@@ -50,13 +50,10 @@
 	~ThemeParser() {}
 
 	enum ParserState {
-		kParserKeyNeedName,
-		kParserKeyNeedToken,
-		kParserKeyNeedSubkey,
 		kParserNeedKey,
-		kParserInComment,
-		kParserError,
-		kParserSuccess
+		kParserNeedKeyName,
+		kParserNeedKeyValues,
+		kParserError
 	};
 
 	bool parse();
@@ -71,6 +68,22 @@
 	void parserCallback_DRAW();
 	void parserCallback_DRAWDATA();
 
+	inline void skipSpaces() {
+		while (isspace(_text[_pos]))
+			_pos++;
+	}
+
+	inline void skipComments() {
+		if (_text[_pos] == '/' && _text[_pos + 1] == '*') {
+			_pos += 2;
+			while (_text[_pos++]) {
+				if (_text[_pos - 2] == '*' && _text[_pos - 1] == '/')
+					break;
+			}
+			skipSpaces();
+		}
+	}
+
 	int _pos;
 	char *_text;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list