decode 0.17.3 → 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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/decode/definition.rb +9 -0
- data/lib/decode/language/generic.rb +6 -6
- data/lib/decode/language/ruby/definition.rb +7 -1
- data/lib/decode/language/ruby/parser.rb +14 -4
- 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: 07565b4d2600fe3cd6552192f8faae065fbd728e98f51008863326a1b4f7f743
|
4
|
+
data.tar.gz: a16e3cf053d0ac25c9e0f2e596832dabf44f027edf0ad509ed7eb20559d685e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1e7ccf9434ddd07c98ce94e64741f30af06698b9841935b99ecc0f7e5027aa76a8ce97778bade6cdaf25853f03d7ec8d2372715bd328ada2b844b4daf68c2a5
|
7
|
+
data.tar.gz: 69d195150f777b3484de296ef8d093e6531856bbc111d3d75e58d806478ecb84506223f5e5372656c06df28e8e1e326817f287dcc680c9055e7286b58fd9a2d2
|
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
|
@@ -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
|
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
|
@@ -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)
|
@@ -253,8 +263,8 @@ module Decode
|
|
253
263
|
end
|
254
264
|
|
255
265
|
# Extract segments from the given input file.
|
256
|
-
def segments_for(
|
257
|
-
top, comments =
|
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
|
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.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-
|
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
|