decode 0.13.0 → 0.14.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.
@@ -62,13 +62,13 @@ module Decode
62
62
  # A Ruby-specific singleton class.
63
63
  class Singleton < Definition
64
64
  # A singleton class is a container for other definitions.
65
- # @return [Boolean]
65
+ # @returns [Boolean]
66
66
  def container?
67
67
  true
68
68
  end
69
69
 
70
70
  # Typically, a singleton class does not contain other definitions.
71
- # @return [Boolean]
71
+ # @returns [Boolean]
72
72
  def nested?
73
73
  false
74
74
  end
@@ -44,7 +44,7 @@ module Decode
44
44
  end
45
45
 
46
46
  # The source code associated with the definition.
47
- # @return [String]
47
+ # @returns [String]
48
48
  def text
49
49
  expression = @node.location.expression
50
50
  lines = expression.source.lines
@@ -207,7 +207,7 @@ module Decode
207
207
  end
208
208
 
209
209
  KIND_ATTRIBUTE = /\A
210
- (@(?<kind>attr)\s+(?<value>.*?))|
210
+ (@(?<kind>attribute)\s+(?<value>.*?))|
211
211
  (@define\s+(?<kind>)\s+(?<value>.*?))
212
212
  \Z/x
213
213
 
@@ -279,6 +279,14 @@ module Decode
279
279
  end
280
280
 
281
281
  yield segment if segment
282
+ else
283
+ # One top level segment:
284
+ segment = Segment.new(
285
+ extract_comments_for(node, comments),
286
+ Ruby, node
287
+ )
288
+
289
+ yield segment
282
290
  end
283
291
  end
284
292
  end
@@ -40,7 +40,7 @@ module Decode
40
40
  end
41
41
 
42
42
  # The source code trailing the comments.
43
- # @return [String | nil]
43
+ # @returns [String | nil]
44
44
  def code
45
45
  @expression.source
46
46
  end
@@ -35,15 +35,15 @@ module Decode
35
35
  end
36
36
 
37
37
  # The preceeding comments.
38
- # @attr [Array(String)]
38
+ # @attribute [Array(String)]
39
39
  attr :comments
40
40
 
41
41
  # The language of the code attached to this segment.
42
- # @attr [Language]
42
+ # @attribute [Language]
43
43
  attr :language
44
44
 
45
45
  # An interface for accsssing the documentation of the definition.
46
- # @return [Documentation | nil] A `Documentation` if this definition has comments.
46
+ # @returns [Documentation | nil] A {Documentation} instance if this definition has comments.
47
47
  def documentation
48
48
  if @comments&.any?
49
49
  @documentation ||= Documentation.new(@comments, @language)
@@ -51,7 +51,7 @@ module Decode
51
51
  end
52
52
 
53
53
  # The source code trailing the comments.
54
- # @return [String | nil]
54
+ # @returns [String | nil]
55
55
  def code
56
56
  end
57
57
  end
data/lib/decode/trie.rb CHANGED
@@ -31,17 +31,17 @@ module Decode
31
31
  end
32
32
 
33
33
  # A mutable array of all values that terminate at this node.
34
- # @attr [Array]
34
+ # @attribute [Array]
35
35
  attr_accessor :values
36
36
 
37
37
  # A hash table of all children nodes, indexed by name.
38
- # @attr [Hash(String, Node)]
38
+ # @attribute [Hash(String, Node)]
39
39
  attr :children
40
40
 
41
41
  # Look up a lexical path starting at this node.
42
42
  #
43
- # @param path [Array(String)] The path to resolve.
44
- # @return [Node | Nil]
43
+ # @parameter path [Array(String)] The path to resolve.
44
+ # @returns [Node | Nil]
45
45
  def lookup(path, index = 0)
46
46
  if index < path.size
47
47
  if child = @children[path[index]]
@@ -55,9 +55,9 @@ module Decode
55
55
  # Traverse the trie from this node.
56
56
  # Invoke `descend.call` to traverse the children of the current node.
57
57
  #
58
- # @param path [Array(String)] The current lexical path.
58
+ # @parameter path [Array(String)] The current lexical path.
59
59
  #
60
- # @block `{|path, node, descend| descend.call}`
60
+ # @block {|path, node, descend| descend.call}
61
61
  # @yield path [Array(String)] The current lexical path.
62
62
  # @yield node [Node] The current node which is being traversed.
63
63
  # @yield descend [Proc] The recursive method for traversing children.
@@ -76,12 +76,12 @@ module Decode
76
76
  end
77
77
 
78
78
  # The root of the trie.
79
- # @attr [Node]
79
+ # @attribute [Node]
80
80
  attr :root
81
81
 
82
82
  # Insert the specified value at the given path into the trie.
83
- # @param path [Array(String)] The lexical path where the value will be inserted.
84
- # @param value [Object] The value to insert.
83
+ # @parameter path [Array(String)] The lexical path where the value will be inserted.
84
+ # @parameter value [Object] The value to insert.
85
85
  def insert(path, value)
86
86
  node = @root
87
87
 
@@ -94,15 +94,15 @@ module Decode
94
94
 
95
95
  # Lookup the values at the specified path.
96
96
  #
97
- # @param path [Array(String)] The lexical path which contains the values.
98
- # @return [Array(Object) | Nil] The values that existed (or not) at the specified path.
97
+ # @parameter path [Array(String)] The lexical path which contains the values.
98
+ # @returns [Array(Object) | Nil] The values that existed (or not) at the specified path.
99
99
  def lookup(path)
100
100
  @root.lookup(path)
101
101
  end
102
102
 
103
103
  # Enumerate all lexical scopes under the specified path.
104
104
  #
105
- # @block `{|path, values| ...}`
105
+ # @block {|path, values| ...}
106
106
  # @yield path [Array(String)] The lexical path.
107
107
  # @yield values [Array(Object)] The values that exist at the given path.
108
108
  def each(path = [], &block)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Decode
22
- VERSION = "0.13.0"
22
+ VERSION = "0.14.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.13.0
4
+ version: 0.14.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-08 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -115,15 +115,19 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".github/workflows/development.yml"
119
- - ".gitignore"
120
- - ".rspec"
121
- - README.md
122
118
  - bake/decode/index.rb
123
- - decode.gemspec
124
- - gems.rb
125
- - guides/extract-symbols/extract.rb
126
119
  - lib/decode.rb
120
+ - lib/decode/comment/attribute.rb
121
+ - lib/decode/comment/node.rb
122
+ - lib/decode/comment/parameter.rb
123
+ - lib/decode/comment/pragma.rb
124
+ - lib/decode/comment/raises.rb
125
+ - lib/decode/comment/returns.rb
126
+ - lib/decode/comment/tag.rb
127
+ - lib/decode/comment/tags.rb
128
+ - lib/decode/comment/text.rb
129
+ - lib/decode/comment/throws.rb
130
+ - lib/decode/comment/yields.rb
127
131
  - lib/decode/definition.rb
128
132
  - lib/decode/documentation.rb
129
133
  - lib/decode/index.rb
@@ -159,9 +163,9 @@ require_paths:
159
163
  - lib
160
164
  required_ruby_version: !ruby/object:Gem::Requirement
161
165
  requirements:
162
- - - ">="
166
+ - - "~>"
163
167
  - !ruby/object:Gem::Version
164
- version: 2.3.0
168
+ version: '2.5'
165
169
  required_rubygems_version: !ruby/object:Gem::Requirement
166
170
  requirements:
167
171
  - - ">="
@@ -1,50 +0,0 @@
1
- name: Development
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- runs-on: ${{matrix.os}}-latest
8
- continue-on-error: ${{matrix.experimental}}
9
-
10
- strategy:
11
- matrix:
12
- os:
13
- - ubuntu
14
-
15
- ruby:
16
- - 2.5
17
- - 2.6
18
- - 2.7
19
-
20
- experimental: [false]
21
- env: [""]
22
-
23
- include:
24
- - os: ubuntu
25
- ruby: truffleruby
26
- experimental: true
27
- - os: ubuntu
28
- ruby: jruby
29
- experimental: true
30
- - os: ubuntu
31
- ruby: head
32
- experimental: true
33
- - os: ubuntu
34
- ruby: 2.6
35
- experimental: false
36
- env: COVERAGE=PartialSummary,Coveralls
37
-
38
- steps:
39
- - uses: actions/checkout@v1
40
- - uses: ruby/setup-ruby@v1
41
- with:
42
- ruby-version: ${{matrix.ruby}}
43
-
44
- - name: Install dependencies
45
- run: ${{matrix.env}} bundle install
46
-
47
- - name: Run tests
48
- timeout-minutes: 5
49
- run: |
50
- ${{matrix.env}} bundle exec rspec
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- /gems.locked
11
-
12
- # rspec failure tracking
13
- .rspec_status
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --require spec_helper
data/README.md DELETED
@@ -1,47 +0,0 @@
1
- # Decode
2
-
3
- A Ruby code analysis tool and documentation generator.
4
-
5
- [![Development](https://github.com/ioquatix/decode/workflows/Development/badge.svg)](https://github.com/ioquatix/decode/actions?workflow=Development)
6
-
7
- ## Motivation
8
-
9
- As part of my effort to build [better project documentation](https://github.com/socketry/utopia-project), I needed a better code analysis tool. While less featured than some of the more mature alternatives, this library focuses on the needs of documentation generation, including speed, cross-referencing and (eventually) multi-language support.
10
-
11
- ## Usage
12
-
13
- Please see the <a href="https://ioquatix.github.io/decode/">project documentation</a> or run it locally using `bake utopia:project:serve`.
14
-
15
- ## Contributing
16
-
17
- We welcome contributions to this project.
18
-
19
- 1. Fork it
20
- 2. Create your feature branch (`git checkout -b my-new-feature`)
21
- 3. Commit your changes (`git commit -am 'Add some feature'`)
22
- 4. Push to the branch (`git push origin my-new-feature`)
23
- 5. Create new Pull Request
24
-
25
- ## License
26
-
27
- Released under the MIT license.
28
-
29
- Copyright, 2020, by [Samuel G. D. Williams](http://www.codeotaku.com).
30
-
31
- Permission is hereby granted, free of charge, to any person obtaining a copy
32
- of this software and associated documentation files (the "Software"), to deal
33
- in the Software without restriction, including without limitation the rights
34
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
- copies of the Software, and to permit persons to whom the Software is
36
- furnished to do so, subject to the following conditions:
37
-
38
- The above copyright notice and this permission notice shall be included in
39
- all copies or substantial portions of the Software.
40
-
41
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
47
- THE SOFTWARE.
data/decode.gemspec DELETED
@@ -1,33 +0,0 @@
1
-
2
- require_relative 'lib/decode/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "decode"
6
- spec.version = Decode::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
-
10
- spec.summary = "Code analysis for documentation generation."
11
- spec.homepage = "https://github.com/ioquatix/decode"
12
- spec.license = "MIT"
13
-
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
-
16
- # Specify which files should be added to the gem when it is released.
17
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(docs|test|spec|features)/}) }
20
- end
21
-
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
24
-
25
- spec.add_dependency "parser"
26
-
27
- spec.add_development_dependency 'build-files'
28
- spec.add_development_dependency 'bake-bundler'
29
- spec.add_development_dependency 'utopia-project'
30
- spec.add_development_dependency 'covered'
31
- spec.add_development_dependency 'bundler'
32
- spec.add_development_dependency 'rspec'
33
- end
data/gems.rb DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This example demonstrates how to extract symbols using the index. An instance of {Decode::Index} is used for loading symbols from source code files. These symbols are available as a flat list and as a trie structure. You can look up specific symbols using a reference using {Decode::Index:lookup}.
4
- require_relative '../../lib/decode/index'
5
-
6
- # Firstly, construct the index:
7
- index = Decode::Index.new
8
-
9
- # Then, update the index by loading paths from the file system:
10
- paths = Dir.glob(File.expand_path("../../lib/**/*.rb", __dir__))
11
- index.update(paths)
12
-
13
- # Finally, you can print out the loaded symbols:
14
- index.symbols.each do |name, symbol|
15
- puts symbol.long_form
16
- end
17
-
18
- # Lookup a specific symbol:
19
- absolute_reference = Decode::Language::Ruby.reference("Decode::Index:lookup")
20
- lookup_symbol = index.lookup(absolute_reference).first
21
- puts lookup_symbol.long_form
22
-
23
- # Lookup a method relative to that symbol:
24
- relative_reference = Decode::Language::Ruby.reference("trie")
25
- trie_attribute = index.lookup(relative_reference, relative_to: lookup_symbol).first
26
- puts trie_attribute.long_form