Skip to content

Commit

Permalink
Fix arguments in method defifinition with parentheses. Add support fo…
Browse files Browse the repository at this point in the history
…r multiline arguments in method definition without parentheses. Add support for double splat operator.
  • Loading branch information
graceful-potato committed Oct 8, 2020
1 parent 02613b0 commit 90b5672
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 113 deletions.
202 changes: 89 additions & 113 deletions Syntaxes/Ruby.plist
Original file line number Diff line number Diff line change
Expand Up @@ -520,102 +520,19 @@
</dict>
</dict>
<key>match</key>
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
</dict>
<dict>
<key>include</key>
<string>#parens</string>
</dict>
<dict>
<key>include</key>
<string>#braces</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
<dict>
<key>braces</key>
<dict>
<key>begin</key>
<string>\{</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.begin.ruby</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.end.ruby</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#parens</string>
</dict>
<dict>
<key>include</key>
<string>#braces</string>
<string>\G(&amp;|\*\*?)?(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<key>parens</key>
<dict>
<key>begin</key>
<string>\(</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.begin.ruby</string>
</dict>
</dict>
<key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.end.ruby</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#parens</string>
</dict>
<dict>
<key>include</key>
<string>#braces</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
<key>include</key>
<string>$self</string>
</dict>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
Expand Down Expand Up @@ -644,16 +561,16 @@
<key>comment</key>
<string>same as the previous rule, but without parentheses around the arguments</string>
<key>end</key>
<string>$</string>
<string>(?&lt;=[\w\])}`'";!?])\s*$|;</string>
<key>name</key>
<string>meta.function.method.with-arguments.ruby</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?![\s,])</string>
<string>(?=[&amp;*_a-zA-Z])</string>
<key>end</key>
<string>(?=,|$)</string>
<string>(?=,|;|\s*$)</string>
<key>patterns</key>
<array>
<dict>
Expand Down Expand Up @@ -681,16 +598,18 @@
</dict>
</dict>
<key>match</key>
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
<key>name</key>
<string>variable.parameter.function.ruby</string>
<string>\G(&amp;|\*\*?)?(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<dict>
Expand Down Expand Up @@ -1956,34 +1875,91 @@
<string>punctuation.separator.other.ruby</string>
</dict>
<dict>
<key>match</key>
<key>begin</key>
<string>\{</string>
<key>name</key>
<string>punctuation.section.scope.begin.ruby</string>
</dict>
<dict>
<key>match</key>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.scope.begin.ruby</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>name</key>
<string>punctuation.section.scope.end.ruby</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.scope.end.ruby</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<dict>
<key>match</key>
<key>begin</key>
<string>\[</string>
<key>name</key>
<string>punctuation.section.array.begin.ruby</string>
</dict>
<dict>
<key>match</key>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.array.begin.ruby</string>
</dict>
</dict>
<key>end</key>
<string>\]</string>
<key>name</key>
<string>punctuation.section.array.end.ruby</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.array.end.ruby</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
<dict>
<key>match</key>
<string>\(|\)</string>
<key>name</key>
<string>punctuation.section.function.ruby</string>
<key>begin</key>
<string>\(</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.ruby</string>
</dict>
</dict>
<key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.function.ruby</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
Expand Down
72 changes: 72 additions & 0 deletions Tests/method_arguments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
def method; hello, world = [1,2] end

def method_with_parentheses(a, b, c = [foo,bar,baz]); hello, world = [1,2] end

def method_without_parentheses a, b, c = [foo,bar,baz]; hello, world = [1,2] end

def method
hello, world = [1,2]
end

def method_with_parentheses(a, b, c = [foo,bar,baz])
hello, world = [1,2]
end

def method_without_parentheses a, b, c = [foo,bar,baz]
hello, world = [1,2]
end

def method_with_parentheses(a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = {})
hello, world = [1,2]
do_something1
do_something2
end

def method_without_parentheses a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = ""
hello, world = [1,2]
do_something1
do_something2
end

def method_with_parentheses(a,
b = hello, # test comment
c = ["foo", bar, :baz],
d = (2 + 2) * 2,
e = {})
hello, world = [1,2]
do_something1
do_something2
end

def method_without_parentheses a,
b = "hello" , # test comment
c = ["foo", bar, :baz],
d = (2 + 2) * 2,
e = proc { |e| e + e }
hello, world = [1,2]
do_something1
do_something2
end

def method_without_parentheses a,
b: hello , # test comment
c: ["foo", bar, :baz],
d: (2 + 2) * 2,
e: proc { |e| e + e }
hello, world = [1,2]
do_something1
do_something2
end

# double splat, splat, and & opearator
def method_with_parentheses(*a, **b, &c); hello, world = [1,2] end

def method_without_parentheses *a, **b, &c; hello, world = [1,2] end

def method_with_parentheses(*a, **b, &c)
hello, world = [1,2]
end

def method_without_parentheses *a, **b, &c
hello, world = [1,2]
end

0 comments on commit 90b5672

Please sign in to comment.