proc_to_ast 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 925e6d8267b75283f13ded71a1f3b17c747a0e6a
4
- data.tar.gz: d9d509c4e5e5ab3024d77ced8016e4a34c00aa7b
3
+ metadata.gz: 5095ab2d916faa3c0fa5d451e7eb2aca7986033c
4
+ data.tar.gz: 6e5fb00aabf284d7b201398687ed7d7d85449e4d
5
5
  SHA512:
6
- metadata.gz: fb81eb0cdeae93b38caa1e77751aceba8804d09e4f5866e7507b0cfad3dbbb8f2eb190a33abfc0e2c5461e91ee11cc2828e7dd69666be00b17d040cc7c3466e5
7
- data.tar.gz: 3e7be1ee19e6497959c8244437547587b18b2665456fdbbaf087c59d359c32a80ccf23dfde1e21400432a1a94fda6f2136a662a968a2304204cdced0cd55ccf3
6
+ metadata.gz: 5573a429abb1df2000f597e755cca7b1871e4ec3cbb64109286463aed93672f1c2820bbfe40fbfe4eb74a046d78364f2f55a36049f65d2db56af1c474bce6cce
7
+ data.tar.gz: e17eaab3f8e06e26b55d77725301a53acfa38622cdaa87e65300923e7b811b85fc39c0d5e6e79b675eaaf2598b33781425f97ce3025b8cb2c5df0d8b3a808708
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
- cache: bundler
2
+ sudo: false
3
3
  rvm:
4
- - 2.1.1
5
- - 2.0.0
4
+ - 2.2.2
5
+ - 2.1
6
+ - 2.0
6
7
  notifications:
7
8
  email:
8
9
  on_success: change
@@ -20,31 +20,21 @@ module ProcToAst
20
20
  #
21
21
  # @param filename [String] reading file path
22
22
  # @param linenum [Integer] start line number
23
- # @param retry_limit [Integer]
24
23
  # @return [Parser::AST::Node] Proc AST
25
- def parse(filename, linenum, retry_limit = 20)
24
+ def parse(filename, linenum)
26
25
  @filename, @linenum = filename, linenum
27
- file = File.open(filename, "rb")
28
-
29
- (linenum - 1).times { file.gets }
30
26
  buf = []
31
- try_count = 0
32
-
33
- begin
34
- try_count += 1
35
-
36
- buf << file.gets
37
- do_parse(buf.join)
38
- rescue ::Parser::SyntaxError => e
39
- node = trim_and_retry(buf)
40
-
41
- return node unless node.nil?
42
- retry if try_count < retry_limit
43
-
44
- raise e
45
- ensure
46
- file.close
27
+ File.open(filename, "rb").each_with_index do |line, index|
28
+ next if index < linenum - 1
29
+ buf << line
30
+ begin
31
+ return do_parse(buf.join)
32
+ rescue ::Parser::SyntaxError
33
+ node = trim_and_retry(buf)
34
+ return node if node
35
+ end
47
36
  end
37
+ fail(::Parser::SyntaxError, 'Unknown error')
48
38
  end
49
39
 
50
40
  private
@@ -90,19 +80,17 @@ module ProcToAst
90
80
  end
91
81
 
92
82
  class Proc
93
- # @param retry_limit [Integer]
94
83
  # @return [Parser::AST::Node] Proc AST
95
- def to_ast(retry_limit = 20)
84
+ def to_ast
96
85
  filename, linenum = source_location
97
86
  parser = ProcToAst::Parser.new
98
- parser.parse(filename, linenum, retry_limit)
87
+ parser.parse(filename, linenum)
99
88
  end
100
89
 
101
90
  # @param highlight [Boolean] enable output highlight
102
- # @param retry_limit [Integer]
103
91
  # @return [String] proc source code
104
- def to_source(highlight: false, retry_limit: 20)
105
- source = Unparser.unparse(to_ast(retry_limit))
92
+ def to_source(highlight: false)
93
+ source = Unparser.unparse(to_ast)
106
94
  if highlight
107
95
  CodeRay.scan(source, :ruby).terminal
108
96
  else
@@ -110,8 +98,8 @@ class Proc
110
98
  end
111
99
  end
112
100
 
113
- def to_raw_source(highlight: false, retry_limit: 20)
114
- source = to_ast(retry_limit).loc.expression.source
101
+ def to_raw_source(highlight: false)
102
+ source = to_ast.loc.expression.source
115
103
 
116
104
  if highlight
117
105
  CodeRay.scan(source, :ruby).terminal
@@ -1,3 +1,3 @@
1
1
  module ProcToAst
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -23,6 +23,32 @@ describe Proc do
23
23
  expect(pr.to_ast).to be_a(AST::Node)
24
24
  end
25
25
 
26
+ it "long proc" do
27
+ pr = Proc.new do |b|
28
+ p 1
29
+ p 1
30
+ p 1
31
+ p 1
32
+ p 1
33
+ p 1
34
+ p 1
35
+ p 1
36
+ p 1
37
+ p 1
38
+ p 1
39
+ p 1
40
+ p 1
41
+ p 1
42
+ p 1
43
+ p 1
44
+ p 1
45
+ p 1
46
+ p 1
47
+ end
48
+
49
+ expect(pr.to_ast).to be_a(AST::Node)
50
+ end
51
+
26
52
  it "converts block passing method" do
27
53
  def receive_block(&block)
28
54
  block.to_ast
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proc_to_ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-01 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.6
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Convert Proc object to AST::Node