steep 0.28.0 → 0.29.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.
@@ -1,80 +0,0 @@
1
- module Steep
2
- module AST
3
- class Namespace
4
- attr_reader :path
5
-
6
- def initialize(path:, absolute:)
7
- @path = path
8
- @absolute = absolute
9
- end
10
-
11
- def self.empty
12
- new(path: [], absolute: false)
13
- end
14
-
15
- def self.root
16
- new(path: [], absolute: true)
17
- end
18
-
19
- def +(other)
20
- if other.absolute?
21
- other
22
- else
23
- self.class.new(path: path + other.path, absolute: absolute?)
24
- end
25
- end
26
-
27
- def append(component)
28
- self.class.new(path: path + [component], absolute: absolute?)
29
- end
30
-
31
- def parent
32
- raise "Parent with empty namespace" if empty?
33
- self.class.new(path: path.take(path.size - 1), absolute: absolute?)
34
- end
35
-
36
- def absolute?
37
- @absolute
38
- end
39
-
40
- def relative?
41
- !absolute?
42
- end
43
-
44
- def absolute!
45
- self.class.new(path: path, absolute: true)
46
- end
47
-
48
- def empty?
49
- path.empty?
50
- end
51
-
52
- def ==(other)
53
- other.is_a?(Namespace) && other.path == path && other.absolute? == absolute?
54
- end
55
-
56
- alias eql? ==
57
-
58
- def hash
59
- self.class.hash ^ path.hash ^ absolute?.hash
60
- end
61
-
62
- def to_s
63
- if empty?
64
- absolute? ? "::" : ""
65
- else
66
- s = path.join("::")
67
- absolute? ? "::#{s}::" : "#{s}::"
68
- end
69
- end
70
-
71
- def self.parse(string)
72
- if string.start_with?("::")
73
- new(path: string.split("::").drop(1).map(&:to_sym), absolute: true)
74
- else
75
- new(path: string.split("::").map(&:to_sym), absolute: false)
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1,86 +0,0 @@
1
- module Steep
2
- module Names
3
- class Base
4
- attr_reader :namespace
5
- attr_reader :name
6
- attr_reader :location
7
-
8
- def initialize(namespace:, name:, location: nil)
9
- @namespace = namespace
10
- @name = name
11
- @location = location
12
- end
13
-
14
- def absolute?
15
- namespace.absolute?
16
- end
17
-
18
- def relative?
19
- !absolute?
20
- end
21
-
22
- def ==(other)
23
- other.is_a?(self.class) && other.name == name && other.namespace == namespace
24
- end
25
-
26
- def hash
27
- self.class.hash ^ name.hash ^ namespace.hash
28
- end
29
-
30
- alias eql? ==
31
-
32
- def self.parse(string)
33
- namespace = AST::Namespace.parse(string.to_s)
34
- *_, name = namespace.path
35
- new(namespace: namespace.parent, name: name)
36
- end
37
-
38
- def absolute!
39
- self.class.new(namespace: namespace.absolute!,
40
- name: name)
41
- end
42
-
43
- def in_namespace(namespace)
44
- if absolute?
45
- self
46
- else
47
- self.class.new(namespace: namespace + self.namespace, name: name)
48
- end
49
- end
50
-
51
- def to_s
52
- "#{namespace}#{name}"
53
- end
54
- end
55
-
56
- class Module < Base
57
- def self.from_node(node)
58
- case node.type
59
- when :const, :casgn
60
- namespace = namespace_from_node(node.children[0]) or return
61
- name = node.children[1]
62
- new(namespace: namespace, name: name)
63
- end
64
- end
65
-
66
- def self.namespace_from_node(node)
67
- case node&.type
68
- when nil
69
- AST::Namespace.empty
70
- when :cbase
71
- AST::Namespace.root
72
- when :const
73
- namespace_from_node(node.children[0])&.yield_self do |parent|
74
- parent.append(node.children[1])
75
- end
76
- end
77
- end
78
- end
79
-
80
- class Interface < Base
81
- end
82
-
83
- class Alias < Base
84
- end
85
- end
86
- end