Skip to content

Commit 90b5672

Browse files
Fix arguments in method defifinition with parentheses. Add support for multiline arguments in method definition without parentheses. Add support for double splat operator.
1 parent 02613b0 commit 90b5672

File tree

2 files changed

+161
-113
lines changed

2 files changed

+161
-113
lines changed

Syntaxes/Ruby.plist

Lines changed: 89 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -520,102 +520,19 @@
520520
</dict>
521521
</dict>
522522
<key>match</key>
523-
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
524-
</dict>
525-
<dict>
526-
<key>include</key>
527-
<string>#parens</string>
528-
</dict>
529-
<dict>
530-
<key>include</key>
531-
<string>#braces</string>
532-
</dict>
533-
<dict>
534-
<key>include</key>
535-
<string>$self</string>
536-
</dict>
537-
</array>
538-
</dict>
539-
</array>
540-
<key>repository</key>
541-
<dict>
542-
<key>braces</key>
543-
<dict>
544-
<key>begin</key>
545-
<string>\{</string>
546-
<key>beginCaptures</key>
547-
<dict>
548-
<key>0</key>
549-
<dict>
550-
<key>name</key>
551-
<string>punctuation.section.function.begin.ruby</string>
552-
</dict>
553-
</dict>
554-
<key>end</key>
555-
<string>\}</string>
556-
<key>endCaptures</key>
557-
<dict>
558-
<key>0</key>
559-
<dict>
560-
<key>name</key>
561-
<string>punctuation.section.function.end.ruby</string>
562-
</dict>
563-
</dict>
564-
<key>patterns</key>
565-
<array>
566-
<dict>
567-
<key>include</key>
568-
<string>#parens</string>
569-
</dict>
570-
<dict>
571-
<key>include</key>
572-
<string>#braces</string>
523+
<string>\G(&amp;|\*\*?)?(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
573524
</dict>
574525
<dict>
575526
<key>include</key>
576527
<string>$self</string>
577528
</dict>
578529
</array>
579530
</dict>
580-
<key>parens</key>
581531
<dict>
582-
<key>begin</key>
583-
<string>\(</string>
584-
<key>beginCaptures</key>
585-
<dict>
586-
<key>0</key>
587-
<dict>
588-
<key>name</key>
589-
<string>punctuation.section.function.begin.ruby</string>
590-
</dict>
591-
</dict>
592-
<key>end</key>
593-
<string>\)</string>
594-
<key>endCaptures</key>
595-
<dict>
596-
<key>0</key>
597-
<dict>
598-
<key>name</key>
599-
<string>punctuation.section.function.end.ruby</string>
600-
</dict>
601-
</dict>
602-
<key>patterns</key>
603-
<array>
604-
<dict>
605-
<key>include</key>
606-
<string>#parens</string>
607-
</dict>
608-
<dict>
609-
<key>include</key>
610-
<string>#braces</string>
611-
</dict>
612-
<dict>
613-
<key>include</key>
614-
<string>$self</string>
615-
</dict>
616-
</array>
532+
<key>include</key>
533+
<string>$self</string>
617534
</dict>
618-
</dict>
535+
</array>
619536
</dict>
620537
<dict>
621538
<key>begin</key>
@@ -644,16 +561,16 @@
644561
<key>comment</key>
645562
<string>same as the previous rule, but without parentheses around the arguments</string>
646563
<key>end</key>
647-
<string>$</string>
564+
<string>(?&lt;=[\w\])}`'";!?])\s*$|;</string>
648565
<key>name</key>
649566
<string>meta.function.method.with-arguments.ruby</string>
650567
<key>patterns</key>
651568
<array>
652569
<dict>
653570
<key>begin</key>
654-
<string>(?![\s,])</string>
571+
<string>(?=[&amp;*_a-zA-Z])</string>
655572
<key>end</key>
656-
<string>(?=,|$)</string>
573+
<string>(?=,|;|\s*$)</string>
657574
<key>patterns</key>
658575
<array>
659576
<dict>
@@ -681,16 +598,18 @@
681598
</dict>
682599
</dict>
683600
<key>match</key>
684-
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
685-
<key>name</key>
686-
<string>variable.parameter.function.ruby</string>
601+
<string>\G(&amp;|\*\*?)?(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
687602
</dict>
688603
<dict>
689604
<key>include</key>
690605
<string>$self</string>
691606
</dict>
692607
</array>
693608
</dict>
609+
<dict>
610+
<key>include</key>
611+
<string>$self</string>
612+
</dict>
694613
</array>
695614
</dict>
696615
<dict>
@@ -1956,34 +1875,91 @@
19561875
<string>punctuation.separator.other.ruby</string>
19571876
</dict>
19581877
<dict>
1959-
<key>match</key>
1878+
<key>begin</key>
19601879
<string>\{</string>
1961-
<key>name</key>
1962-
<string>punctuation.section.scope.begin.ruby</string>
1963-
</dict>
1964-
<dict>
1965-
<key>match</key>
1880+
<key>beginCaptures</key>
1881+
<dict>
1882+
<key>0</key>
1883+
<dict>
1884+
<key>name</key>
1885+
<string>punctuation.section.scope.begin.ruby</string>
1886+
</dict>
1887+
</dict>
1888+
<key>end</key>
19661889
<string>\}</string>
1967-
<key>name</key>
1968-
<string>punctuation.section.scope.end.ruby</string>
1890+
<key>endCaptures</key>
1891+
<dict>
1892+
<key>0</key>
1893+
<dict>
1894+
<key>name</key>
1895+
<string>punctuation.section.scope.end.ruby</string>
1896+
</dict>
1897+
</dict>
1898+
<key>patterns</key>
1899+
<array>
1900+
<dict>
1901+
<key>include</key>
1902+
<string>$self</string>
1903+
</dict>
1904+
</array>
19691905
</dict>
19701906
<dict>
1971-
<key>match</key>
1907+
<key>begin</key>
19721908
<string>\[</string>
1973-
<key>name</key>
1974-
<string>punctuation.section.array.begin.ruby</string>
1975-
</dict>
1976-
<dict>
1977-
<key>match</key>
1909+
<key>beginCaptures</key>
1910+
<dict>
1911+
<key>0</key>
1912+
<dict>
1913+
<key>name</key>
1914+
<string>punctuation.section.array.begin.ruby</string>
1915+
</dict>
1916+
</dict>
1917+
<key>end</key>
19781918
<string>\]</string>
1979-
<key>name</key>
1980-
<string>punctuation.section.array.end.ruby</string>
1919+
<key>endCaptures</key>
1920+
<dict>
1921+
<key>0</key>
1922+
<dict>
1923+
<key>name</key>
1924+
<string>punctuation.section.array.end.ruby</string>
1925+
</dict>
1926+
</dict>
1927+
<key>patterns</key>
1928+
<array>
1929+
<dict>
1930+
<key>include</key>
1931+
<string>$self</string>
1932+
</dict>
1933+
</array>
19811934
</dict>
19821935
<dict>
1983-
<key>match</key>
1984-
<string>\(|\)</string>
1985-
<key>name</key>
1986-
<string>punctuation.section.function.ruby</string>
1936+
<key>begin</key>
1937+
<string>\(</string>
1938+
<key>beginCaptures</key>
1939+
<dict>
1940+
<key>0</key>
1941+
<dict>
1942+
<key>name</key>
1943+
<string>punctuation.section.function.ruby</string>
1944+
</dict>
1945+
</dict>
1946+
<key>end</key>
1947+
<string>\)</string>
1948+
<key>endCaptures</key>
1949+
<dict>
1950+
<key>0</key>
1951+
<dict>
1952+
<key>name</key>
1953+
<string>punctuation.section.function.ruby</string>
1954+
</dict>
1955+
</dict>
1956+
<key>patterns</key>
1957+
<array>
1958+
<dict>
1959+
<key>include</key>
1960+
<string>$self</string>
1961+
</dict>
1962+
</array>
19871963
</dict>
19881964
</array>
19891965
<key>repository</key>

Tests/method_arguments.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
def method; hello, world = [1,2] end
2+
3+
def method_with_parentheses(a, b, c = [foo,bar,baz]); hello, world = [1,2] end
4+
5+
def method_without_parentheses a, b, c = [foo,bar,baz]; hello, world = [1,2] end
6+
7+
def method
8+
hello, world = [1,2]
9+
end
10+
11+
def method_with_parentheses(a, b, c = [foo,bar,baz])
12+
hello, world = [1,2]
13+
end
14+
15+
def method_without_parentheses a, b, c = [foo,bar,baz]
16+
hello, world = [1,2]
17+
end
18+
19+
def method_with_parentheses(a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = {})
20+
hello, world = [1,2]
21+
do_something1
22+
do_something2
23+
end
24+
25+
def method_without_parentheses a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = ""
26+
hello, world = [1,2]
27+
do_something1
28+
do_something2
29+
end
30+
31+
def method_with_parentheses(a,
32+
b = hello, # test comment
33+
c = ["foo", bar, :baz],
34+
d = (2 + 2) * 2,
35+
e = {})
36+
hello, world = [1,2]
37+
do_something1
38+
do_something2
39+
end
40+
41+
def method_without_parentheses a,
42+
b = "hello" , # test comment
43+
c = ["foo", bar, :baz],
44+
d = (2 + 2) * 2,
45+
e = proc { |e| e + e }
46+
hello, world = [1,2]
47+
do_something1
48+
do_something2
49+
end
50+
51+
def method_without_parentheses a,
52+
b: hello , # test comment
53+
c: ["foo", bar, :baz],
54+
d: (2 + 2) * 2,
55+
e: proc { |e| e + e }
56+
hello, world = [1,2]
57+
do_something1
58+
do_something2
59+
end
60+
61+
# double splat, splat, and & opearator
62+
def method_with_parentheses(*a, **b, &c); hello, world = [1,2] end
63+
64+
def method_without_parentheses *a, **b, &c; hello, world = [1,2] end
65+
66+
def method_with_parentheses(*a, **b, &c)
67+
hello, world = [1,2]
68+
end
69+
70+
def method_without_parentheses *a, **b, &c
71+
hello, world = [1,2]
72+
end

0 commit comments

Comments
 (0)