ripl-multi_line 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +3 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +4 -3
- data/Rakefile +5 -3
- data/lib/ripl/multi_line.rb +1 -2
- data/lib/ripl/multi_line/error_check.rb +4 -7
- data/lib/ripl/multi_line/irb.rb +1 -1
- data/lib/ripl/multi_line/live_error.rb +64 -49
- data/lib/ripl/multi_line/ripper.rb +2 -2
- data/lib/ripl/multi_line/version.rb +6 -0
- data/{.gemspec → ripl-multi_line.gemspec} +2 -2
- data/test/shell_test.rb +23 -18
- metadata +89 -70
- data/deps.rip +0 -1
data/CHANGELOG.rdoc
CHANGED
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -56,7 +56,8 @@ None of the above solutions is perfect, so... maybe it's time to roll your own ;
|
|
56
56
|
Ripl::MultiLine.engine = Ripl::MultiLine::LiveError
|
57
57
|
Ripl::Shell.include Ripl::MultiLine.engine
|
58
58
|
|
59
|
-
==
|
60
|
-
|
59
|
+
== TODO
|
60
|
+
* Write thousands of test cases
|
61
61
|
|
62
|
-
J-_-L
|
62
|
+
== J-_-L
|
63
|
+
Contributions & influences by cldwalker and godfat.
|
data/Rakefile
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
+
GEMSPEC_NAME = Dir['*.gemspec'].first
|
5
|
+
|
4
6
|
def gemspec
|
5
|
-
@gemspec ||= eval(File.read(
|
7
|
+
@gemspec ||= eval(File.read(GEMSPEC_NAME), binding, GEMSPEC_NAME)
|
6
8
|
end
|
7
9
|
|
8
10
|
desc "Build the gem"
|
9
11
|
task :gem => :gemspec do
|
10
|
-
sh "gem build
|
12
|
+
sh "gem build #{GEMSPEC_NAME}"
|
11
13
|
FileUtils.mkdir_p 'pkg'
|
12
14
|
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
15
|
end
|
14
16
|
|
15
17
|
desc "Install the gem locally"
|
16
18
|
task :install => :gem do
|
17
|
-
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
|
19
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}.gem --no-rdoc --no-ri}
|
18
20
|
end
|
19
21
|
|
20
22
|
desc "Generate the gemspec"
|
data/lib/ripl/multi_line.rb
CHANGED
@@ -5,15 +5,12 @@ require 'ripl/multi_line'
|
|
5
5
|
require 'ripl/multi_line/live_error'
|
6
6
|
|
7
7
|
# # # #
|
8
|
-
# This multi-line implementation uses
|
9
|
-
# works on: 1.9 1.8 jruby rbx
|
8
|
+
# This multi-line implementation uses catches the syntax errors that are yielded by unfinsihed statements
|
9
|
+
# works on: 2.0 1.9 1.8 jruby rbx
|
10
10
|
# analyze features: see live_error.rb
|
11
11
|
# known issues: see live_error.rb
|
12
12
|
module Ripl::MultiLine::ErrorCheck
|
13
|
-
VERSION = '0.
|
14
|
-
|
15
|
-
ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE.downcase.to_sym
|
16
|
-
ruby_engine = :ruby if !Ripl::MultiLine::LiveError::ERROR_MESSAGES.keys.include?(ruby_engine)
|
13
|
+
VERSION = '0.2.0'
|
17
14
|
|
18
15
|
define_method(:multiline?) do |string|
|
19
16
|
break [:forced] if string =~ /;\s*\Z/ # force multi line with ;
|
@@ -21,7 +18,7 @@ module Ripl::MultiLine::ErrorCheck
|
|
21
18
|
begin
|
22
19
|
eval "if nil; #{string}; end"
|
23
20
|
rescue SyntaxError => e
|
24
|
-
Ripl::MultiLine::LiveError::ERROR_MESSAGES[ruby_engine].each{ |type, message|
|
21
|
+
Ripl::MultiLine::LiveError::ERROR_MESSAGES[Ripl::MultiLine::LiveError.ruby_engine].each{ |type, message|
|
25
22
|
break type if message === e.message
|
26
23
|
}
|
27
24
|
end
|
data/lib/ripl/multi_line/irb.rb
CHANGED
@@ -4,8 +4,8 @@ Ripl.config[:multi_line_engine] ||= :live_error
|
|
4
4
|
require 'ripl/multi_line'
|
5
5
|
|
6
6
|
# # # #
|
7
|
-
# This multi-line implementation uses
|
8
|
-
# works on: 1.9 1.8 jruby rbx
|
7
|
+
# This multi-line implementation uses catches the syntax errors that are yielded by unfinsihed statements
|
8
|
+
# works on: 2.0 1.9 1.8 jruby rbx
|
9
9
|
# analyze features: [:literal, :string]
|
10
10
|
# [:literal, :regexp]
|
11
11
|
# [:literal, :array] (mri only)
|
@@ -13,59 +13,74 @@ require 'ripl/multi_line'
|
|
13
13
|
# [:statement]
|
14
14
|
# [:forced]
|
15
15
|
# notes: rbx support buggy (depends on rubinius error messages)
|
16
|
-
module Ripl::MultiLine
|
17
|
-
|
16
|
+
module Ripl::MultiLine
|
17
|
+
module LiveError
|
18
|
+
VERSION = "0.2.0"
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
],
|
27
|
-
:jruby => [
|
28
|
-
[[:literal, :string], /unterminated string meets end of file/],
|
29
|
-
[[:literal, :regexp], /unterminated regexp meets end of file/], # array or hash cannot be detected
|
30
|
-
[[:statement], /syntax error, unexpected end-of-file/],
|
31
|
-
],
|
32
|
-
:rbx => [
|
33
|
-
[[:literal, :string], /unterminated [a-z]+ meets end of file/], # no extra message for regexes
|
34
|
-
[[:literal], /expecting '\\n' or ';'/], # TODO: better rbx regexes or rbx bug report
|
35
|
-
[[:literal, :hash], /expecting '\}'/],
|
36
|
-
# [:literal, /expecting '\]'/],
|
37
|
-
# [:literal, /expecting '\)'/],
|
38
|
-
[[:statement], /syntax error, unexpected \$end/],
|
39
|
-
[[:statement], /missing 'end'/], # for i in [2,3,4] do;
|
40
|
-
],
|
41
|
-
}
|
42
|
-
ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE.downcase.to_sym
|
43
|
-
ruby_engine = :ruby if !ERROR_MESSAGES.keys.include?(ruby_engine)
|
20
|
+
def self.ruby_engine
|
21
|
+
return @ruby_engine if defined? @ruby_engine
|
22
|
+
@ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE.downcase.to_sym
|
23
|
+
@ruby_engine = :ruby if !ERROR_MESSAGES.keys.include?(ruby_engine) # 1.8 is same as 1.9
|
24
|
+
@ruby_engine = :ruby19 if ruby_engine == :ruby && RUBY_VERSION <= "2.0"
|
25
|
+
@ruby_engine
|
26
|
+
end
|
44
27
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
28
|
+
ERROR_MESSAGES = {
|
29
|
+
:ruby => [
|
30
|
+
[[:literal, :string], /unterminated string meets end of file/],
|
31
|
+
[[:literal, :regexp], /unterminated regexp meets end of file/],
|
32
|
+
[[:literal, :array], /syntax error, unexpected end-of-input, expecting '\]'/],
|
33
|
+
[[:literal, :hash], /syntax error, unexpected end-of-input, expecting '\}'/], # does not work for ranges or {5=>
|
34
|
+
[[:statement], /syntax error, unexpected end-of-input/],
|
35
|
+
],
|
36
|
+
:ruby19 => [
|
37
|
+
[[:literal, :string], /unterminated string meets end of file/],
|
38
|
+
[[:literal, :regexp], /unterminated regexp meets end of file/],
|
39
|
+
[[:literal, :array], /syntax error, unexpected \$end, expecting '\]'/],
|
40
|
+
[[:literal, :hash], /syntax error, unexpected \$end, expecting '\}'/], # does not work for ranges or {5=>
|
41
|
+
[[:statement], /syntax error, unexpected \$end/],
|
42
|
+
],
|
43
|
+
:jruby => [
|
44
|
+
[[:literal, :string], /unterminated string meets end of file/],
|
45
|
+
[[:literal, :regexp], /unterminated regexp meets end of file/], # array or hash cannot be detected
|
46
|
+
[[:statement], /syntax error, unexpected end-of-file/],
|
47
|
+
],
|
48
|
+
:rbx => [
|
49
|
+
[[:literal, :string], /unterminated [a-z]+ meets end of file/], # no extra message for regexes
|
50
|
+
[[:literal], /expecting '\\n' or ';'/], # TODO: better rbx regexes or rbx bug report
|
51
|
+
[[:literal, :hash], /expecting '\}'/],
|
52
|
+
# [:literal, /expecting '\]'/],
|
53
|
+
# [:literal, /expecting '\)'/],
|
54
|
+
[[:statement], /syntax error, unexpected \$end/],
|
55
|
+
[[:statement], /missing 'end'/], # for i in [2,3,4] do;
|
56
|
+
],
|
57
|
+
}
|
58
|
+
|
59
|
+
define_method(:print_eval_error) do |e|
|
60
|
+
if e.is_a? SyntaxError
|
61
|
+
ERROR_MESSAGES[LiveError.ruby_engine].each{ |type, message|
|
62
|
+
handle_multiline(type) if message === e.message
|
63
|
+
}
|
64
|
+
end
|
65
|
+
super(e)
|
50
66
|
end
|
51
|
-
super(e)
|
52
|
-
end
|
53
67
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
68
|
+
def eval_input(input)
|
69
|
+
if input =~ /;\s*\Z/ # force multi line with ;
|
70
|
+
handle_multiline(:forced)
|
71
|
+
elsif input =~ /^=begin(\s.*)?$/ && !@buffer
|
72
|
+
@ignore_mode = true # MAYBE: change prompt
|
73
|
+
elsif !@ignore_mode
|
74
|
+
super
|
75
|
+
end
|
61
76
|
end
|
62
|
-
end
|
63
77
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
def print_result(result)
|
79
|
+
if @ignore_mode && @input == '=end'
|
80
|
+
@ignore_mode = false
|
81
|
+
elsif !@ignore_mode
|
82
|
+
super
|
83
|
+
end
|
69
84
|
end
|
70
85
|
end
|
71
86
|
end
|
@@ -6,8 +6,8 @@ Ripl.config[:multi_line_engine] ||= :ripper
|
|
6
6
|
require 'ripl/multi_line'
|
7
7
|
|
8
8
|
# # # #
|
9
|
-
# This multi-line implementation uses
|
10
|
-
# works on: 1.9 1.8(gem)
|
9
|
+
# This multi-line implementation uses Ripper
|
10
|
+
# works on: 2.0 1.9 1.8(gem)
|
11
11
|
# analyze features: [:literal, :string]
|
12
12
|
# [:literal, :regexp]
|
13
13
|
# [:literal, :array] (mri only)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'rubygems' unless defined? Gem
|
3
|
-
require File.dirname(__FILE__) + "/lib/ripl/multi_line"
|
3
|
+
require File.dirname(__FILE__) + "/lib/ripl/multi_line/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "ripl-multi_line"
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_development_dependency 'bacon-bits'
|
17
17
|
s.add_development_dependency 'bacon-rr'
|
18
18
|
s.add_development_dependency 'rr'
|
19
|
-
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip
|
19
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip Rakefile *.gemspec])
|
20
20
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
21
21
|
s.license = 'MIT'
|
22
22
|
end
|
data/test/shell_test.rb
CHANGED
@@ -8,24 +8,29 @@ describe "Shell" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "multi-line behaviour" do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
%w[live_error error_check ripper irb].each { |engine|
|
12
|
+
describe "[#{engine}]" do
|
13
|
+
should_eval %| "m" * 2 |
|
14
|
+
should_eval %| "8989" |
|
15
|
+
should_eval %| "zzz" |
|
16
|
+
|
17
|
+
should_not_eval %| "m" * |
|
18
|
+
|
19
|
+
should_not_eval %| " |
|
20
|
+
should_not_eval %| ' |
|
21
|
+
should_not_eval %| / |
|
22
|
+
|
23
|
+
should_not_eval %| [ |
|
24
|
+
should_not_eval %| { |
|
25
|
+
should_not_eval %| ( |
|
26
|
+
|
27
|
+
should_not_eval %| def hey |
|
28
|
+
should_not_eval %| def hey; 89 |
|
29
|
+
should_not_eval %| begin |
|
30
|
+
should_not_eval %| module Foo |
|
31
|
+
should_eval %| for x in [2,3,4];7;end |
|
32
|
+
end
|
33
|
+
}
|
29
34
|
end
|
30
35
|
|
31
36
|
# TODO add misc real tests for everything
|
metadata
CHANGED
@@ -1,122 +1,141 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-multi_line
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Jan Lelis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: ripl
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.3.6
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: bacon
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
25
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bacon
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
34
37
|
version: 1.1.0
|
35
38
|
type: :development
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: bacon-bits
|
39
39
|
prerelease: false
|
40
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bacon-bits
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
46
54
|
type: :development
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: bacon-rr
|
50
55
|
prerelease: false
|
51
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
57
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bacon-rr
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
57
70
|
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: rr
|
61
71
|
prerelease: false
|
62
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
73
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rr
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
68
86
|
type: :development
|
69
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
70
94
|
description: This ripl plugin allows you to evaluate multiple lines of Ruby code.
|
71
95
|
email: mail@janlelis.de
|
72
96
|
executables: []
|
73
|
-
|
74
97
|
extensions: []
|
75
|
-
|
76
|
-
extra_rdoc_files:
|
98
|
+
extra_rdoc_files:
|
77
99
|
- README.rdoc
|
78
100
|
- LICENSE.txt
|
79
|
-
files:
|
80
|
-
- lib/ripl/multi_line.rb
|
101
|
+
files:
|
81
102
|
- lib/ripl/multi_line/live_error.rb
|
82
|
-
- lib/ripl/multi_line/
|
103
|
+
- lib/ripl/multi_line/irb.rb
|
104
|
+
- lib/ripl/multi_line/version.rb
|
83
105
|
- lib/ripl/multi_line/ripper.rb
|
84
106
|
- lib/ripl/multi_line/ruby_parser.rb
|
85
|
-
- lib/ripl/multi_line/
|
86
|
-
-
|
107
|
+
- lib/ripl/multi_line/error_check.rb
|
108
|
+
- lib/ripl/multi_line.rb
|
87
109
|
- test/shell_test.rb
|
110
|
+
- test/test_helper.rb
|
88
111
|
- LICENSE.txt
|
89
112
|
- README.rdoc
|
90
113
|
- CHANGELOG.rdoc
|
91
|
-
- deps.rip
|
92
114
|
- Rakefile
|
93
|
-
- .gemspec
|
115
|
+
- ripl-multi_line.gemspec
|
94
116
|
homepage: http://github.com/janlelis/ripl-multi_line
|
95
|
-
licenses:
|
117
|
+
licenses:
|
96
118
|
- MIT
|
97
119
|
post_install_message:
|
98
120
|
rdoc_options: []
|
99
|
-
|
100
|
-
require_paths:
|
121
|
+
require_paths:
|
101
122
|
- lib
|
102
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
124
|
none: false
|
104
|
-
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
version:
|
108
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
130
|
none: false
|
110
|
-
requirements:
|
111
|
-
- -
|
112
|
-
- !ruby/object:Gem::Version
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
113
134
|
version: 1.3.6
|
114
135
|
requirements: []
|
115
|
-
|
116
136
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
137
|
+
rubygems_version: 1.8.25
|
118
138
|
signing_key:
|
119
139
|
specification_version: 3
|
120
140
|
summary: A ripl plugin for multi-line eval.
|
121
141
|
test_files: []
|
122
|
-
|
data/deps.rip
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ripl >=0.3.0
|