[geany/geany] 35e8fb: JavaScript: fix handling of various missing semicolons in loops

Colomban Wendling git-noreply at xxxxx
Sun Aug 3 21:24:33 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 03 Aug 2014 21:24:33 UTC
Commit:      35e8fbbe2886b2c5c82686f7e0435e5aa6aad32f
             https://github.com/geany/geany/commit/35e8fbbe2886b2c5c82686f7e0435e5aa6aad32f

Log Message:
-----------
JavaScript: fix handling of various missing semicolons in loops


Modified Paths:
--------------
    tagmanager/ctags/js.c
    tests/ctags/1880687.js
    tests/ctags/1880687.js.tags

Modified: tagmanager/ctags/js.c
16 lines changed, 11 insertions(+), 5 deletions(-)
===================================================================
@@ -709,7 +709,7 @@ static void parseSwitch (tokenInfo *const token)
 
 }
 
-static void parseLoop (tokenInfo *const token)
+static boolean parseLoop (tokenInfo *const token)
 {
 	/*
 	 * Handles these statements
@@ -732,6 +732,7 @@ static void parseLoop (tokenInfo *const token)
 	 *	   }
 	 *	   while (number<5);
 	 */
+	boolean is_terminated = TRUE;
 
 	if (isKeyword (token, KEYWORD_for) || isKeyword (token, KEYWORD_while))
 	{
@@ -758,7 +759,7 @@ static void parseLoop (tokenInfo *const token)
 		}
 		else
 		{
-			parseLine(token, FALSE);
+			is_terminated = parseLine(token, FALSE);
 		}
 	}
 	else if (isKeyword (token, KEYWORD_do))
@@ -777,10 +778,11 @@ static void parseLoop (tokenInfo *const token)
 		}
 		else
 		{
-			parseLine(token, FALSE);
+			is_terminated = parseLine(token, FALSE);
 		}
 
-		readToken(token);
+		if (is_terminated)
+			readToken(token);
 
 		if (isKeyword (token, KEYWORD_while))
 		{
@@ -794,8 +796,12 @@ static void parseLoop (tokenInfo *const token)
 				 */
 				skipArgumentList(token);
 			}
+			if (! isType (token, TOKEN_SEMICOLON))
+				is_terminated = FALSE;
 		}
 	}
+
+	return is_terminated;
 }
 
 static boolean parseIf (tokenInfo *const token)
@@ -1654,7 +1660,7 @@ static boolean parseLine (tokenInfo *const token, boolean is_inside_class)
 			case KEYWORD_for:
 			case KEYWORD_while:
 			case KEYWORD_do:
-				parseLoop (token);
+				is_terminated = parseLoop (token);
 				break;
 			case KEYWORD_if:
 			case KEYWORD_else:


Modified: tests/ctags/1880687.js
53 lines changed, 52 insertions(+), 1 deletions(-)
===================================================================
@@ -1,5 +1,5 @@
 
-// All these examples contain various forms of IF statements
+// All these examples contain various forms of statements
 // with missing semicolons.  Each of these are valid and must
 // be accommodated.
 //
@@ -7,6 +7,9 @@
 // The following tags should be generated:
 //     functions
 //       a
+//       aa
+//       aa_sub1 [aa]
+//       aa_sub2 [aa]
 //       b
 //       baz [f]
 //       c
@@ -32,6 +35,15 @@
 //       w
 //       w_sub1 [w]
 //       w_sub2 [w]
+//       x
+//       x_sub1 [x]
+//       x_sub2 [x]
+//       y
+//       y_sub1 [y]
+//       y_sub2 [y]
+//       z
+//       z_sub1 [z]
+//       z_sub2 [z]
 //     classes
 //       MyClass
 //     methods
@@ -189,3 +201,42 @@ MyClass = {
         var dummy5 = 42;
     }
 };
+
+function x(){
+    function x_sub1(){
+        while (1)
+            x_sub2()
+    }
+    function x_sub2(){
+    }
+}
+
+function y(){
+    function y_sub1(){
+        while (1) {
+            y_sub2()
+        }
+    }
+    function y_sub2(){
+    }
+}
+
+function z(){
+    function z_sub1(){
+        do {
+            z_sub2()
+        } while (0)
+    }
+    function z_sub2(){
+    }
+}
+
+function aa(){
+    function aa_sub1(){
+        do
+            aa_sub2()
+        while (0)
+    }
+    function aa_sub2(){
+    }
+}


Modified: tests/ctags/1880687.js.tags
12 lines changed, 12 insertions(+), 0 deletions(-)
===================================================================
@@ -3,6 +3,9 @@ MyClass
 MyClass_sub1�128�MyClass�0
 MyClass_sub2�128�MyClass�0
 a�16�0
+aa�16�0
+aa_sub1�16�aa�0
+aa_sub2�16�aa�0
 b�16�0
 baz�16�f�0
 c�16�0
@@ -28,3 +31,12 @@ v
 w�16�0
 w_sub1�16�w�0
 w_sub2�16�w�0
+x�16�0
+x_sub1�16�x�0
+x_sub2�16�x�0
+y�16�0
+y_sub1�16�y�0
+y_sub2�16�y�0
+z�16�0
+z_sub1�16�z�0
+z_sub2�16�z�0



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list