[rkward-cvs] SF.net SVN: rkward:[2688] trunk/rkward/rkward/plugins/php2js.js

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 5 18:22:01 UTC 2009


Revision: 2688
          http://rkward.svn.sourceforge.net/rkward/?rev=2688&view=rev
Author:   tfry
Date:     2009-10-05 18:22:00 +0000 (Mon, 05 Oct 2009)

Log Message:
-----------
Deal with control statements without braces when merging echos.

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/php2js.js

Modified: trunk/rkward/rkward/plugins/php2js.js
===================================================================
--- trunk/rkward/rkward/plugins/php2js.js	2009-10-05 18:13:07 UTC (rev 2687)
+++ trunk/rkward/rkward/plugins/php2js.js	2009-10-05 18:22:00 UTC (rev 2688)
@@ -281,6 +281,11 @@
 			} else {
 				output += c;
 			}
+			
+			if (line.indexOf ("if", i) == i) {
+				output += "f";
+				i += feedthroughControlStatement (line.substr (i+2)) + 2;
+			}
 		}
 	}
 
@@ -293,6 +298,40 @@
 	return (ret);
 }
 
+function feedthroughControlStatement (input) {
+	var levelstack = new Array ();
+	for (var i = 0; i < input.length; ++i) {
+		var c = input.charAt (i);
+
+		output += c;
+
+		if ((c == "{") || (c == "(")) {
+			levelstack.push (c);
+		} else if (c == "}") {
+			if (levelstack[levelstack.length - 1] == "{") {
+				levelstack.pop ();
+				if (levelstack.length == 0) {
+					return i;
+				}
+			} else {
+				print ("Warning: Brace mismatch while postprocessing " + input);
+			}
+		} else if (c == ")") {
+			if (levelstack[levelstack.length - 1] == "(") {
+				levelstack.pop ();
+			} else {
+				print ("Warning: Brace mismatch while postprocessing " + input);
+			}
+		} else if (c == ";") {
+			if (levelstack.length == 0) {
+				print ("Note: Control statement without braces. This is bad style. ");
+				return i;
+			}
+		}
+	}
+	return i;	// end of line reached is an ok condition
+}
+
 function postProcess (input) {
 	var lines = input.split ("\n");
 	var olines = new Array ();


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




More information about the rkward-tracker mailing list