decode 0.13.0 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/bake/decode/index.rb +1 -1
  3. data/lib/decode/comment/attribute.rb +53 -0
  4. data/lib/decode/comment/node.rb +90 -0
  5. data/lib/decode/comment/parameter.rb +58 -0
  6. data/lib/decode/comment/pragma.rb +50 -0
  7. data/lib/decode/comment/raises.rb +32 -0
  8. data/lib/decode/comment/returns.rb +32 -0
  9. data/lib/decode/comment/tag.rb +50 -0
  10. data/lib/decode/comment/tags.rb +80 -0
  11. data/lib/decode/comment/text.rb +37 -0
  12. data/lib/decode/comment/throws.rb +32 -0
  13. data/lib/decode/comment/yields.rb +52 -0
  14. data/lib/decode/definition.rb +26 -19
  15. data/lib/decode/documentation.rb +21 -66
  16. data/lib/decode/index.rb +7 -7
  17. data/lib/decode/language/generic.rb +2 -2
  18. data/lib/decode/language/reference.rb +39 -9
  19. data/lib/decode/language/ruby.rb +40 -6
  20. data/lib/decode/language/ruby/block.rb +1 -1
  21. data/lib/decode/language/ruby/class.rb +2 -2
  22. data/lib/decode/language/ruby/code.rb +85 -0
  23. data/lib/decode/language/ruby/definition.rb +1 -1
  24. data/lib/decode/language/ruby/method.rb +7 -1
  25. data/lib/decode/language/ruby/module.rb +6 -0
  26. data/lib/decode/language/ruby/parser.rb +11 -3
  27. data/lib/decode/language/ruby/reference.rb +31 -0
  28. data/lib/decode/language/ruby/segment.rb +1 -1
  29. data/lib/decode/scope.rb +3 -0
  30. data/lib/decode/segment.rb +4 -4
  31. data/lib/decode/source.rb +24 -8
  32. data/lib/decode/syntax/link.rb +44 -0
  33. data/lib/decode/syntax/match.rb +53 -0
  34. data/lib/decode/syntax/rewriter.rb +70 -0
  35. data/lib/decode/trie.rb +13 -13
  36. data/lib/decode/version.rb +1 -1
  37. metadata +23 -43
  38. data/.github/workflows/development.yml +0 -50
  39. data/.gitignore +0 -13
  40. data/.rspec +0 -2
  41. data/README.md +0 -47
  42. data/decode.gemspec +0 -33
  43. data/gems.rb +0 -3
  44. data/guides/extract-symbols/extract.rb +0 -26
@@ -0,0 +1,53 @@
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
+ module Decode
22
+ module Syntax
23
+ class Match
24
+ def initialize(range)
25
+ @range = range
26
+ end
27
+
28
+ attr :range
29
+
30
+ def apply(source)
31
+ return source[range]
32
+ end
33
+
34
+ def <=> other
35
+ @range.min <=> other.range.min
36
+ end
37
+
38
+ def offset
39
+ @range.min
40
+ end
41
+
42
+ def size
43
+ @range.size
44
+ end
45
+
46
+ def apply(output, rewriter)
47
+ output << rewriter.text_for(@range)
48
+
49
+ return self.size
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,70 @@
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
+ module Decode
22
+ module Syntax
23
+ class Rewriter
24
+ def initialize(text)
25
+ @text = text
26
+ @matches = []
27
+ end
28
+
29
+ attr :text
30
+
31
+ attr :matches
32
+
33
+ def << match
34
+ @matches << match
35
+ end
36
+
37
+ # Returns a chunk of raw text with no formatting.
38
+ def text_for(range)
39
+ @text[range]
40
+ end
41
+
42
+ def apply(output = [])
43
+ offset = 0
44
+
45
+ @matches.sort.each do |match|
46
+ if match.offset > offset
47
+ output << text_for(offset...match.offset)
48
+
49
+ offset = match.offset
50
+ elsif match.offset < offset
51
+ # Match intersects last output buffer.
52
+ next
53
+ end
54
+
55
+ offset += match.apply(output, self)
56
+ end
57
+
58
+ if offset < @text.size
59
+ output << text_for(offset...@text.size)
60
+ end
61
+
62
+ return output
63
+ end
64
+
65
+ def link_to(definition, text)
66
+ "[#{text}]"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -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)
@@ -116,7 +116,7 @@ module Decode
116
116
  end
117
117
 
118
118
  # Traverse the trie.
119
- # See {Node:traverse} for details.
119
+ # See {Node#traverse} for details.
120
120
  def traverse(path = [], &block)
121
121
  if node = @root.lookup(path)
122
122
  node.traverse(&block)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Decode
22
- VERSION = "0.13.0"
22
+ VERSION = "0.15.2"
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.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bake-bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: utopia-project
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: covered
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,22 +80,26 @@ dependencies:
108
80
  - - ">="
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
- description:
83
+ description:
112
84
  email:
113
85
  - samuel.williams@oriontransfer.co.nz
114
86
  executables: []
115
87
  extensions: []
116
88
  extra_rdoc_files: []
117
89
  files:
118
- - ".github/workflows/development.yml"
119
- - ".gitignore"
120
- - ".rspec"
121
- - README.md
122
90
  - bake/decode/index.rb
123
- - decode.gemspec
124
- - gems.rb
125
- - guides/extract-symbols/extract.rb
126
91
  - lib/decode.rb
92
+ - lib/decode/comment/attribute.rb
93
+ - lib/decode/comment/node.rb
94
+ - lib/decode/comment/parameter.rb
95
+ - lib/decode/comment/pragma.rb
96
+ - lib/decode/comment/raises.rb
97
+ - lib/decode/comment/returns.rb
98
+ - lib/decode/comment/tag.rb
99
+ - lib/decode/comment/tags.rb
100
+ - lib/decode/comment/text.rb
101
+ - lib/decode/comment/throws.rb
102
+ - lib/decode/comment/yields.rb
127
103
  - lib/decode/definition.rb
128
104
  - lib/decode/documentation.rb
129
105
  - lib/decode/index.rb
@@ -135,6 +111,7 @@ files:
135
111
  - lib/decode/language/ruby/block.rb
136
112
  - lib/decode/language/ruby/call.rb
137
113
  - lib/decode/language/ruby/class.rb
114
+ - lib/decode/language/ruby/code.rb
138
115
  - lib/decode/language/ruby/constant.rb
139
116
  - lib/decode/language/ruby/definition.rb
140
117
  - lib/decode/language/ruby/function.rb
@@ -147,21 +124,24 @@ files:
147
124
  - lib/decode/scope.rb
148
125
  - lib/decode/segment.rb
149
126
  - lib/decode/source.rb
127
+ - lib/decode/syntax/link.rb
128
+ - lib/decode/syntax/match.rb
129
+ - lib/decode/syntax/rewriter.rb
150
130
  - lib/decode/trie.rb
151
131
  - lib/decode/version.rb
152
132
  homepage: https://github.com/ioquatix/decode
153
133
  licenses:
154
134
  - MIT
155
135
  metadata: {}
156
- post_install_message:
136
+ post_install_message:
157
137
  rdoc_options: []
158
138
  require_paths:
159
139
  - lib
160
140
  required_ruby_version: !ruby/object:Gem::Requirement
161
141
  requirements:
162
- - - ">="
142
+ - - "~>"
163
143
  - !ruby/object:Gem::Version
164
- version: 2.3.0
144
+ version: '2.5'
165
145
  required_rubygems_version: !ruby/object:Gem::Requirement
166
146
  requirements:
167
147
  - - ">="
@@ -169,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
149
  version: '0'
170
150
  requirements: []
171
151
  rubygems_version: 3.1.2
172
- signing_key:
152
+ signing_key:
173
153
  specification_version: 4
174
154
  summary: Code analysis for documentation generation.
175
155
  test_files: []
@@ -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.