decode 0.17.3 → 0.18.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
  SHA256:
3
- metadata.gz: a838fd5f42db321e8afe7627740faca8a0bce85e66016b1a9f5eac4c1b800e13
4
- data.tar.gz: 2d2e88c8dfbddaf2507f8b94ef7b3678247640ff48768dd8971afe4bca32a579
3
+ metadata.gz: 07565b4d2600fe3cd6552192f8faae065fbd728e98f51008863326a1b4f7f743
4
+ data.tar.gz: a16e3cf053d0ac25c9e0f2e596832dabf44f027edf0ad509ed7eb20559d685e5
5
5
  SHA512:
6
- metadata.gz: 2fd7f4dc09a37c14d87750e3cf12ed22f6352877a382ab6a08f8571b48d774761fa2deb6dcc7382bb43868361774816d018c086f3ae2e0b0908a89c8e9704154
7
- data.tar.gz: e6b60875db3b53417736599852a9354eabbdc08503b3dda594bd364df7c98fa84702303917f27c7850054ab40d0f5c25b018a0a9919bf07a9e7d922cd8b480fb
6
+ metadata.gz: a1e7ccf9434ddd07c98ce94e64741f30af06698b9841935b99ecc0f7e5027aa76a8ce97778bade6cdaf25853f03d7ec8d2372715bd328ada2b844b4daf68c2a5
7
+ data.tar.gz: 69d195150f777b3484de296ef8d093e6531856bbc111d3d75e58d806478ecb84506223f5e5372656c06df28e8e1e326817f287dcc680c9055e7286b58fd9a2d2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -18,6 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require_relative 'location'
22
+
21
23
  module Decode
22
24
  # A symbol with attached documentation.
23
25
  class Definition
@@ -168,5 +170,12 @@ module Decode
168
170
  @documentation ||= Documentation.new(@comments, @language)
169
171
  end
170
172
  end
173
+
174
+ # The location of the definition.
175
+ #
176
+ # @returns [Location | Nil] A {Location} instance if this definition has a location.
177
+ def location
178
+ nil
179
+ end
171
180
  end
172
181
  end
@@ -70,25 +70,25 @@ module Decode
70
70
  end
71
71
 
72
72
  # Parse the input yielding definitions.
73
- # @parameter input [File] The input file which contains the source code.
73
+ # @parameter source [Source] The input source file which contains the source code.
74
74
  # @yields {|definition| ...} Receives the definitions extracted from the source code.
75
75
  # @parameter definition [Definition] The source code definition including methods, classes, etc.
76
76
  # @returns [Enumerator(Segment)] If no block given.
77
- def definitions_for(input, &block)
77
+ def definitions_for(source, &block)
78
78
  if parser = self.parser
79
- parser.definitions_for(input, &block)
79
+ parser.definitions_for(source, &block)
80
80
  end
81
81
  end
82
82
 
83
83
  # Parse the input yielding segments.
84
84
  # Segments are constructed from a block of top level comments followed by a block of code.
85
- # @parameter input [File] The input file which contains the source code.
85
+ # @parameter source [Source] The input source file which contains the source code.
86
86
  # @yields {|segment| ...}
87
87
  # @parameter segment [Segment]
88
88
  # @returns [Enumerator(Segment)] If no block given.
89
- def segments_for(input, &block)
89
+ def segments_for(source, &block)
90
90
  if parser = self.parser
91
- parser.segments_for(input, &block)
91
+ parser.segments_for(source, &block)
92
92
  end
93
93
  end
94
94
  end
@@ -59,7 +59,13 @@ module Decode
59
59
  return lines.join
60
60
  end
61
61
  end
62
+
63
+ def location
64
+ expression = @node.location.expression
65
+
66
+ Location.new(expression.source_buffer.name, expression.line)
67
+ end
62
68
  end
63
69
  end
64
70
  end
65
- end
71
+ end
@@ -42,9 +42,19 @@ module Decode
42
42
  @language = language
43
43
  end
44
44
 
45
+ # Parse the given source object, can be a string or a Source instance.
46
+ # @parameter source [String | Source] The source to parse.
47
+ private def parse_source(source)
48
+ if source.is_a?(Source)
49
+ ::Parser::CurrentRuby.parse_with_comments(source.read, source.path)
50
+ else
51
+ ::Parser::CurrentRuby.parse_with_comments(source)
52
+ end
53
+ end
54
+
45
55
  # Extract definitions from the given input file.
46
- def definitions_for(input, &block)
47
- top, comments = ::Parser::CurrentRuby.parse_with_comments(input)
56
+ def definitions_for(source, &block)
57
+ top, comments = self.parse_source(source)
48
58
 
49
59
  if top
50
60
  walk_definitions(top, comments, &block)
@@ -253,8 +263,8 @@ module Decode
253
263
  end
254
264
 
255
265
  # Extract segments from the given input file.
256
- def segments_for(input, &block)
257
- top, comments = ::Parser::CurrentRuby.parse_with_comments(input)
266
+ def segments_for(source, &block)
267
+ top, comments = self.parse_source(source)
258
268
 
259
269
  # We delete any leading comments:
260
270
  line = 0
@@ -0,0 +1,27 @@
1
+ # Copyright, 2022, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Decode
22
+ class Location < Struct.new(:path, :line)
23
+ def to_s
24
+ "#{path}:#{line}"
25
+ end
26
+ end
27
+ end
data/lib/decode/source.rb CHANGED
@@ -50,7 +50,7 @@ module Decode
50
50
  def definitions(&block)
51
51
  return to_enum(:definitions) unless block_given?
52
52
 
53
- @language.definitions_for(self.read, &block)
53
+ @language.definitions_for(self, &block)
54
54
  end
55
55
 
56
56
  # Open the source file and read all segments.
@@ -60,7 +60,7 @@ module Decode
60
60
  def segments(&block)
61
61
  return to_enum(:segments) unless block_given?
62
62
 
63
- @language.segments_for(self.read, &block)
63
+ @language.segments_for(self, &block)
64
64
  end
65
65
 
66
66
  def code(index = nil, relative_to: nil)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Decode
22
- VERSION = "0.17.3"
22
+ VERSION = "0.18.0"
23
23
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.3
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -36,7 +36,7 @@ cert_chain:
36
36
  RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
37
37
  HiLJ8VOFx6w=
38
38
  -----END CERTIFICATE-----
39
- date: 2022-05-13 00:00:00.000000000 Z
39
+ date: 2022-06-28 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: parser
@@ -149,6 +149,7 @@ files:
149
149
  - lib/decode/language/ruby/reference.rb
150
150
  - lib/decode/language/ruby/segment.rb
151
151
  - lib/decode/languages.rb
152
+ - lib/decode/location.rb
152
153
  - lib/decode/scope.rb
153
154
  - lib/decode/segment.rb
154
155
  - lib/decode/source.rb
metadata.gz.sig CHANGED
Binary file