decode 0.14.0 → 0.15.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/decode/comment/attribute.rb +0 -8
- data/lib/decode/comment/node.rb +4 -4
- data/lib/decode/comment/parameter.rb +0 -4
- data/lib/decode/definition.rb +8 -2
- data/lib/decode/documentation.rb +1 -1
- data/lib/decode/language/reference.rb +28 -6
- data/lib/decode/language/ruby.rb +5 -0
- data/lib/decode/language/ruby/block.rb +1 -1
- data/lib/decode/language/ruby/code.rb +85 -0
- data/lib/decode/language/ruby/definition.rb +4 -4
- data/lib/decode/language/ruby/method.rb +7 -1
- data/lib/decode/language/ruby/module.rb +6 -0
- data/lib/decode/language/ruby/parser.rb +2 -2
- data/lib/decode/language/ruby/reference.rb +31 -0
- data/lib/decode/scope.rb +3 -0
- data/lib/decode/segment.rb +1 -1
- data/lib/decode/source.rb +24 -8
- data/lib/decode/syntax/link.rb +44 -0
- data/lib/decode/syntax/match.rb +53 -0
- data/lib/decode/syntax/rewriter.rb +70 -0
- data/lib/decode/trie.rb +1 -1
- data/lib/decode/version.rb +1 -1
- metadata +10 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fef5bd0d089112f4e4897666683a8ecebb9306a9c4a1d454aa2cfef8a30daecf
|
4
|
+
data.tar.gz: cddb38a43954d3bd8ee2587ee66a2a7bd9ab207b33553dcc871b1d032fcde01e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ffceab58980663e235b35dcf68575e4a6857a483b796fe9a6df8248d52df5c52810711f7a4d9ba249113c6bb5facfc36af5efab22482b8ab1dc52956503c18e
|
7
|
+
data.tar.gz: daf76f009f6bc36d3f7515f182fc8daf5aceec3fc74758cd11fcb67c3f5f0780cbd55cffc0b3786dbe058f95c1a3085a7442d7a09833797a1c625add875def1a
|
data/lib/decode/comment/node.rb
CHANGED
@@ -63,11 +63,11 @@ module Decode
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# Traverse the tags from this node using {each}.
|
66
|
-
# Invoke `descend.call` to traverse the
|
66
|
+
# Invoke `descend.call(child)` to recursively traverse the specified child.
|
67
67
|
#
|
68
|
-
# @
|
69
|
-
#
|
70
|
-
#
|
68
|
+
# @yields {|node, descend| descend.call}
|
69
|
+
# @parameter node [Node] The current node which is being traversed.
|
70
|
+
# @parameter descend [Proc | Nil] The recursive method for traversing children.
|
71
71
|
def traverse(&block)
|
72
72
|
descend = ->(node){
|
73
73
|
node.traverse(&block)
|
data/lib/decode/definition.rb
CHANGED
@@ -44,12 +44,15 @@ module Decode
|
|
44
44
|
|
45
45
|
# The symbol name.
|
46
46
|
# e.g. `:Decode`.
|
47
|
+
# @attribute [Symbol]
|
47
48
|
attr :name
|
48
49
|
|
49
|
-
# The parent
|
50
|
+
# The parent definition, defining lexical scope.
|
51
|
+
# @attribute [Definition | Nil]
|
50
52
|
attr :parent
|
51
53
|
|
52
54
|
# The language the symbol is defined within.
|
55
|
+
# @attribute [Language::Generic]
|
53
56
|
attr :language
|
54
57
|
|
55
58
|
# The comment lines which directly preceeded the definition.
|
@@ -74,6 +77,8 @@ module Decode
|
|
74
77
|
"::#{@name}"
|
75
78
|
end
|
76
79
|
|
80
|
+
# Does the definition name match the specified prefix?
|
81
|
+
# @returns [Boolean]
|
77
82
|
def start_with?(prefix)
|
78
83
|
self.nested_name.start_with?(prefix)
|
79
84
|
end
|
@@ -83,7 +88,8 @@ module Decode
|
|
83
88
|
raise ArgumentError, "Unable to convert #{self} into #{kind}!"
|
84
89
|
end
|
85
90
|
|
86
|
-
# The lexical scope
|
91
|
+
# The lexical scope as an array of names.
|
92
|
+
# e.g. `[:Decode, :Definition]`
|
87
93
|
# @returns [Array]
|
88
94
|
def path
|
89
95
|
if @path
|
data/lib/decode/documentation.rb
CHANGED
@@ -24,11 +24,11 @@ module Decode
|
|
24
24
|
class Reference
|
25
25
|
# Initialize the reference.
|
26
26
|
# @parameter identifier [String] The identifier part of the reference.
|
27
|
-
def initialize(identifier, language)
|
27
|
+
def initialize(identifier, language, lexical_path = nil)
|
28
28
|
@identifier = identifier
|
29
29
|
@language = language
|
30
30
|
|
31
|
-
@lexical_path =
|
31
|
+
@lexical_path = lexical_path
|
32
32
|
@path = nil
|
33
33
|
end
|
34
34
|
|
@@ -45,6 +45,7 @@ module Decode
|
|
45
45
|
attr :identifier
|
46
46
|
|
47
47
|
# The language associated with this reference.
|
48
|
+
# @attribute [Language::Generic]
|
48
49
|
attr :language
|
49
50
|
|
50
51
|
# Whether the reference starts at the base of the lexical tree.
|
@@ -66,14 +67,35 @@ module Decode
|
|
66
67
|
@lexical_path ||= self.split(@identifier)
|
67
68
|
end
|
68
69
|
|
70
|
+
def priority(definition, prefix)
|
71
|
+
if prefix.nil?
|
72
|
+
return 1
|
73
|
+
elsif definition.start_with?(prefix)
|
74
|
+
return 0
|
75
|
+
else
|
76
|
+
return 2
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
69
80
|
def best(definitions)
|
70
81
|
prefix, name = lexical_path.last
|
71
82
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
83
|
+
first = nil
|
84
|
+
without_prefix = nil
|
85
|
+
|
86
|
+
definitions.each do |definition|
|
87
|
+
first ||= definition
|
88
|
+
|
89
|
+
next unless definition.language == @language
|
90
|
+
|
91
|
+
if prefix.nil?
|
92
|
+
without_prefix ||= definition
|
93
|
+
elsif definition.start_with?(prefix)
|
94
|
+
return definition
|
95
|
+
end
|
76
96
|
end
|
97
|
+
|
98
|
+
return without_prefix || first
|
77
99
|
end
|
78
100
|
|
79
101
|
# The lexical path of the reference.
|
data/lib/decode/language/ruby.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require_relative 'ruby/reference'
|
22
22
|
require_relative 'ruby/parser'
|
23
|
+
require_relative 'ruby/code'
|
23
24
|
|
24
25
|
require_relative '../comment/tags'
|
25
26
|
require_relative '../comment/parameter'
|
@@ -86,6 +87,10 @@ module Decode
|
|
86
87
|
def self.segments_for(input, &block)
|
87
88
|
Parser.new.segments_for(input, &block)
|
88
89
|
end
|
90
|
+
|
91
|
+
def self.code_for(text, index, relative_to: nil)
|
92
|
+
Code.new(text, index, relative_to: relative_to, language: self)
|
93
|
+
end
|
89
94
|
end
|
90
95
|
end
|
91
96
|
end
|
@@ -0,0 +1,85 @@
|
|
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
|
+
require_relative '../../syntax/link'
|
23
|
+
|
24
|
+
require 'parser/current'
|
25
|
+
|
26
|
+
module Decode
|
27
|
+
module Language
|
28
|
+
module Ruby
|
29
|
+
# A Ruby-specific block of code.
|
30
|
+
class Code
|
31
|
+
def initialize(text, index, relative_to: nil, language: relative_to&.language)
|
32
|
+
@text = text
|
33
|
+
@root = ::Parser::CurrentRuby.parse(text)
|
34
|
+
@index = index
|
35
|
+
@relative_to = relative_to
|
36
|
+
@language = language
|
37
|
+
end
|
38
|
+
|
39
|
+
attr :text
|
40
|
+
|
41
|
+
attr :language
|
42
|
+
|
43
|
+
def extract(into = [])
|
44
|
+
if @index
|
45
|
+
traverse(@root, into)
|
46
|
+
end
|
47
|
+
|
48
|
+
return into
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def traverse(node, into)
|
54
|
+
case node&.type
|
55
|
+
when :send
|
56
|
+
if reference = Reference.from_const(node, @language)
|
57
|
+
if definition = @index.lookup(reference, relative_to: @relative_to)
|
58
|
+
expression = node.location.selector
|
59
|
+
range = expression.begin_pos...expression.end_pos
|
60
|
+
into << Syntax::Link.new(range, definition)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Extract constants from arguments:
|
65
|
+
children = node.children[2..-1].each do |node|
|
66
|
+
traverse(node, into)
|
67
|
+
end
|
68
|
+
when :const
|
69
|
+
if reference = Reference.from_const(node, @language)
|
70
|
+
if definition = @index.lookup(reference, relative_to: @relative_to)
|
71
|
+
expression = node.location.name
|
72
|
+
range = expression.begin_pos...expression.end_pos
|
73
|
+
into << Syntax::Link.new(range, definition)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
when :begin
|
77
|
+
node.children.each do |child|
|
78
|
+
traverse(child, into)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -51,10 +51,10 @@ module Decode
|
|
51
51
|
if lines.count == 1
|
52
52
|
return lines.first
|
53
53
|
else
|
54
|
-
indentation = expression.source_line[/\A\s+/]
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
if indentation = expression.source_line[/\A\s+/]
|
55
|
+
# Remove all the indentation:
|
56
|
+
lines.each{|line| line.sub!(indentation, '')}
|
57
|
+
end
|
58
58
|
|
59
59
|
return lines.join
|
60
60
|
end
|
@@ -52,9 +52,15 @@ module Decode
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
# The fully qualified name of the block.
|
56
|
+
# e.g. `::Barnyard#foo`.
|
57
|
+
def qualified_form
|
58
|
+
self.qualified_name
|
59
|
+
end
|
60
|
+
|
55
61
|
def convert(kind)
|
56
62
|
case kind
|
57
|
-
when :
|
63
|
+
when :attribute
|
58
64
|
Attribute.new(@node, @name,
|
59
65
|
comments: @comments, parent: @parent, language: @language
|
60
66
|
)
|
@@ -42,6 +42,12 @@ module Decode
|
|
42
42
|
|
43
43
|
# The long form is the same as the short form.
|
44
44
|
alias long_form short_form
|
45
|
+
|
46
|
+
# The fully qualified name of the class.
|
47
|
+
# e.g. `module ::Barnyard::Dog`.
|
48
|
+
def qualified_form
|
49
|
+
"module #{self.qualified_name}"
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
@@ -40,7 +40,7 @@ module Decode
|
|
40
40
|
class Parser
|
41
41
|
# Extract definitions from the given input file.
|
42
42
|
def definitions_for(input, &block)
|
43
|
-
top, comments = ::Parser::CurrentRuby.parse_with_comments(input
|
43
|
+
top, comments = ::Parser::CurrentRuby.parse_with_comments(input)
|
44
44
|
|
45
45
|
if top
|
46
46
|
walk_definitions(top, comments, &block)
|
@@ -241,7 +241,7 @@ module Decode
|
|
241
241
|
|
242
242
|
# Extract segments from the given input file.
|
243
243
|
def segments_for(input, &block)
|
244
|
-
top, comments = ::Parser::CurrentRuby.parse_with_comments(input
|
244
|
+
top, comments = ::Parser::CurrentRuby.parse_with_comments(input)
|
245
245
|
|
246
246
|
# We delete any leading comments:
|
247
247
|
line = 0
|
@@ -25,6 +25,37 @@ module Decode
|
|
25
25
|
module Ruby
|
26
26
|
# An Ruby-specific reference which can be resolved to zero or more definitions.
|
27
27
|
class Reference < Language::Reference
|
28
|
+
def self.from_const(node, language)
|
29
|
+
lexical_path = append_const(node)
|
30
|
+
|
31
|
+
return self.new(node.location.expression.source, language, lexical_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.append_const(node, path = [])
|
35
|
+
parent, name = node.children
|
36
|
+
|
37
|
+
if parent and parent.type != :cbase
|
38
|
+
append_const(parent, path)
|
39
|
+
end
|
40
|
+
|
41
|
+
case node.type
|
42
|
+
when :const
|
43
|
+
if parent && parent.type != :cbase
|
44
|
+
path << ['::', name]
|
45
|
+
else
|
46
|
+
path << [nil, name]
|
47
|
+
end
|
48
|
+
when :send
|
49
|
+
path << ['#', name]
|
50
|
+
when :cbase
|
51
|
+
# Ignore.
|
52
|
+
else
|
53
|
+
raise ArgumentError, "Could not determine reference for #{node}!"
|
54
|
+
end
|
55
|
+
|
56
|
+
return path
|
57
|
+
end
|
58
|
+
|
28
59
|
def split(text)
|
29
60
|
text.scan(/(::|\.|#|:)?([^:.#]+)/)
|
30
61
|
end
|
data/lib/decode/scope.rb
CHANGED
@@ -23,10 +23,13 @@ require_relative 'definition'
|
|
23
23
|
module Decode
|
24
24
|
# An abstract namespace for nesting definitions.
|
25
25
|
class Scope < Definition
|
26
|
+
# @returns [String] The name of the scope.
|
26
27
|
def short_form
|
27
28
|
@name
|
28
29
|
end
|
29
30
|
|
31
|
+
# Scopes are always containers.
|
32
|
+
# @returns [Boolean] Always `true`.
|
30
33
|
def container?
|
31
34
|
true
|
32
35
|
end
|
data/lib/decode/segment.rb
CHANGED
data/lib/decode/source.rb
CHANGED
@@ -21,34 +21,50 @@
|
|
21
21
|
require_relative 'language'
|
22
22
|
|
23
23
|
module Decode
|
24
|
+
# Represents a source file in a specific language.
|
24
25
|
class Source
|
25
26
|
def initialize(path, language)
|
26
27
|
@path = path
|
28
|
+
@buffer = nil
|
27
29
|
@language = language
|
28
30
|
end
|
29
31
|
|
32
|
+
# The path of the source file.
|
33
|
+
# @attribute [String] A file-system path.
|
30
34
|
attr :path
|
31
35
|
|
36
|
+
# The language of the source file.
|
37
|
+
# @attribute [Language::Generic]
|
32
38
|
attr :language
|
33
39
|
|
34
|
-
|
35
|
-
|
40
|
+
# Read the source file into an internal buffer/cache.
|
41
|
+
# @returns [String]
|
42
|
+
def read
|
43
|
+
@buffer ||= File.read(@path).freeze
|
36
44
|
end
|
37
45
|
|
46
|
+
# Open the source file and read all definitions.
|
47
|
+
# @yields {|definition| ...} All definitions from the source file.
|
48
|
+
# @parameter definition [Definition]
|
49
|
+
# @returns [Enumerator(Definition)] If no block given.
|
38
50
|
def definitions(&block)
|
39
51
|
return to_enum(:definitions) unless block_given?
|
40
52
|
|
41
|
-
self.
|
42
|
-
@language.definitions_for(file, &block)
|
43
|
-
end
|
53
|
+
@language.definitions_for(self.read, &block)
|
44
54
|
end
|
45
55
|
|
56
|
+
# Open the source file and read all segments.
|
57
|
+
# @yields {|segment| ...} All segments from the source file.
|
58
|
+
# @parameter segment [Segment]
|
59
|
+
# @returns [Enumerator(Segment)] If no block given.
|
46
60
|
def segments(&block)
|
47
61
|
return to_enum(:segments) unless block_given?
|
48
62
|
|
49
|
-
self.
|
50
|
-
|
51
|
-
|
63
|
+
@language.segments_for(self.read, &block)
|
64
|
+
end
|
65
|
+
|
66
|
+
def code(index = nil, relative_to: nil)
|
67
|
+
@language.code_for(self.read, index, relative_to: relative_to)
|
52
68
|
end
|
53
69
|
end
|
54
70
|
end
|
@@ -0,0 +1,44 @@
|
|
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 'match'
|
22
|
+
|
23
|
+
module Decode
|
24
|
+
module Syntax
|
25
|
+
class Link < Match
|
26
|
+
def initialize(range, definition)
|
27
|
+
@definition = definition
|
28
|
+
|
29
|
+
super(range)
|
30
|
+
end
|
31
|
+
|
32
|
+
attr :definition
|
33
|
+
|
34
|
+
def apply(output, rewriter)
|
35
|
+
output << rewriter.link_to(
|
36
|
+
@definition,
|
37
|
+
rewriter.text_for(@range)
|
38
|
+
)
|
39
|
+
|
40
|
+
return self.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -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
|
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.15.3
|
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
|
11
|
+
date: 2020-08-05 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,7 +80,7 @@ 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: []
|
@@ -139,6 +111,7 @@ files:
|
|
139
111
|
- lib/decode/language/ruby/block.rb
|
140
112
|
- lib/decode/language/ruby/call.rb
|
141
113
|
- lib/decode/language/ruby/class.rb
|
114
|
+
- lib/decode/language/ruby/code.rb
|
142
115
|
- lib/decode/language/ruby/constant.rb
|
143
116
|
- lib/decode/language/ruby/definition.rb
|
144
117
|
- lib/decode/language/ruby/function.rb
|
@@ -151,13 +124,16 @@ files:
|
|
151
124
|
- lib/decode/scope.rb
|
152
125
|
- lib/decode/segment.rb
|
153
126
|
- lib/decode/source.rb
|
127
|
+
- lib/decode/syntax/link.rb
|
128
|
+
- lib/decode/syntax/match.rb
|
129
|
+
- lib/decode/syntax/rewriter.rb
|
154
130
|
- lib/decode/trie.rb
|
155
131
|
- lib/decode/version.rb
|
156
132
|
homepage: https://github.com/ioquatix/decode
|
157
133
|
licenses:
|
158
134
|
- MIT
|
159
135
|
metadata: {}
|
160
|
-
post_install_message:
|
136
|
+
post_install_message:
|
161
137
|
rdoc_options: []
|
162
138
|
require_paths:
|
163
139
|
- lib
|
@@ -173,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
149
|
version: '0'
|
174
150
|
requirements: []
|
175
151
|
rubygems_version: 3.1.2
|
176
|
-
signing_key:
|
152
|
+
signing_key:
|
177
153
|
specification_version: 4
|
178
154
|
summary: Code analysis for documentation generation.
|
179
155
|
test_files: []
|