decode 0.17.3 → 0.18.2
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/decode/definition.rb +12 -1
- data/lib/decode/language/generic.rb +6 -6
- data/lib/decode/language/ruby/class.rb +32 -2
- data/lib/decode/language/ruby/definition.rb +7 -1
- 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 +3 -2
- 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: 73f08a729f4aab1c447325886ac2f07a76c3e0b12a4ac9fadd0da81343fb24fe
|
4
|
+
data.tar.gz: 0fa743ec70c64044f12d56b1660fd8e2d2dfb5f6aeeb7ee49fbbe8325eca724d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65c43bcc6ead3b9ab8b67a5a203910520e81837a8654dedb86f3fd92010803e9762fc200b14cb724d4862871fc8d4f87ee39d2aee2eaa5abbe23b34b2a1cea19
|
7
|
+
data.tar.gz: 8aa62d064fd628fd5a8fa16dfcd6464072e7d7b271be4c81f66b504905b725aec59892ffcbf8d30835328ce7f42903a44f2ffbd437f80bdc7c6bb89cbd19952e
|
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
|
@@ -38,10 +40,12 @@ module Decode
|
|
38
40
|
@qualified_name = nil
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
43
|
+
def inspect
|
42
44
|
"\#<#{self.class} #{qualified_name}>"
|
43
45
|
end
|
44
46
|
|
47
|
+
alias to_s inspect
|
48
|
+
|
45
49
|
# The symbol name.
|
46
50
|
# e.g. `:Decode`.
|
47
51
|
# @attribute [Symbol]
|
@@ -168,5 +172,12 @@ module Decode
|
|
168
172
|
@documentation ||= Documentation.new(@comments, @language)
|
169
173
|
end
|
170
174
|
end
|
175
|
+
|
176
|
+
# The location of the definition.
|
177
|
+
#
|
178
|
+
# @returns [Location | Nil] A {Location} instance if this definition has a location.
|
179
|
+
def location
|
180
|
+
nil
|
181
|
+
end
|
171
182
|
end
|
172
183
|
end
|
@@ -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
|
@@ -69,6 +69,10 @@ module Decode
|
|
69
69
|
|
70
70
|
# A Ruby-specific singleton class.
|
71
71
|
class Singleton < Definition
|
72
|
+
def nested_name
|
73
|
+
"::class"
|
74
|
+
end
|
75
|
+
|
72
76
|
# A singleton class is a container for other definitions.
|
73
77
|
# @returns [Boolean]
|
74
78
|
def container?
|
@@ -82,14 +86,40 @@ module Decode
|
|
82
86
|
end
|
83
87
|
|
84
88
|
# The short form of the class.
|
85
|
-
# e.g. `class <<
|
89
|
+
# e.g. `class << self`.
|
86
90
|
def short_form
|
87
91
|
"class << #{@name}"
|
88
92
|
end
|
89
93
|
|
90
94
|
# The long form is the same as the short form.
|
91
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
|
92
122
|
end
|
93
123
|
end
|
94
124
|
end
|
95
|
-
end
|
125
|
+
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.2
|
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-
|
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
|
metadata.gz.sig
CHANGED
Binary file
|