Skip to content

Commit

Permalink
Merge pull request #1766 from tambeta/ruby-assign-blocks-sigils
Browse files Browse the repository at this point in the history
Ruby block assign: handle variables with sigils
  • Loading branch information
masatake authored Jun 18, 2018
2 parents 44a0e97 + 48ae2e7 commit 6aa62c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Units/parser-ruby.r/ruby-block-assign.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ method_c input.rb /^ def method_c$/;" f class:Bar
method_d input.rb /^ def method_d$/;" f class:Bar
method_e input.rb /^ def method_e$/;" f class:Bar
method_f input.rb /^ def method_f$/;" f class:Bar
method_g input.rb /^ def method_g$/;" f class:Bar
method_h input.rb /^ def method_h$/;" f class:Bar
method_j input.rb /^ def method_j$/;" f class:Bar
18 changes: 18 additions & 0 deletions Units/parser-ruby.r/ruby-block-assign.d/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def method_e
end

def method_f
@x = if 1
else
end
end

def method_g
@@x = if 1
else
end
end

def method_h
$x = if 1
else
end
end

def method_j
end
end

Expand Down
13 changes: 10 additions & 3 deletions parsers/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static bool notIdentChar (int c)
return ! isIdentChar (c);
}

static bool operatorChar (int c)
static bool isOperatorChar (int c)
{
return (c == '[' || c == ']' ||
c == '=' || c == '!' || c == '~' ||
Expand All @@ -134,7 +134,12 @@ static bool operatorChar (int c)

static bool notOperatorChar (int c)
{
return ! operatorChar (c);
return ! isOperatorChar (c);
}

static bool isSigilChar (int c)
{
return (c == '@' || c == '$');
}

static bool isWhitespace (int c)
Expand Down Expand Up @@ -181,6 +186,8 @@ static bool canMatchKeywordWithAssign (const unsigned char** s, const char* lite
return true;
}

advanceWhile (s, isSigilChar);

if (! advanceWhile (s, isIdentChar))
{
*s = original_pos;
Expand All @@ -189,7 +196,7 @@ static bool canMatchKeywordWithAssign (const unsigned char** s, const char* lite

advanceWhile (s, isWhitespace);

if (! (advanceWhile (s, operatorChar) && *(*s - 1) == '='))
if (! (advanceWhile (s, isOperatorChar) && *(*s - 1) == '='))
{
*s = original_pos;
return false;
Expand Down

0 comments on commit 6aa62c9

Please sign in to comment.