Permalink
Browse files

Ruby parser: don't create an extra scope after "for .. in .. do"

When "do" appears as the separator after a "for", "while" or "until"
construct, don't improperly make it start its own scope too.
  • Loading branch information...
1 parent faeeaf4 commit f1e88ca311af3c3ced49f4b348d88140a74302b0 @b4n b4n committed Sep 13, 2012
Showing with 23 additions and 3 deletions.
  1. +23 −3 tagmanager/ctags/ruby.c
View
26 tagmanager/ctags/ruby.c
@@ -287,6 +287,9 @@ static void findRubyTags (void)
while ((line = fileReadLine ()) != NULL)
{
const unsigned char *cp = line;
+ /* if we expect a separator after a while, for, or until statement
+ * separators are "do", ";" or newline */
+ boolean expect_separator = FALSE;
if (canMatch (&cp, "=begin"))
{
@@ -318,10 +321,15 @@ static void findRubyTags (void)
* puts("hello") \
* unless <exp>
*/
- if (canMatch (&cp, "case") || canMatch (&cp, "for") ||
- canMatch (&cp, "if") || canMatch (&cp, "unless") ||
+ if (canMatch (&cp, "for") || canMatch (&cp, "until") ||
canMatch (&cp, "while"))
{
+ expect_separator = TRUE;
+ enterUnnamedScope ();
+ }
+ else if (canMatch (&cp, "case") || canMatch (&cp, "if") ||
+ canMatch (&cp, "unless"))
+ {
enterUnnamedScope ();
}
@@ -362,10 +370,17 @@ static void findRubyTags (void)
*/
break;
}
- else if (canMatch (&cp, "begin") || canMatch (&cp, "do"))
+ else if (canMatch (&cp, "begin"))
{
enterUnnamedScope ();
}
+ else if (canMatch (&cp, "do"))
+ {
+ if (! expect_separator)
+ enterUnnamedScope ();
+ else
+ expect_separator = FALSE;
+ }
else if (canMatch (&cp, "end") && stringListCount (nesting) > 0)
{
/* Leave the most recent scope. */
@@ -383,6 +398,11 @@ static void findRubyTags (void)
if (*cp == '"')
cp++; /* skip the last found '"' */
}
+ else if (*cp == ';')
+ {
+ ++cp;
+ expect_separator = FALSE;
+ }
else if (*cp != '\0')
{
do

0 comments on commit f1e88ca

Please sign in to comment.