Skip to content

Commit

Permalink
Make sure end is a keyword, not a method name
Browse files Browse the repository at this point in the history
  • Loading branch information
graceful-potato committed Dec 18, 2019
1 parent 25449e8 commit dbb3a75
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 23 deletions.
24 changes: 12 additions & 12 deletions Syntaxes/Ruby.plist
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -238,7 +238,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -353,7 +353,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -433,7 +433,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -464,7 +464,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -495,7 +495,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -660,7 +660,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -732,7 +732,7 @@
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -1025,7 +1025,7 @@
<key>comment</key>
<string>the method pattern comes from the symbol pattern, see there for a explaination</string>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -1150,7 +1150,7 @@
<key>comment</key>
<string>same as the previous rule, but without parentheses around the arguments</string>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand All @@ -1167,7 +1167,7 @@
<key>begin</key>
<string>(?![\s,])</string>
<key>end</key>
<string>(?=,|\bend\b|$)</string>
<string>(?=,|(?&lt;!\.|::)\bend\b(?![?!])|$)</string>
<key>patterns</key>
<array>
<dict>
Expand Down Expand Up @@ -1233,7 +1233,7 @@
<key>comment</key>
<string> the optional name is just to catch the def also without a method-name</string>
<key>end</key>
<string>\bend\b</string>
<string>(?&lt;!\.|::)\bend\b(?![?!])</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down
129 changes: 118 additions & 11 deletions Tests/end_distinction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,63 +36,97 @@ class Foo
# singleline
def a; puts "a"; end
def b; def c; puts "c"; end; end
def d; puts self.end; end

# multiline
def d
puts "d"
def e
puts "e"
end

def e
def f
puts "f"
def f
def g
puts "g"
end
end

def h
puts self.end
end

def i
end? # self.end?
end! # self.end!
end

# -------------------------------------------
# Testarea for method with arguments
# -------------------------------------------

# singleline
def a(arg); puts arg; end
def b; def c(arg); puts arg; end; end
def d(arg); puts arg.end; end

# multiline
def d(arg)
def e(arg)
puts arg
end

def e
def f(arg)
def f
def g(arg)
puts arg
end
end

def h(arg)
puts arg.end
end

def i(arg)
end? # self.end?
end! # self.end!
end

# -------------------------------------------
# Testarea for method with arguments without parenthesis
# -------------------------------------------

# singleline
def a arg; puts arg; end
def b; def c arg; puts arg; end; end
def d arg; puts arg.end; end

# multiline
def d arg
def e arg
puts arg
end

def e
def f arg
def f
def g arg
puts arg
end
end

def h arg
puts arg.end
end

def i arg
end? # self.end?
end! # self.end!
end

# -------------------------------------------
# Testarea for begin-block
# -------------------------------------------

# singleline
begin puts "foo" end
begin puts "foo"; begin puts "bar" end end
begin puts self.end end
begin puts self.end; end
begin puts end? end
begin puts end!; end
if begin true end then true else false end
1..begin 10 end
1...begin 10 end
Expand All @@ -107,6 +141,15 @@ def f arg
puts "foo"
end

begin
puts self.end
end

begin
puts end?
puts end!
end

begin
puts "foo"
begin
Expand All @@ -122,6 +165,7 @@ def f arg
3.times.map do 1 end
3.times.map do || 1 end
3.times.map do |e, x=1| e + x end
[(0..10), (10..20)].map do |r| r.end end
any_method do? 1 end #shouldn't work
any_method do! 1 end #shouldn't work
self.do 1 end #shouldn't work
Expand All @@ -138,6 +182,14 @@ def f arg
end
end

[(0..10), (10..20)].map do |r|
r.end
end

[].each do |e|
e + end? - end!
end

3.times do
puts "foo"
end
Expand All @@ -156,6 +208,8 @@ def f arg
for i in for j in [[1,2]]; break j; end; [i].map do |e| e end; end
for i in for j in if true then [[1,2]] else [[3,4]] end; break j; end; [i].map do |e| e end; end
for i in for j in if true; [[1,2]] else [[3,4]] end; break j; end; [i].map do |e| e end; end
for i in [(0..10), (10..20)] do break i.end end
for i in [] do puts end?; puts end! end
1..for i in [1,2,3] do break i if i == 2; end
1...for i in [1,2,3] do break i if i == 2; end
10 / for i in [1,2,3] do break i if i == 2; end
Expand All @@ -170,6 +224,15 @@ def f arg
puts i
end

for i in [(0..10), (10..20)] do
puts i.end
end

for i in []
puts end?
puts end!
end

for i in for j in [[1,2]] do break j; end do
r = [i].map do |e|
e
Expand Down Expand Up @@ -202,6 +265,8 @@ def f arg
while i < while j < 10; break j if j == 5; j+=1; end do break i if i > 3; i += 1; end
while i < while j < 10 do break j if j == 5; j+=1; end do break i if i > 3; i += 1; end
while false do [1,2,3].each do |e| puts e end; end
while false do [(0..10), (10..20)].each do |r| puts r.end end end
while false do puts end?; puts end! end

# singleline modifier
foo::while false # shouldn't work
Expand Down Expand Up @@ -236,6 +301,17 @@ def f arg
i += 1
end

while false do
[(0..10), (10..20)].each do |r|
puts r.end
end
end

while false do
puts end?
puts end!
end

begin
i += 1
end; while i < 100 do i += 1; end
Expand Down Expand Up @@ -267,6 +343,8 @@ def f arg
true && ! if true then true else false end
a = /hello/; 20 / if true then 1 else 2 end
a = /hello/; if true then 1 else 2 end
if true then puts (1..10).end else puts (1..20).end end
if true then puts end? else puts end! end

# singleline modifier
foo::if something # shouldn't work
Expand Down Expand Up @@ -300,6 +378,18 @@ def f arg
baz
end

if true
puts (1..10).end
else
puts (1..20).end
end

if true
puts end?
else
puts end!
end

begin
1
end; if true; true else false end
Expand All @@ -318,6 +408,8 @@ def f arg
case x = rand(1..100) when 0..50 then case x when 0..25 then 1 else 2 end when 51..100 then case x when 51..75 then 3 else 4 end end
1..case 15 when 0..50 then 10 when 51..100 then 20 else 30 end
1...case 15 when 0..50 then 10 when 51..100 then 20 else 30 end
case x = rand(1..100) when 0..50 then puts (1..10).end when 51..100 then puts (1..20).end end
case x = rand(1..100) when 0..50 then puts end? when 51..100 then puts end! end

self.case 15 when 0..50 then "foo" when 51..100 then "bar" else "baz" end # shouldn't work
self::case 15 when 0..50 then "foo" when 51..100 then "bar" else "baz" end # shouldn't work
Expand All @@ -334,6 +426,21 @@ def f arg
"baz"
end

case x = rand(1..100)
when 0..50 then
puts (1..10).end
when 51..100 then
puts (1..20).end
end

case x = rand(1..100)
when 0..50 then
puts end?
when 51..100 then
puts end!
end


case if [true, false].sample then 25 else 75 end
when 0..50
"foo"
Expand Down

0 comments on commit dbb3a75

Please sign in to comment.