decode 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/decode/definition.rb +7 -0
- data/lib/decode/language/ruby/attribute.rb +37 -0
- data/lib/decode/language/ruby/class.rb +5 -1
- data/lib/decode/language/ruby/parser.rb +23 -1
- data/lib/decode/language/ruby.rb +4 -0
- data/lib/decode/trie.rb +3 -1
- data/lib/decode/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59ccb94aeeb9afb9e56f473a90991bfb2955ce6bdc2a681b1c8ecf7ee72974f9
|
4
|
+
data.tar.gz: d092f82acb7134df72dfbf2042617f656b94749c8f5b89ec7830e002ff781e8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df6fd92d34b379631cf7a0358e3d41c7470824daadd0ce9274def8b40cd5579ddb9d81eaed6cfdd8bf44a09b735525332a35b75fb0cb95068063d5e67431c52
|
7
|
+
data.tar.gz: fc5a74af220d01473013e7943d778017fd7f141086103fb350713e935893c2616495d1ce61a5b8421a940dfe44ca3b8eb3658dab0190ef3f4232fa2d9765892f
|
data/lib/decode/definition.rb
CHANGED
@@ -39,6 +39,13 @@ module Decode
|
|
39
39
|
# A long form of the definition, e.g. `def initialize(kind, name, comments, **options)`.
|
40
40
|
# @return [String | nil]
|
41
41
|
def long_form
|
42
|
+
self.short_form
|
43
|
+
end
|
44
|
+
|
45
|
+
# A long form which uses the qualified name if possible. Defaults to the {long_form}.
|
46
|
+
# @return [String | nil]
|
47
|
+
def qualified_form
|
48
|
+
self.long_form
|
42
49
|
end
|
43
50
|
|
44
51
|
# The full text of the definition.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright, 2020, 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
|
+
require_relative 'definition'
|
22
|
+
|
23
|
+
module Decode
|
24
|
+
module Language
|
25
|
+
module Ruby
|
26
|
+
class Attribute < Definition
|
27
|
+
def keyword
|
28
|
+
@node.children[1]
|
29
|
+
end
|
30
|
+
|
31
|
+
def short_form
|
32
|
+
"#{self.keyword} #{@name.inspect}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -35,12 +35,16 @@ module Decode
|
|
35
35
|
def long_form
|
36
36
|
if super_node = @node.children[1]
|
37
37
|
@node.location.keyword.join(
|
38
|
-
super_node.location.
|
38
|
+
super_node.location.expression
|
39
39
|
).source
|
40
40
|
else
|
41
41
|
self.short_form
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
def qualified_form
|
46
|
+
"class #{self.qualified_name}"
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
class Singleton < Definition
|
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'parser/current'
|
22
22
|
|
23
|
+
require_relative 'attribute'
|
23
24
|
require_relative 'class'
|
24
25
|
require_relative 'constant'
|
25
26
|
require_relative 'function'
|
@@ -40,7 +41,9 @@ module Decode
|
|
40
41
|
|
41
42
|
top, comments = @parser.parse_with_comments(buffer)
|
42
43
|
|
43
|
-
|
44
|
+
if top
|
45
|
+
walk(top, comments, &block)
|
46
|
+
end
|
44
47
|
end
|
45
48
|
|
46
49
|
def extract_comments_for(node, comments)
|
@@ -135,6 +138,25 @@ module Decode
|
|
135
138
|
)
|
136
139
|
|
137
140
|
yield definition
|
141
|
+
when :send
|
142
|
+
name = node.children[1]
|
143
|
+
case name
|
144
|
+
when :attr, :attr_reader, :attr_writer, :attr_accessor
|
145
|
+
definition = Attribute.new(
|
146
|
+
:def, name_for(node.children[2]),
|
147
|
+
extract_comments_for(node, comments), node,
|
148
|
+
parent: parent, language: Ruby
|
149
|
+
)
|
150
|
+
|
151
|
+
yield definition
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def name_for(node)
|
157
|
+
case node.type
|
158
|
+
when :sym
|
159
|
+
return node.children[0]
|
138
160
|
end
|
139
161
|
end
|
140
162
|
end
|
data/lib/decode/language/ruby.rb
CHANGED
data/lib/decode/trie.rb
CHANGED
data/lib/decode/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/decode/index.rb
|
128
128
|
- lib/decode/language.rb
|
129
129
|
- lib/decode/language/ruby.rb
|
130
|
+
- lib/decode/language/ruby/attribute.rb
|
130
131
|
- lib/decode/language/ruby/class.rb
|
131
132
|
- lib/decode/language/ruby/constant.rb
|
132
133
|
- lib/decode/language/ruby/definition.rb
|