Skip to content

Commit e466843

Browse files
Fixed optional do for while loop.
1 parent 861e8d9 commit e466843

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

Syntaxes/Ruby.plist

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
</dict>
318318
<dict>
319319
<key>begin</key>
320-
<string>\b(for)\b(?![?!])</string>
320+
<string>(?&lt;!^\.|[^.]\.|::)\b(for)\b(?![?!])</string>
321321
<key>beginCaptures</key>
322322
<dict>
323323
<key>1</key>
@@ -387,7 +387,7 @@
387387
</dict>
388388
<dict>
389389
<key>begin</key>
390-
<string>(?&lt;![^.]\.|::)\b(do)\b(?![?!])\s*(\|[^|]*\|)?</string>
390+
<string>(?&lt;!^\.|[^.]\.|::)\b(do)\b(?![?!])\s*(\|[^|]*\|)?</string>
391391
<key>beginCaptures</key>
392392
<dict>
393393
<key>1</key>
@@ -428,7 +428,7 @@
428428
</dict>
429429
<dict>
430430
<key>begin</key>
431-
<string>(?&lt;![^.]\.|::)\b(begin)\b(?![?!])</string>
431+
<string>(?&lt;!^\.|[^.]\.|::)\b(begin)\b(?![?!])</string>
432432
<key>beginCaptures</key>
433433
<dict>
434434
<key>1</key>
@@ -459,7 +459,7 @@
459459
</dict>
460460
<dict>
461461
<key>begin</key>
462-
<string>(?&lt;![^.]\.|::)\b(case)\b(?![?!])</string>
462+
<string>(?&lt;!^\.|[^.]\.|::)\b(case)\b(?![?!])</string>
463463
<key>beginCaptures</key>
464464
<dict>
465465
<key>1</key>
@@ -695,7 +695,7 @@
695695
\Win|^in|
696696
\W!|^!|
697697
\W\?|^\?)
698-
\s*\b(while|until)\b(?![?!])\s*((?:.+?)(?=do)|(?:.+?)(?=;)|(?:.+?)(?=$))(\bdo\b)?
698+
\s*\b(while|until)\b(?![?!])
699699
</string>
700700
<key>beginCaptures</key>
701701
<dict>
@@ -704,26 +704,7 @@
704704
<key>name</key>
705705
<string>keyword.control.while-until.begin.ruby</string>
706706
</dict>
707-
<key>2</key>
708-
<dict>
709-
<key>name</key>
710-
<string>source.ruby</string>
711-
<key>patterns</key>
712-
<array>
713-
<dict>
714-
<key>include</key>
715-
<string>$self</string>
716-
</dict>
717-
</array>
718-
</dict>
719-
<key>3</key>
720-
<dict>
721-
<key>name</key>
722-
<string>keyword.control.do.optional.ruby</string>
723-
</dict>
724707
</dict>
725-
<key>comment</key>
726-
<string> the optional name is just to catch the def also without a method-name</string>
727708
<key>end</key>
728709
<string>\bend\b</string>
729710
<key>endCaptures</key>
@@ -738,6 +719,27 @@
738719
<string>meta.syntax.while-until-block.ruby</string>
739720
<key>patterns</key>
740721
<array>
722+
<dict>
723+
<key>begin</key>
724+
<string>\G</string>
725+
<key>end</key>
726+
<string>(?&lt;!\.)(\bdo\b)(?![?!])|;|$</string>
727+
<key>endCaptures</key>
728+
<dict>
729+
<key>1</key>
730+
<dict>
731+
<key>name</key>
732+
<string>keyword.control.do.optional.ruby</string>
733+
</dict>
734+
</dict>
735+
<key>patterns</key>
736+
<array>
737+
<dict>
738+
<key>include</key>
739+
<string>$self</string>
740+
</dict>
741+
</array>
742+
</dict>
741743
<dict>
742744
<key>include</key>
743745
<string>$self</string>
@@ -746,13 +748,13 @@
746748
</dict>
747749
<dict>
748750
<key>match</key>
749-
<string>(?&lt;![^.]\.|::)\brescue\b(?![?!])</string>
751+
<string>(?&lt;!^\.|[^.]\.|::)\brescue\b(?![?!])</string>
750752
<key>name</key>
751753
<string>keyword.control.rescue.ruby</string>
752754
</dict>
753755
<dict>
754756
<key>match</key>
755-
<string>(?&lt;![^.]\.|::)\bensure\b(?![?!])</string>
757+
<string>(?&lt;!^\.|[^.]\.|::)\bensure\b(?![?!])</string>
756758
<key>name</key>
757759
<string>keyword.control.ensure.ruby</string>
758760
</dict>

Tests/end_distinction.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,23 @@ def f arg
127127
1..for i in [1,2,3] do break i if i == 2; end
128128
1...for i in [1,2,3] do break i if i == 2; end
129129
10 / for i in [1,2,3] do break i if i == 2; end
130-
131-
132130
#you cant use do-end blocks inside in statement
133131
for i in 3.times.map do 1 end do puts i; end # shouldn't work
134132
for? i in [1,2,3] # shouldn't work
133+
for! i in [1,2,3] # shouldn't work
134+
self.for i in [1,2,3] # shouldn't work
135+
136+
# multiline
137+
for i in [1,2,3]
138+
puts i
139+
end
140+
141+
for i in for j in [[1,2]] do break j; end do
142+
r = [i].map do |e|
143+
e
144+
end
145+
p r
146+
end
135147

136148
# -------------------------------------------
137149
# Testarea for while/until
@@ -157,6 +169,7 @@ def f arg
157169
while i < while j < 10 do break j if j == 5; j+=1; end; break i if i > 3; i += 1; end
158170
while i < while j < 10; break j if j == 5; j+=1; end do break i if i > 3; i += 1; end
159171
while i < while j < 10 do break j if j == 5; j+=1; end do break i if i > 3; i += 1; end
172+
while false do [1,2,3].each do |e| puts e end; end
160173

161174
# singleline modifier
162175
foo::while false # shouldn't work

0 commit comments

Comments
 (0)