decode 0.17.2 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/decode/definition.rb +15 -2
- data/lib/decode/index.rb +0 -1
- data/lib/decode/language/generic.rb +6 -6
- data/lib/decode/language/ruby/class.rb +46 -8
- data/lib/decode/language/ruby/definition.rb +7 -1
- data/lib/decode/language/ruby/module.rb +8 -3
- data/lib/decode/language/ruby/parser.rb +35 -14
- data/lib/decode/location.rb +27 -0
- data/lib/decode/source.rb +2 -2
- data/lib/decode/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6161432dca8cff543a44aa7077863081acc65e2c30ae5a71a6cee66c8c0ff1fa
|
4
|
+
data.tar.gz: 6881ade662a2414f923631ff5e34a90c4df6adf7501f9b973fad2a74fc231f74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3b92e010e0d756e1462702efaef891f148ac804f2aaf9c3df4cd9f5e8a2fc5957c68fe2a9013bef25643805ff30c9c4501c66d2580d43026f5a4fe025ee277
|
7
|
+
data.tar.gz: 4bfbb2545dba5f1921c5a222bbd7fddb895a7fe29418b5280573a26a82814dee387b3377bfe6738d493059735d7a7ae444a51e3b0a8f0106166aa706b9cc2697
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/decode/definition.rb
CHANGED
@@ -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,
|
102
|
+
@path = [*@parent.path, *path_name].freeze
|
101
103
|
else
|
102
104
|
# At top:
|
103
|
-
@path =
|
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
@@ -70,25 +70,25 @@ module Decode
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# Parse the input yielding definitions.
|
73
|
-
# @parameter
|
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(
|
77
|
+
def definitions_for(source, &block)
|
78
78
|
if parser = self.parser
|
79
|
-
parser.definitions_for(
|
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
|
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(
|
89
|
+
def segments_for(source, &block)
|
90
90
|
if parser = self.parser
|
91
|
-
parser.segments_for(
|
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 #{
|
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
|
47
|
-
|
48
|
-
super_node.location.expression
|
49
|
-
).source
|
46
|
+
if super_class = self.super_class
|
47
|
+
"#{qualified_form} < #{super_class}"
|
50
48
|
else
|
51
|
-
|
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,10 +61,18 @@ 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.
|
63
71
|
class Singleton < Definition
|
72
|
+
def nested_name
|
73
|
+
"::class"
|
74
|
+
end
|
75
|
+
|
64
76
|
# A singleton class is a container for other definitions.
|
65
77
|
# @returns [Boolean]
|
66
78
|
def container?
|
@@ -74,14 +86,40 @@ module Decode
|
|
74
86
|
end
|
75
87
|
|
76
88
|
# The short form of the class.
|
77
|
-
# e.g. `class <<
|
89
|
+
# e.g. `class << self`.
|
78
90
|
def short_form
|
79
91
|
"class << #{@name}"
|
80
92
|
end
|
81
93
|
|
82
94
|
# The long form is the same as the short form.
|
83
95
|
alias long_form short_form
|
96
|
+
|
97
|
+
def path_name
|
98
|
+
[:class]
|
99
|
+
end
|
100
|
+
|
101
|
+
# The lexical scope as an array of names.
|
102
|
+
# e.g. `[:Decode, :Definition]`
|
103
|
+
# @returns [Array]
|
104
|
+
def path
|
105
|
+
if @path
|
106
|
+
# Cached version:
|
107
|
+
@path
|
108
|
+
else
|
109
|
+
@path = [*self.absolute_path, *self.path_name]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def absolute_path
|
116
|
+
if @parent
|
117
|
+
@parent.path
|
118
|
+
else
|
119
|
+
@name.to_s.split('::').map(&:to_sym)
|
120
|
+
end
|
121
|
+
end
|
84
122
|
end
|
85
123
|
end
|
86
124
|
end
|
87
|
-
end
|
125
|
+
end
|
@@ -37,17 +37,22 @@ module Decode
|
|
37
37
|
# The short form of the module.
|
38
38
|
# e.g. `module Barnyard`.
|
39
39
|
def short_form
|
40
|
-
"module #{
|
40
|
+
"module #{path_name.last}"
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
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
|
@@ -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(
|
47
|
-
top, comments =
|
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)
|
@@ -109,16 +119,18 @@ module Decode
|
|
109
119
|
walk_definitions(children, comments, definition, &block)
|
110
120
|
end
|
111
121
|
when :sclass
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
+
if name = singleton_name_for(node.children[0])
|
123
|
+
definition = Singleton.new(
|
124
|
+
node, name,
|
125
|
+
comments: extract_comments_for(node, comments),
|
126
|
+
parent: parent, language: @language
|
127
|
+
)
|
128
|
+
|
129
|
+
yield definition
|
130
|
+
|
131
|
+
if children = node.children[1]
|
132
|
+
walk_definitions(children, comments, definition, &block)
|
133
|
+
end
|
122
134
|
end
|
123
135
|
when :def
|
124
136
|
definition = Method.new(
|
@@ -219,6 +231,15 @@ module Decode
|
|
219
231
|
end
|
220
232
|
end
|
221
233
|
|
234
|
+
def singleton_name_for(node)
|
235
|
+
case node.type
|
236
|
+
when :const
|
237
|
+
nested_name_for(node)
|
238
|
+
when :self
|
239
|
+
:'self'
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
222
243
|
KIND_ATTRIBUTE = /\A
|
223
244
|
(@(?<kind>attribute)\s+(?<value>.*?))|
|
224
245
|
(@define\s+(?<kind>)\s+(?<value>.*?))
|
@@ -253,8 +274,8 @@ module Decode
|
|
253
274
|
end
|
254
275
|
|
255
276
|
# Extract segments from the given input file.
|
256
|
-
def segments_for(
|
257
|
-
top, comments =
|
277
|
+
def segments_for(source, &block)
|
278
|
+
top, comments = self.parse_source(source)
|
258
279
|
|
259
280
|
# We delete any leading comments:
|
260
281
|
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
|
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
|
63
|
+
@language.segments_for(self, &block)
|
64
64
|
end
|
65
65
|
|
66
66
|
def code(index = nil, relative_to: nil)
|
data/lib/decode/version.rb
CHANGED
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.
|
4
|
+
version: 0.18.1
|
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:
|
39
|
+
date: 2022-07-08 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.
|
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
|