decode 0.5.0 → 0.6.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: c0f1e26c4b0aad982ae69ec4240f058d101c92f15b125f12e17b0a59e7f1a8f2
4
- data.tar.gz: 552744c2f9ab8477a01eafd7042f5332325a779d94a29d8a4ec03df387a9174b
3
+ metadata.gz: 59ccb94aeeb9afb9e56f473a90991bfb2955ce6bdc2a681b1c8ecf7ee72974f9
4
+ data.tar.gz: d092f82acb7134df72dfbf2042617f656b94749c8f5b89ec7830e002ff781e8e
5
5
  SHA512:
6
- metadata.gz: fe2a85001a162ca96082bd05788d7b57bae41af6aed065c72db26ef2c1d10d0b7c7e76836cf236a640bb7fdba84c66977e387e0fab449536c6915e3ec2413262
7
- data.tar.gz: a55480e4354fd41c4bb6e5197180289ab1b29671f65988b67935f001016fd731d083adfbd9edcd079fb2a50894ed2a5ba0b728722c54f66f378609009e20033a
6
+ metadata.gz: 4df6fd92d34b379631cf7a0358e3d41c7470824daadd0ce9274def8b40cd5579ddb9d81eaed6cfdd8bf44a09b735525332a35b75fb0cb95068063d5e67431c52
7
+ data.tar.gz: fc5a74af220d01473013e7943d778017fd7f141086103fb350713e935893c2616495d1ce61a5b8421a940dfe44ca3b8eb3658dab0190ef3f4232fa2d9765892f
@@ -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.name
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
- walk(top, comments, &block)
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
@@ -52,6 +52,10 @@ module Decode
52
52
 
53
53
  return buffer
54
54
  end
55
+
56
+ def self.reference(value)
57
+ Reference.new(value)
58
+ end
55
59
  end
56
60
  end
57
61
  end
data/lib/decode/trie.rb CHANGED
@@ -42,7 +42,9 @@ module Decode
42
42
  end
43
43
 
44
44
  def traverse(path = [], &block)
45
- if yield(path, self)
45
+ catch(:skip) do
46
+ yield(path, self)
47
+
46
48
  @children.each do |name, node|
47
49
  node.traverse([*path, name], &block)
48
50
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Decode
22
- VERSION = "0.5.0"
22
+ VERSION = "0.6.0"
23
23
  end
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.5.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-01 00:00:00.000000000 Z
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