From 48ae2e7bba9700e2d027d54d12347bdc2ec1b67c Mon Sep 17 00:00:00 2001 From: Tambet Arak Date: Mon, 18 Jun 2018 12:02:27 +0300 Subject: [PATCH] Ruby block assign: handle variables with sigils When assigning blocks in Ruby, handle assignment to variables prefixed by `@`, `@@` or `$`. Function naming consistency: operatorChar -> isOperatorChar. --- .../ruby-block-assign.d/expected.tags | 3 +++ .../parser-ruby.r/ruby-block-assign.d/input.rb | 18 ++++++++++++++++++ parsers/ruby.c | 13 ++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Units/parser-ruby.r/ruby-block-assign.d/expected.tags b/Units/parser-ruby.r/ruby-block-assign.d/expected.tags index 2c1dcc2df4..a56297dfc9 100644 --- a/Units/parser-ruby.r/ruby-block-assign.d/expected.tags +++ b/Units/parser-ruby.r/ruby-block-assign.d/expected.tags @@ -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 diff --git a/Units/parser-ruby.r/ruby-block-assign.d/input.rb b/Units/parser-ruby.r/ruby-block-assign.d/input.rb index 5b2d3ab684..8c8a4b4efa 100644 --- a/Units/parser-ruby.r/ruby-block-assign.d/input.rb +++ b/Units/parser-ruby.r/ruby-block-assign.d/input.rb @@ -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 diff --git a/parsers/ruby.c b/parsers/ruby.c index 67a57dc9c8..988b6f6703 100644 --- a/parsers/ruby.c +++ b/parsers/ruby.c @@ -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 == '~' || @@ -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) @@ -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; @@ -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;