From 0036681bf6c055ebee1853137ab7bb015c6deff7 Mon Sep 17 00:00:00 2001 From: egwspiti Date: Fri, 9 Oct 2015 18:36:51 +0300 Subject: [PATCH 1/2] Lines ending with $\ are not incomplete. --- lib/method_source/code_helpers.rb | 4 ++-- test/test_code_helpers.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/method_source/code_helpers.rb b/lib/method_source/code_helpers.rb index 6c1d53e..2ea5535 100644 --- a/lib/method_source/code_helpers.rb +++ b/lib/method_source/code_helpers.rb @@ -71,8 +71,8 @@ def complete_expression?(str) eval("BEGIN{throw :valid}\n#{str}") end - # Assert that a line which ends with a , or \ is incomplete. - str !~ /[,\\]\s*\z/ + # Assert that a line which ends with a , or \ but not with $\ is incomplete. + str !~ /(,|[^\$]\\)\s*\z/ rescue IncompleteExpression false ensure diff --git a/test/test_code_helpers.rb b/test/test_code_helpers.rb index ba83a63..7706630 100644 --- a/test/test_code_helpers.rb +++ b/test/test_code_helpers.rb @@ -38,4 +38,8 @@ }.should.raise(SyntaxError) end end + + it "should consider as complete lines ending with $\\" do + @tester.complete_expression?('$\\').should == true + end end From 809dada4053433519c488371216660c0857f8d8c Mon Sep 17 00:00:00 2001 From: egwspiti Date: Sun, 11 Oct 2015 22:04:16 +0300 Subject: [PATCH 2/2] Do not create a capture group. --- lib/method_source/code_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/method_source/code_helpers.rb b/lib/method_source/code_helpers.rb index 2ea5535..210100a 100644 --- a/lib/method_source/code_helpers.rb +++ b/lib/method_source/code_helpers.rb @@ -72,7 +72,7 @@ def complete_expression?(str) end # Assert that a line which ends with a , or \ but not with $\ is incomplete. - str !~ /(,|[^\$]\\)\s*\z/ + str !~ /(?:,|[^\$]\\)\s*\z/ rescue IncompleteExpression false ensure