decode 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e93383d44bf331fbbe47bf804d1f59331de0437d9adbe725ba9a9182510842ef
4
- data.tar.gz: 48e8dc949ea4ea603da59bfde63e42040b6fe3df448064fd0107fa2d8fd2d99a
3
+ metadata.gz: 07565b4d2600fe3cd6552192f8faae065fbd728e98f51008863326a1b4f7f743
4
+ data.tar.gz: a16e3cf053d0ac25c9e0f2e596832dabf44f027edf0ad509ed7eb20559d685e5
5
5
  SHA512:
6
- metadata.gz: 9b74c5d5c31cc1f8b0bc0dbc3a9e00ab2d8862763d009acfbb7734ae330138d264ddd06cb6ae2efa23ce907d1f7af330ef5e43475e828bdfaca32c9cc87c87a7
7
- data.tar.gz: 3d1c155aa5cb886fe536d6e15ab04e3a955b59be026b223a8ae064ae175e635293f3dc12dd292eb0a15622f371d0c4687e3ef62534bba34fa8e092f616ae4b35
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
@@ -97,13 +99,17 @@ module Decode
97
99
  @path
98
100
  elsif @parent
99
101
  # Merge with parent:
100
- @path = [*@parent.path, @name].freeze
102
+ @path = [*@parent.path, *path_name].freeze
101
103
  else
102
104
  # At top:
103
- @path = [@name].freeze
105
+ @path = path_name.freeze
104
106
  end
105
107
  end
106
108
 
109
+ def path_name
110
+ [@name]
111
+ end
112
+
107
113
  alias lexical_path path
108
114
 
109
115
  # A short form of the definition.
@@ -164,5 +170,12 @@ module Decode
164
170
  @documentation ||= Documentation.new(@comments, @language)
165
171
  end
166
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
167
180
  end
168
181
  end
data/lib/decode/index.rb CHANGED
@@ -51,7 +51,6 @@ module Decode
51
51
 
52
52
  # A (prefix) trie of lexically scoped definitions.
53
53
  # @attribute [Trie]
54
-
55
54
  attr :trie
56
55
 
57
56
  # Updates the index by parsing the specified files.
@@ -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
@@ -37,18 +37,22 @@ module Decode
37
37
  # The short form of the class.
38
38
  # e.g. `class Animal`.
39
39
  def short_form
40
- "class #{@name}"
40
+ "class #{path_name.last}"
41
41
  end
42
42
 
43
43
  # The long form of the class.
44
44
  # e.g. `class Dog < Animal`.
45
45
  def long_form
46
- if super_node = @node.children[1]
47
- @node.location.keyword.join(
48
- super_node.location.expression
49
- ).source
46
+ if super_class = self.super_class
47
+ "#{qualified_form} < #{super_class}"
50
48
  else
51
- self.short_form
49
+ qualified_form
50
+ end
51
+ end
52
+
53
+ def super_class
54
+ if super_node = @node.children[1]
55
+ super_node.location.expression.source
52
56
  end
53
57
  end
54
58
 
@@ -57,6 +61,10 @@ module Decode
57
61
  def qualified_form
58
62
  "class #{self.qualified_name}"
59
63
  end
64
+
65
+ def path_name
66
+ @name.to_s.split('::').map(&:to_sym)
67
+ end
60
68
  end
61
69
 
62
70
  # A Ruby-specific singleton class.
@@ -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
@@ -37,18 +37,23 @@ module Decode
37
37
  # The short form of the module.
38
38
  # e.g. `module Barnyard`.
39
39
  def short_form
40
- "module #{@name}"
40
+ "module #{path_name.last}"
41
41
  end
42
42
 
43
- # The long form is the same as the short form.
44
- alias long_form short_form
43
+ def long_form
44
+ qualified_form
45
+ end
45
46
 
46
47
  # The fully qualified name of the class.
47
48
  # e.g. `module ::Barnyard::Dog`.
48
49
  def qualified_form
49
50
  "module #{self.qualified_name}"
50
51
  end
52
+
53
+ def path_name
54
+ @name.to_s.split('::').map(&:to_sym)
55
+ end
51
56
  end
52
57
  end
53
58
  end
54
- end
59
+ 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)
@@ -85,7 +95,7 @@ module Decode
85
95
  end
86
96
  when :module
87
97
  definition = Module.new(
88
- node, node.children[0].children[1],
98
+ node, nested_name_for(node.children[0]),
89
99
  comments: extract_comments_for(node, comments),
90
100
  parent: parent,
91
101
  language: @language
@@ -98,7 +108,7 @@ module Decode
98
108
  end
99
109
  when :class
100
110
  definition = Class.new(
101
- node, class_name_for(node.children[0]),
111
+ node, nested_name_for(node.children[0]),
102
112
  comments: extract_comments_for(node, comments),
103
113
  parent: parent, language: @language
104
114
  )
@@ -211,9 +221,9 @@ module Decode
211
221
  end
212
222
  end
213
223
 
214
- def class_name_for(node)
224
+ def nested_name_for(node)
215
225
  if prefix = node.children[0]
216
- "#{class_name_for(prefix)}::#{node.children[1]}"
226
+ "#{nested_name_for(prefix)}::#{node.children[1]}".to_sym
217
227
  else
218
228
  node.children[1]
219
229
  end
@@ -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.1"
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.1
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: 2021-10-08 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
@@ -177,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubygems_version: 3.1.6
181
+ rubygems_version: 3.3.7
181
182
  signing_key:
182
183
  specification_version: 4
183
184
  summary: Code analysis for documentation generation.
metadata.gz.sig CHANGED
Binary file