Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby block assign: handle variables with sigils #1766

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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