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.
  • Loading branch information
graceful-potato committed Oct 5, 2020
1 parent 02613b0 commit 2c906ca
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 111 deletions.
198 changes: 87 additions & 111 deletions Syntaxes/Ruby.plist
Original file line number Diff line number Diff line change
Expand Up @@ -522,100 +522,17 @@
<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>
</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 @@ -682,15 +599,17 @@
</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>
</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
54 changes: 54 additions & 0 deletions Tests/method_arguments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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

0 comments on commit 2c906ca

Please sign in to comment.