Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Mon, 24 Nov 2014 01:41:57 UTC Commit: 5a1a22d9306fdf0e4352127b12cafd8555ea55b8 https://github.com/geany/geany/commit/5a1a22d9306fdf0e4352127b12cafd8555ea55...
Log Message: ----------- javascript: Properly handle nested unknown blocks
Properly match open curly braces when parsing a statement not to possibly get fooled by unexpected nested blocks, e.g. after a `switch`'s `case` or a label.
This mostly reverts c54c3ad5e815d16e3b48f3c477465627808aadee and replaces it with a more correct and complete solution.
Modified Paths: -------------- tagmanager/ctags/js.c tests/ctags/Makefile.am tests/ctags/js-unknown-construct-nesting.js tests/ctags/js-unknown-construct-nesting.js.tags
Modified: tagmanager/ctags/js.c 40 lines changed, 11 insertions(+), 29 deletions(-) =================================================================== @@ -169,7 +169,7 @@ static const keywordDesc JsKeywordTable [] = {
/* Recursive functions */ static void parseFunction (tokenInfo *const token); -static boolean parseBlock (tokenInfo *const token, tokenInfo *const parent); +static boolean parseBlock (tokenInfo *const token, tokenInfo *const orig_parent); static boolean parseLine (tokenInfo *const token, boolean is_inside_class); static void parseUI5 (tokenInfo *const token);
@@ -674,31 +674,6 @@ static void findCmdTerm (tokenInfo *const token) } }
-static void findMatchingToken (tokenInfo *const token, tokenType begin_token, tokenType end_token) -{ - int nest_level = 0; - - if ( ! isType (token, end_token)) - { - nest_level++; - while (! (isType (token, end_token) && (nest_level == 0))) - { - readToken (token); - if (isType (token, begin_token)) - { - nest_level++; - } - if (isType (token, end_token)) - { - if (nest_level > 0) - { - nest_level--; - } - } - } - } -} - static void parseSwitch (tokenInfo *const token) { /* @@ -726,9 +701,8 @@ static void parseSwitch (tokenInfo *const token)
if (isType (token, TOKEN_OPEN_CURLY)) { - findMatchingToken (token, TOKEN_OPEN_CURLY, TOKEN_CLOSE_CURLY); + parseBlock (token, token); } - }
static boolean parseLoop (tokenInfo *const token) @@ -951,11 +925,15 @@ static void parseFunction (tokenInfo *const token) deleteToken (name); }
-static boolean parseBlock (tokenInfo *const token, tokenInfo *const parent) +static boolean parseBlock (tokenInfo *const token, tokenInfo *const orig_parent) { boolean is_class = FALSE; boolean read_next_token = TRUE; vString * saveScope = vStringNew (); + tokenInfo *const parent = newToken (); + + /* backup the parent token to allow calls like parseBlock(token, token) */ + copyToken (parent, orig_parent);
token->nestLevel++; /* @@ -1041,6 +1019,7 @@ static boolean parseBlock (tokenInfo *const token, tokenInfo *const parent) } while (! isType (token, TOKEN_CLOSE_CURLY) && read_next_token ); }
+ deleteToken (parent); vStringDelete(saveScope); token->nestLevel--;
@@ -1228,6 +1207,9 @@ static boolean parseStatement (tokenInfo *const token, boolean is_inside_class) ! isType (token, TOKEN_SEMICOLON) && ! isType (token, TOKEN_EQUAL_SIGN) ) { + if (isType (token, TOKEN_OPEN_CURLY)) + parseBlock (token, token); + /* Potentially the name of the function */ readToken (token); if (isType (token, TOKEN_PERIOD))
Modified: tests/ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -160,6 +160,7 @@ test_sources = \ invalid_name.f90 \ java_enum.java \ js-scope.js \ + js-unknown-construct-nesting.js \ jsFunc_tutorial.js \ keyword_abstract.cs \ keyword_catch_try.cs \
Modified: tests/ctags/js-unknown-construct-nesting.js 23 lines changed, 23 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,23 @@ + +var o = { + aa: function () { + foo: { + return ; + } + }, + + bb: function (a) { + switch (a) { + case 1: + if (1) { + return 32 + } + break; + case 2: + return 31; + } + return 1; + }, + + cc: function() {} +};
Modified: tests/ctags/js-unknown-construct-nesting.js.tags 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,5 @@ +# format=tagmanager +aa�128�o�0 +bb�128�o�0 +cc�128�o�0 +o�1�0
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).