yard2steep 0.1.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 +7 -0
- data/.gitignore +52 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/steep-check +8 -0
- data/bin/steep-gen +16 -0
- data/bin/steep-gen-check +7 -0
- data/example/sample1/lib/example1.rb +107 -0
- data/example/sample1/sig/example1.rbi +21 -0
- data/example/sample2/lib/2.rb +68 -0
- data/example/sample2/sig/2.rbi +25 -0
- data/exe/yard2steep +6 -0
- data/lib/yard2steep/ast/class_node.rb +95 -0
- data/lib/yard2steep/ast/constant_node.rb +21 -0
- data/lib/yard2steep/ast/i_var_node.rb +15 -0
- data/lib/yard2steep/ast/method_node.rb +21 -0
- data/lib/yard2steep/ast/p_node.rb +23 -0
- data/lib/yard2steep/ast/p_type_node.rb +26 -0
- data/lib/yard2steep/ast.rb +11 -0
- data/lib/yard2steep/cli/option.rb +27 -0
- data/lib/yard2steep/cli.rb +70 -0
- data/lib/yard2steep/engine.rb +23 -0
- data/lib/yard2steep/gen.rb +162 -0
- data/lib/yard2steep/parser.rb +584 -0
- data/lib/yard2steep/util.rb +11 -0
- data/lib/yard2steep/version.rb +3 -0
- data/lib/yard2steep.rb +9 -0
- data/sig/steep-scaffold/td.rbi +174 -0
- data/sig/yard2steep/yard2steep/ast/class_node.rbi +26 -0
- data/sig/yard2steep/yard2steep/ast/constant_node.rbi +8 -0
- data/sig/yard2steep/yard2steep/ast/i_var_node.rbi +5 -0
- data/sig/yard2steep/yard2steep/ast/method_node.rbi +9 -0
- data/sig/yard2steep/yard2steep/ast/p_node.rbi +8 -0
- data/sig/yard2steep/yard2steep/ast/p_type_node.rbi +10 -0
- data/sig/yard2steep/yard2steep/ast.rbi +0 -0
- data/sig/yard2steep/yard2steep/cli/option.rbi +12 -0
- data/sig/yard2steep/yard2steep/cli.rbi +9 -0
- data/sig/yard2steep/yard2steep/engine.rbi +3 -0
- data/sig/yard2steep/yard2steep/gen.rbi +15 -0
- data/sig/yard2steep/yard2steep/parser.rbi +52 -0
- data/sig/yard2steep/yard2steep/util.rbi +3 -0
- data/sig/yard2steep/yard2steep/version.rbi +1 -0
- data/sig/yard2steep/yard2steep.rbi +0 -0
- data/yard2steep.gemspec +29 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb6af8f5dee325bf592f102d800a9d740fbe6cf1abf5548487def95356834d39
|
4
|
+
data.tar.gz: 42b2cd5e679580d2b1765cd1a8204a5940f4b4c683dde3b151f061ebe76311c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60dee77fb6ea4475770849f0f89f44de867a9bcee2d59fdb988443a4edc77945b0540e7932b7a1b3a4f888ef33c97e378f81c3601830d8f90b311905a4c1598e
|
7
|
+
data.tar.gz: 198627709bc5227d0996fdadf7be838421dbacf0c01a3ef34e3ab24af66e90db02ee96cea76c1e02732f94578207aae3fc54a5cb06f891cf0365e1c8f8afe0e5
|
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
tags
|
2
|
+
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/spec/examples.txt
|
11
|
+
/test/tmp/
|
12
|
+
/test/version_tmp/
|
13
|
+
/tmp/
|
14
|
+
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
## Specific to RubyMotion:
|
19
|
+
.dat*
|
20
|
+
.repl_history
|
21
|
+
build/
|
22
|
+
*.bridgesupport
|
23
|
+
build-iPhoneOS/
|
24
|
+
build-iPhoneSimulator/
|
25
|
+
|
26
|
+
## Specific to RubyMotion (use of CocoaPods):
|
27
|
+
#
|
28
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
29
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
30
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
31
|
+
#
|
32
|
+
# vendor/Pods/
|
33
|
+
|
34
|
+
## Documentation cache and generated files:
|
35
|
+
/.yardoc/
|
36
|
+
/_yardoc/
|
37
|
+
/doc/
|
38
|
+
/rdoc/
|
39
|
+
|
40
|
+
## Environment normalization:
|
41
|
+
/.bundle/
|
42
|
+
/vendor/bundle
|
43
|
+
/lib/bundler/man/
|
44
|
+
|
45
|
+
# for a library or gem, you might want to ignore these files since the code is
|
46
|
+
# intended to run in multiple environments; otherwise, check them in:
|
47
|
+
# Gemfile.lock
|
48
|
+
# .ruby-version
|
49
|
+
# .ruby-gemset
|
50
|
+
|
51
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
52
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yard2steep (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.1.6)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
ast (2.4.0)
|
15
|
+
ast_utils (0.1.0)
|
16
|
+
parser (~> 2.4)
|
17
|
+
thor (~> 0.19.4)
|
18
|
+
coderay (1.1.2)
|
19
|
+
concurrent-ruby (1.0.5)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
i18n (1.0.1)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
method_source (0.9.0)
|
24
|
+
minitest (5.11.3)
|
25
|
+
parser (2.5.1.0)
|
26
|
+
ast (~> 2.4.0)
|
27
|
+
pry (0.11.3)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
rainbow (2.2.2)
|
31
|
+
rake
|
32
|
+
rake (10.5.0)
|
33
|
+
rspec (3.7.0)
|
34
|
+
rspec-core (~> 3.7.0)
|
35
|
+
rspec-expectations (~> 3.7.0)
|
36
|
+
rspec-mocks (~> 3.7.0)
|
37
|
+
rspec-core (3.7.1)
|
38
|
+
rspec-support (~> 3.7.0)
|
39
|
+
rspec-expectations (3.7.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.7.0)
|
42
|
+
rspec-mocks (3.7.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.7.0)
|
45
|
+
rspec-support (3.7.1)
|
46
|
+
steep (0.4.0)
|
47
|
+
activesupport (~> 5.1.0)
|
48
|
+
ast_utils (~> 0.1.0)
|
49
|
+
parser (~> 2.4)
|
50
|
+
rainbow (~> 2.2.2)
|
51
|
+
thor (0.19.4)
|
52
|
+
thread_safe (0.3.6)
|
53
|
+
tzinfo (1.2.5)
|
54
|
+
thread_safe (~> 0.1)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bundler (~> 1.16)
|
61
|
+
pry
|
62
|
+
rake (~> 10.0)
|
63
|
+
rspec (~> 3.2)
|
64
|
+
steep (= 0.4.0)
|
65
|
+
yard2steep!
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Nao Minami
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Yard2steep
|
2
|
+
|
3
|
+
Generate [steep](https://github.com/soutaro/steep) type definition file from yard annotation.
|
4
|
+
|
5
|
+
:warning: **This is highly experimental project. Current version is 0.1.0.**
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'yard2steep'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yard2steep
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
`yard2steep` generates steep type definition file from yard annotation.
|
26
|
+
|
27
|
+
```console
|
28
|
+
$ yard2steep lib sig
|
29
|
+
```
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# lib/parser.rb
|
33
|
+
class AST
|
34
|
+
# @return [String]
|
35
|
+
def to_s
|
36
|
+
# Do something
|
37
|
+
"AST"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Parser
|
42
|
+
# @param [String] text
|
43
|
+
# @return [AST]
|
44
|
+
def parse(text)
|
45
|
+
ast = AST.new
|
46
|
+
# Do something
|
47
|
+
ast
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
`sig/parser.rbi` is generated.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# sig/parser.rbi
|
56
|
+
class AST
|
57
|
+
def to_s: -> String
|
58
|
+
end
|
59
|
+
class Parser
|
60
|
+
def parse: (String) -> AST
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
After generating `.rbi` file, we can run `steep check` command to type check. (cf. [Usage of steep](https://github.com/soutaro/steep#usage) )
|
65
|
+
|
66
|
+
```
|
67
|
+
$ steep check lib -I sig
|
68
|
+
```
|
69
|
+
|
70
|
+
Congraturation! :tada:
|
71
|
+
You did type checking by yard annotation!
|
72
|
+
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
77
|
+
|
78
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/south37/yard2steep.
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yard2steep"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/steep-check
ADDED
data/bin/steep-gen
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
print "Generate interface with steep-scaffold\n"
|
4
|
+
TARGET = 'sig/steep-scaffold/td.rbi'
|
5
|
+
# Update sig/steep-scaffold/td.rbi
|
6
|
+
%x{ bundle exec steep scaffold lib > #{TARGET} }
|
7
|
+
# Postfix
|
8
|
+
text = File.read(TARGET)
|
9
|
+
# Fix block type
|
10
|
+
text = text.gsub('def self.assert!: () -> void', 'def self.assert!: { () -> any } -> void')
|
11
|
+
# Fix duplicated `module Yard2steep
|
12
|
+
text = text.split("\n")[0..-3].join("\n") + "\n"
|
13
|
+
File.write(TARGET, text)
|
14
|
+
|
15
|
+
print "Generate interface with yard2steep\n"
|
16
|
+
%x{ bundle exec yard2steep lib sig/yard2steep }
|
data/bin/steep-gen-check
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# @param [Array] contents
|
2
|
+
# @return [Symbol]
|
3
|
+
def first(contents:)
|
4
|
+
# .
|
5
|
+
# .
|
6
|
+
# .
|
7
|
+
# NOTE: this is wrong comment. so should ignore it
|
8
|
+
# @param [Array] contents
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
|
12
|
+
# NOTE: this is wrong comment. so should ignore it
|
13
|
+
# @param [Array] contents
|
14
|
+
|
15
|
+
class MyClass
|
16
|
+
# NOTE: method definition in singleton class should be ignored
|
17
|
+
class << self
|
18
|
+
# @return [String]
|
19
|
+
def ok
|
20
|
+
return 'no' if true
|
21
|
+
'ok'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
CONSTANT = "This is constant".freeze
|
26
|
+
|
27
|
+
attr_reader :index
|
28
|
+
|
29
|
+
# This for should not be used.
|
30
|
+
# @return [String]
|
31
|
+
def self.name
|
32
|
+
'name'
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def name
|
37
|
+
'name'
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Array(Symbol, Symbol)]
|
41
|
+
def pair
|
42
|
+
[:ok, :no]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Array(Symbol, Integer)]
|
46
|
+
def type
|
47
|
+
[:number, 1]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Hash]
|
51
|
+
def opts
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param [Integer] off
|
56
|
+
# @return [Hash{ Symbol => Integer, nil }]
|
57
|
+
def values(off: 0)
|
58
|
+
{ ok: 3, no: nil }
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Array<Integer>] contents
|
62
|
+
# @param [Symbol] order
|
63
|
+
# @return [Array<Integer>]
|
64
|
+
def reverse contents, order:
|
65
|
+
if order == :normal
|
66
|
+
return []
|
67
|
+
end
|
68
|
+
|
69
|
+
case order
|
70
|
+
when :other then return []
|
71
|
+
else
|
72
|
+
raise "invalid"
|
73
|
+
end
|
74
|
+
# .
|
75
|
+
# .
|
76
|
+
# .
|
77
|
+
# NOTE: this is wrong comment. so should ignore it
|
78
|
+
# @param [Array] contents
|
79
|
+
[]
|
80
|
+
end
|
81
|
+
|
82
|
+
# NOTE: should be interpreterd as any -> any
|
83
|
+
def first!(list)
|
84
|
+
list.last
|
85
|
+
end
|
86
|
+
|
87
|
+
# NOTE: should be interpreterd as any -> any
|
88
|
+
def present?(list)
|
89
|
+
list.size > 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def mysum(list, &block)
|
93
|
+
list.map { |e| block.call(e) }.inject(&:+)
|
94
|
+
end
|
95
|
+
|
96
|
+
module InnerClass
|
97
|
+
# @param [Integer] source
|
98
|
+
# @return [Integer]
|
99
|
+
def double(source:); source * 2; end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class OtherClass < MyClass
|
104
|
+
def yes
|
105
|
+
'yes'
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class MyClass
|
2
|
+
@index: any
|
3
|
+
def index: -> any
|
4
|
+
def self.name: -> String
|
5
|
+
def name: -> String
|
6
|
+
def pair: -> Array<Symbol>
|
7
|
+
def type: -> Array<Symbol | Integer>
|
8
|
+
def opts: -> Hash<any, any>
|
9
|
+
def values: (?off: Integer) -> Hash<Symbol, Integer | nil>
|
10
|
+
def reverse: (Array<Integer>, order: Symbol) -> Array<Integer>
|
11
|
+
def first!: (any) -> any
|
12
|
+
def present?: (any) -> any
|
13
|
+
def mysum: (any) { (any) -> any } -> any
|
14
|
+
end
|
15
|
+
MyClass::CONSTANT: any
|
16
|
+
module MyClass::InnerClass
|
17
|
+
def double: (source: Integer) -> Integer
|
18
|
+
end
|
19
|
+
class OtherClass
|
20
|
+
def yes: -> any
|
21
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class Person
|
2
|
+
# `@dynamic` annotation is to tell steep that
|
3
|
+
# the `name` and `contacts` methods are defined without def syntax.
|
4
|
+
# (Steep can skip checking if the methods are implemented.)
|
5
|
+
|
6
|
+
# @dynamic name, contacts
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :contacts
|
9
|
+
|
10
|
+
def initialize(name:)
|
11
|
+
@name = name
|
12
|
+
@contacts = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def guess_country()
|
16
|
+
contacts.map do |contact|
|
17
|
+
# With case expression, simple type-case is implemented.
|
18
|
+
# `contact` has type of `Phone | Email` but in the `when` clause, contact has type of `Phone`.
|
19
|
+
case contact
|
20
|
+
when Phone
|
21
|
+
contact.country
|
22
|
+
end
|
23
|
+
end.compact.first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Email
|
28
|
+
# @dynamic address
|
29
|
+
attr_reader :address
|
30
|
+
|
31
|
+
def initialize(address:)
|
32
|
+
@address = address
|
33
|
+
end
|
34
|
+
|
35
|
+
def ==(other)
|
36
|
+
# `other` has type of `any`, which means type checking is skipped.
|
37
|
+
# No type errors can be detected in this method.
|
38
|
+
other.is_a?(self.class) && other.address == address
|
39
|
+
end
|
40
|
+
|
41
|
+
def hash
|
42
|
+
self.class.hash ^ address.hash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Phone
|
47
|
+
# @dynamic country, number
|
48
|
+
attr_reader :country, :number
|
49
|
+
|
50
|
+
def initialize(country:, number:)
|
51
|
+
@country = country
|
52
|
+
@number = number
|
53
|
+
end
|
54
|
+
|
55
|
+
def ==(other)
|
56
|
+
# You cannot use `case` for type case because `other` has type of `any`, not a union type.
|
57
|
+
# You have to explicitly declare the type of `other` in `if` expression.
|
58
|
+
|
59
|
+
if other.is_a?(Phone)
|
60
|
+
# @type var other: Phone
|
61
|
+
other.country == country && other.number == number
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def hash
|
66
|
+
self.class.hash ^ country.hash ^ number.hash
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Person
|
2
|
+
@name: String
|
3
|
+
@contacts: Array<Email | Phone>
|
4
|
+
|
5
|
+
def initialize: (name: String) -> any
|
6
|
+
def name: -> String
|
7
|
+
def contacts: -> Array<Email | Phone>
|
8
|
+
def guess_country: -> (String | nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Email
|
12
|
+
@address: String
|
13
|
+
|
14
|
+
def initialize: (address: String) -> any
|
15
|
+
def address: -> String
|
16
|
+
end
|
17
|
+
|
18
|
+
class Phone
|
19
|
+
@country: String
|
20
|
+
@number: String
|
21
|
+
|
22
|
+
def initialize: (country: String, number: String) -> any
|
23
|
+
def country: -> String
|
24
|
+
def number: -> String
|
25
|
+
end
|
data/exe/yard2steep
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module Yard2steep
|
2
|
+
module AST
|
3
|
+
# AST::ClassNode represents `Class` or `Module` AST.
|
4
|
+
class ClassNode
|
5
|
+
# @return [AST::ClassNode]
|
6
|
+
def self.create_main
|
7
|
+
AST::ClassNode.new(
|
8
|
+
kind: 'module',
|
9
|
+
c_name: 'main',
|
10
|
+
parent: nil,
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @dynamic kind, c_name, c_list, m_list, ivar_list, children, parent
|
15
|
+
attr_reader :kind, :c_name, :c_list, :m_list, :ivar_list, :children, :parent
|
16
|
+
|
17
|
+
KIND = ['class', 'module']
|
18
|
+
|
19
|
+
# @param [String] kind
|
20
|
+
# @param [String] c_name
|
21
|
+
# @param [AST::ClassNode | nil] parent
|
22
|
+
def initialize(kind:, c_name:, parent:)
|
23
|
+
Util.assert! { KIND.include?(kind) }
|
24
|
+
Util.assert! { c_name.is_a?(String) }
|
25
|
+
Util.assert! {
|
26
|
+
parent.is_a?(AST::ClassNode) ||
|
27
|
+
(parent == nil && c_name == 'main')
|
28
|
+
}
|
29
|
+
@kind = kind
|
30
|
+
@c_name = c_name
|
31
|
+
@c_list = [] # list of constants
|
32
|
+
@m_list = [] # list of methods
|
33
|
+
@ivar_list = [] # list of instance variables
|
34
|
+
@children = [] # list of child classes
|
35
|
+
@parent = parent
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [AST::ConstantNode] c
|
39
|
+
# @return [void]
|
40
|
+
def append_constant(c)
|
41
|
+
@c_list.push(c)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param [AST::MethodNode] m
|
45
|
+
# @return [void]
|
46
|
+
def append_m(m)
|
47
|
+
@m_list.push(m)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param [AST::IVarNode] ivar
|
51
|
+
# @return [void]
|
52
|
+
def append_ivar(ivar)
|
53
|
+
@ivar_list.push(ivar)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [AST::ClassNode] child
|
57
|
+
# @return [void]
|
58
|
+
def append_child(child)
|
59
|
+
@children.push(child)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [String]
|
63
|
+
def long_name
|
64
|
+
@long_name ||= begin
|
65
|
+
# NOTE: main has no long_name
|
66
|
+
if @c_name == 'main'
|
67
|
+
''
|
68
|
+
elsif @parent.c_name == 'main'
|
69
|
+
@c_name
|
70
|
+
else
|
71
|
+
"#{@parent.long_name}::#{@c_name}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [String]
|
77
|
+
def to_s
|
78
|
+
inspect
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [String]
|
82
|
+
def inspect
|
83
|
+
<<-EOF
|
84
|
+
{
|
85
|
+
#{@kind}: #{c_name},
|
86
|
+
c_list: [#{@c_list.map(&:to_s).map { |s| "#{s}\n" }.join}],
|
87
|
+
m_list: [#{@m_list.map(&:to_s).map { |s| "#{s}\n" }.join}],
|
88
|
+
ivar_list: [#{@ivar_list.map(&:to_s).map { |s| "#{s}\n" }.join}],
|
89
|
+
children: [#{@children.map(&:to_s).map { |s| "#{s}\n" }.join}],
|
90
|
+
}
|
91
|
+
EOF
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Yard2steep
|
2
|
+
module AST
|
3
|
+
class ConstantNode
|
4
|
+
# @dynamic name, klass
|
5
|
+
attr_reader :name, :klass
|
6
|
+
|
7
|
+
# @param [String] name
|
8
|
+
# @param [String] klass
|
9
|
+
def initialize(name:, klass:)
|
10
|
+
Util.assert! { name.is_a?(String) }
|
11
|
+
@name = name
|
12
|
+
@klass = klass
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
def long_name
|
17
|
+
"#{@klass.long_name}::#{@name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Yard2steep
|
2
|
+
module AST
|
3
|
+
# IVarNode represents `instance variable` AST.
|
4
|
+
class IVarNode
|
5
|
+
# @dynamic name
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
# @param [String] name
|
9
|
+
def initialize(name:)
|
10
|
+
Util.assert! { name.is_a?(String) }
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|