rpr 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -15
- data/lib/rpr.rb +17 -8
- data/lib/rpr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3e4966534807640fa07c9c5a4582d307c144a8
|
4
|
+
data.tar.gz: 67524b5f039708d2800f08d7dc12c20365214cdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41e66cfb496f1b831061c85705c464e77e51836749c88fc2d9ba9faf63380a9054843d27732c164eed874e710ea455d525971597cdebd2f2e76217a554801a8f
|
7
|
+
data.tar.gz: 18a93ae0e9aa189af4efb868207c4a2ff27705c15a19bcbbdaf7a0d6b6ceee8dbc32dc0645f3b2f96169f305150d00484a3ae0b52e50ea0068309ec754da642f
|
data/README.md
CHANGED
@@ -36,25 +36,14 @@ $ rpr hello.rb
|
|
36
36
|
false]]]]
|
37
37
|
```
|
38
38
|
|
39
|
-
### Specify
|
39
|
+
### Specify Parser
|
40
40
|
|
41
41
|
Default: `sexp`
|
42
42
|
|
43
43
|
```sh
|
44
|
-
$ rpr hello.rb --
|
45
|
-
|
46
|
-
|
47
|
-
[:stmts_new],
|
48
|
-
[:command,
|
49
|
-
[:@ident, "puts", [1, 0]],
|
50
|
-
[:args_add_block,
|
51
|
-
[:args_add,
|
52
|
-
[:args_new],
|
53
|
-
[:string_literal,
|
54
|
-
[:string_add,
|
55
|
-
[:string_content],
|
56
|
-
[:@tstring_content, "Hello world", [1, 6]]]]],
|
57
|
-
false]]]]
|
44
|
+
$ rpr hello.rb --parser rubocop
|
45
|
+
s(:send, nil, :puts,
|
46
|
+
s(:str, "Hello world"))
|
58
47
|
```
|
59
48
|
|
60
49
|
```sh
|
data/lib/rpr.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rpr/config'
|
|
3
3
|
|
4
4
|
require 'ripper'
|
5
5
|
require 'optparse'
|
6
|
+
require 'stringio'
|
6
7
|
|
7
8
|
module Rpr
|
8
9
|
class << self
|
@@ -17,17 +18,23 @@ module Rpr
|
|
17
18
|
|
18
19
|
formatter = find_formatter(options[:formatter])
|
19
20
|
parser = find_parser(options[:parser])
|
20
|
-
args.each do |fname|
|
21
|
-
code = File.read(fname)
|
22
|
-
res = parser.parse(code)
|
23
21
|
|
22
|
+
if options[:expression]
|
23
|
+
res = parser.parse(options[:expression])
|
24
24
|
formatter.print(res)
|
25
|
+
else
|
26
|
+
args.each do |fname|
|
27
|
+
code = File.read(fname)
|
28
|
+
res = parser.parse(code)
|
29
|
+
|
30
|
+
formatter.print(res)
|
31
|
+
end
|
25
32
|
end
|
26
33
|
ensure
|
27
34
|
$stdout.close unless $stdout.tty?
|
28
35
|
end
|
29
36
|
|
30
|
-
# @param [
|
37
|
+
# @param [Symbol] name
|
31
38
|
# @return [Module]
|
32
39
|
def find_formatter(name)
|
33
40
|
require "rpr/formatter/#{name}"
|
@@ -36,7 +43,7 @@ module Rpr
|
|
36
43
|
raise "#{name} is unknown formatter."
|
37
44
|
end
|
38
45
|
|
39
|
-
# @param [
|
46
|
+
# @param [Symbol] name
|
40
47
|
# @return [Module]
|
41
48
|
def find_parser(name)
|
42
49
|
require "rpr/parser/#{name}"
|
@@ -51,13 +58,15 @@ module Rpr
|
|
51
58
|
formatter: :pp,
|
52
59
|
version: false,
|
53
60
|
parser: :sexp,
|
61
|
+
expression: nil,
|
54
62
|
}
|
55
63
|
|
56
64
|
opt = OptionParser.new
|
57
65
|
|
58
|
-
opt.on('-f=
|
59
|
-
opt.on('-o=
|
60
|
-
opt.on('-p=
|
66
|
+
opt.on('-f=FORMATTER', '--formatter=FORMATTER'){|v| res[:formatter] = v.to_sym}
|
67
|
+
opt.on('-o=FILE', '--out=FILE'){|v| $stdout = File.new(v, 'w')}
|
68
|
+
opt.on('-p=PARSER', '--parser=PARSER'){|v| res[:parser] = v.to_sym}
|
69
|
+
opt.on('-e=CODE'){|v| res[:expression] = v}
|
61
70
|
opt.on('-v', '--version'){|v| res[:version] = v}
|
62
71
|
|
63
72
|
opt.parse!(args)
|
data/lib/rpr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|