yard2steep 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile.lock +6 -1
- data/example/sample1/lib/example1.rb +20 -1
- data/example/sample1/sig/example1.rbi +3 -0
- data/lib/yard2steep/ast/p_node.rb +1 -0
- data/lib/yard2steep/gen.rb +2 -0
- data/lib/yard2steep/parser.rb +566 -373
- data/lib/yard2steep/type/parser.rb +6 -2
- data/lib/yard2steep/type.rb +9 -3
- data/lib/yard2steep/util.rb +9 -1
- data/lib/yard2steep/version.rb +1 -1
- data/sig/steep-scaffold/td.rbi +29 -42
- data/sig/yard2steep/yard2steep/parser.rbi +25 -36
- data/sig/yard2steep/yard2steep/type/parser.rbi +3 -3
- data/sig/yard2steep/yard2steep/type.rbi +2 -2
- data/yard2steep.gemspec +1 -0
- metadata +16 -2
@@ -1,13 +1,13 @@
|
|
1
1
|
module Yard2steep
|
2
2
|
class Type
|
3
3
|
class Parser
|
4
|
-
# @param [Array<String>]
|
4
|
+
# @param [Array<String>] tokens
|
5
5
|
# @return [Array<TypeBase>]
|
6
6
|
def self.parse(tokens)
|
7
7
|
Parser.new(tokens).parse
|
8
8
|
end
|
9
9
|
|
10
|
-
# @param [Array<String>]
|
10
|
+
# @param [Array<String>] tokens
|
11
11
|
def initialize(tokens)
|
12
12
|
@tokens = tokens
|
13
13
|
@types = []
|
@@ -100,6 +100,7 @@ module Yard2steep
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
# @return [HashType]
|
103
104
|
def parse_hash
|
104
105
|
debug_print!("parse_hash, peek: #{peek}")
|
105
106
|
|
@@ -107,8 +108,11 @@ module Yard2steep
|
|
107
108
|
when '{'
|
108
109
|
expect!('{')
|
109
110
|
key = parse_multiple_types('=')
|
111
|
+
Util.assert! { key.size > 0 }
|
112
|
+
|
110
113
|
expect!('>')
|
111
114
|
val = parse_multiple_types('}')
|
115
|
+
Util.assert! { val.size > 0 }
|
112
116
|
HashType.new(
|
113
117
|
key: key,
|
114
118
|
val: val,
|
data/lib/yard2steep/type.rb
CHANGED
@@ -4,7 +4,7 @@ require 'yard2steep/type/parser'
|
|
4
4
|
|
5
5
|
module Yard2steep
|
6
6
|
class Type
|
7
|
-
# @param [
|
7
|
+
# @param [String] text
|
8
8
|
# @return [String]
|
9
9
|
def self.translate(text)
|
10
10
|
Type.new(text).translate
|
@@ -15,6 +15,7 @@ module Yard2steep
|
|
15
15
|
@text = text
|
16
16
|
end
|
17
17
|
|
18
|
+
# @return [String]
|
18
19
|
def translate
|
19
20
|
tokens = tokens(@text)
|
20
21
|
ast = Parser.parse(tokens)
|
@@ -31,9 +32,14 @@ module Yard2steep
|
|
31
32
|
def tokens(str)
|
32
33
|
r = []
|
33
34
|
s = StringScanner.new(str)
|
34
|
-
while
|
35
|
+
while true
|
35
36
|
s.scan(S_RE)
|
36
|
-
|
37
|
+
break if s.eos?
|
38
|
+
if t = s.scan(TOKENS)
|
39
|
+
r.push(t)
|
40
|
+
else
|
41
|
+
raise "token must exist!"
|
42
|
+
end
|
37
43
|
end
|
38
44
|
r
|
39
45
|
end
|
data/lib/yard2steep/util.rb
CHANGED
@@ -2,10 +2,18 @@ module Yard2steep
|
|
2
2
|
module Util
|
3
3
|
class AssertError < RuntimeError; end
|
4
4
|
|
5
|
-
# @param [{ () -> any }]
|
6
5
|
# @return [void]
|
7
6
|
def self.assert!(&block)
|
8
7
|
raise AssertError.new("Assertion failed!") if !block.call
|
8
|
+
rescue AssertError => e
|
9
|
+
# NOTE: Enable when debug option is true
|
10
|
+
# print e
|
11
|
+
# code = <<-CODE
|
12
|
+
# require 'pry'
|
13
|
+
# binding.pry
|
14
|
+
# CODE
|
15
|
+
# eval(code, block.binding)
|
16
|
+
raise e
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
data/lib/yard2steep/version.rb
CHANGED
data/sig/steep-scaffold/td.rbi
CHANGED
@@ -4,59 +4,46 @@ end
|
|
4
4
|
class Yard2steep::Parser
|
5
5
|
@debug: any
|
6
6
|
@file: any
|
7
|
+
@comments_map: any
|
7
8
|
@ast: any
|
8
|
-
@stack: any
|
9
|
-
@state: any
|
10
9
|
@current_class: any
|
11
|
-
@p_types: any
|
12
10
|
@r_type: any
|
13
|
-
@
|
14
|
-
def initialize: () -> any
|
11
|
+
@p_types: any
|
12
|
+
def initialize: () -> Hash<any, any>
|
15
13
|
def parse: (any, any, ?debug: bool) -> any
|
16
|
-
def
|
17
|
-
def
|
18
|
-
def
|
19
|
-
def
|
20
|
-
def
|
21
|
-
def
|
22
|
-
def
|
23
|
-
def
|
24
|
-
def
|
25
|
-
def
|
26
|
-
def
|
27
|
-
def
|
28
|
-
def
|
29
|
-
def
|
30
|
-
def
|
31
|
-
def
|
32
|
-
def
|
33
|
-
def
|
34
|
-
def
|
14
|
+
def parse_program: (any) -> any
|
15
|
+
def parse_stmts: (any) -> any
|
16
|
+
def parse_stmt: (any) -> any
|
17
|
+
def parse_defs: (any) -> any
|
18
|
+
def parse_def: (any) -> any
|
19
|
+
def parse_method_impl: (any, any, any) -> any
|
20
|
+
def extract_p_types!: (any) -> void
|
21
|
+
def parse_comment!: (any) -> any
|
22
|
+
def try_param_comment: (any) -> bool
|
23
|
+
def try_return_comment: (any) -> bool
|
24
|
+
def parse_params: (any) -> any
|
25
|
+
def parse_paren_params: (any) -> any
|
26
|
+
def parse_no_paren_params: (any) -> any
|
27
|
+
def within_context: () -> any
|
28
|
+
def parse_class_or_module: (any) -> any
|
29
|
+
def parse_bodystmt: (any) -> any
|
30
|
+
def parse_assign: (any) -> void
|
31
|
+
def parse_command: (any) -> void
|
32
|
+
def parse_command_args_add_block: (any) -> any
|
33
|
+
def parse_method_add_arg: (any) -> void
|
34
|
+
def parse_attr_reader: (any) -> any
|
35
|
+
def extract_comments: (any) -> any
|
36
|
+
def debug_print!: (any) -> void
|
35
37
|
def type_node: (any) -> any
|
36
|
-
def
|
38
|
+
def block_type_node: (any) -> any
|
37
39
|
def normalize_type: (any) -> any
|
38
40
|
end
|
39
41
|
|
40
42
|
Yard2steep::Parser::S_RE: Regexp
|
41
|
-
Yard2steep::Parser::S_P_RE: Regexp
|
42
|
-
Yard2steep::Parser::PRE_RE: Regexp
|
43
|
-
Yard2steep::Parser::POST_RE: Regexp
|
44
|
-
Yard2steep::Parser::CLASS_RE: Regexp
|
45
|
-
Yard2steep::Parser::MODULE_RE: Regexp
|
46
|
-
Yard2steep::Parser::S_CLASS_RE: Regexp
|
47
|
-
Yard2steep::Parser::END_RE: Regexp
|
48
|
-
Yard2steep::Parser::CONSTANT_ASSIGN_RE: Regexp
|
49
|
-
Yard2steep::Parser::POSTFIX_IF_RE: Regexp
|
50
|
-
Yard2steep::Parser::BEGIN_END_RE: Regexp
|
51
|
-
Yard2steep::Parser::COMMENT_RE: Regexp
|
52
43
|
Yard2steep::Parser::TYPE_WITH_PAREN_RE: Regexp
|
44
|
+
Yard2steep::Parser::COMMENT_RE: Regexp
|
53
45
|
Yard2steep::Parser::PARAM_RE: Regexp
|
54
46
|
Yard2steep::Parser::RETURN_RE: Regexp
|
55
|
-
Yard2steep::Parser::PAREN_RE: Regexp
|
56
|
-
Yard2steep::Parser::ARGS_RE: Regexp
|
57
|
-
Yard2steep::Parser::METHOD_RE: Regexp
|
58
|
-
Yard2steep::Parser::ATTR_RE: Regexp
|
59
|
-
Yard2steep::Parser::STATES: Hash<any, any>
|
60
47
|
Yard2steep::Parser::ANY_TYPE: String
|
61
48
|
Yard2steep::Parser::ANY_BLOCK_TYPE: String
|
62
49
|
class Yard2steep::CLI
|
@@ -140,7 +127,7 @@ end
|
|
140
127
|
Yard2steep::Type::S_RE: Regexp
|
141
128
|
Yard2steep::Type::TOKENS: Regexp
|
142
129
|
module Yard2steep::Util
|
143
|
-
def self.assert!:
|
130
|
+
def self.assert!: () -> any
|
144
131
|
end
|
145
132
|
|
146
133
|
class Yard2steep::Util::AssertError
|
@@ -1,48 +1,37 @@
|
|
1
1
|
class Yard2steep::Parser
|
2
2
|
def initialize: -> any
|
3
3
|
def parse: (String, String, ?debug: bool) -> AST::ClassNode
|
4
|
-
def
|
5
|
-
def
|
6
|
-
def
|
7
|
-
def
|
8
|
-
def
|
9
|
-
def
|
10
|
-
def
|
11
|
-
def
|
12
|
-
def
|
13
|
-
def
|
14
|
-
def
|
15
|
-
def
|
16
|
-
def
|
17
|
-
def
|
18
|
-
def
|
19
|
-
def
|
20
|
-
def
|
21
|
-
def
|
22
|
-
def
|
4
|
+
def parse_program: (String) -> void
|
5
|
+
def parse_stmts: (Array<any>) -> void
|
6
|
+
def parse_stmt: (Array<any>) -> void
|
7
|
+
def parse_defs: (Array<any>) -> void
|
8
|
+
def parse_def: (Array<any>) -> void
|
9
|
+
def parse_method_impl: (String, Integer, Array<any>) -> void
|
10
|
+
def extract_p_types!: (Integer) -> void
|
11
|
+
def parse_comment!: (String) -> void
|
12
|
+
def try_param_comment: (String) -> bool
|
13
|
+
def try_return_comment: (String) -> bool
|
14
|
+
def parse_params: (Array<any>) -> Array<AST::PNode>
|
15
|
+
def parse_paren_params: (Array<any>) -> Array<AST::PNode>
|
16
|
+
def parse_no_paren_params: (Array<any>) -> Array<AST::PNode>
|
17
|
+
def within_context: { (any) -> any } -> void
|
18
|
+
def parse_class_or_module: (Array<any>) -> void
|
19
|
+
def parse_bodystmt: (Array<any>) -> void
|
20
|
+
def parse_assign: (Array<any>) -> void
|
21
|
+
def parse_command: (Array<any>) -> void
|
22
|
+
def parse_command_args_add_block: (Array<any>) -> Array<String>
|
23
|
+
def parse_method_add_arg: (Array<any>) -> void
|
24
|
+
def parse_attr_reader: (any) -> void
|
25
|
+
def extract_comments: (String) -> Hash<String, String>
|
26
|
+
def debug_print!: (String) -> void
|
23
27
|
def type_node: (String) -> AST::PTypeNode
|
24
|
-
def
|
28
|
+
def block_type_node: (String) -> AST::PTypeNode
|
25
29
|
def normalize_type: (String) -> String
|
26
30
|
end
|
27
31
|
Yard2steep::Parser::S_RE: any
|
28
|
-
Yard2steep::Parser::S_P_RE: any
|
29
|
-
Yard2steep::Parser::PRE_RE: any
|
30
|
-
Yard2steep::Parser::POST_RE: any
|
31
|
-
Yard2steep::Parser::CLASS_RE: any
|
32
|
-
Yard2steep::Parser::MODULE_RE: any
|
33
|
-
Yard2steep::Parser::S_CLASS_RE: any
|
34
|
-
Yard2steep::Parser::END_RE: any
|
35
|
-
Yard2steep::Parser::CONSTANT_ASSIGN_RE: any
|
36
|
-
Yard2steep::Parser::POSTFIX_IF_RE: any
|
37
|
-
Yard2steep::Parser::BEGIN_END_RE: any
|
38
|
-
Yard2steep::Parser::COMMENT_RE: any
|
39
32
|
Yard2steep::Parser::TYPE_WITH_PAREN_RE: any
|
33
|
+
Yard2steep::Parser::COMMENT_RE: any
|
40
34
|
Yard2steep::Parser::PARAM_RE: any
|
41
35
|
Yard2steep::Parser::RETURN_RE: any
|
42
|
-
Yard2steep::Parser::PAREN_RE: any
|
43
|
-
Yard2steep::Parser::ARGS_RE: any
|
44
|
-
Yard2steep::Parser::METHOD_RE: any
|
45
|
-
Yard2steep::Parser::ATTR_RE: any
|
46
|
-
Yard2steep::Parser::STATES: any
|
47
36
|
Yard2steep::Parser::ANY_TYPE: any
|
48
37
|
Yard2steep::Parser::ANY_BLOCK_TYPE: any
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Yard2steep::Type::Parser
|
2
|
-
def self.parse: (
|
3
|
-
def initialize: (
|
2
|
+
def self.parse: (Array<String>) -> Array<TypeBase>
|
3
|
+
def initialize: (Array<String>) -> any
|
4
4
|
def parse: -> any
|
5
5
|
def parse_type: -> TypeBase
|
6
6
|
def parse_normal_type: (String) -> NormalType
|
7
7
|
def parse_multiple_types: (String) -> Array<TypeBase>
|
8
8
|
def parse_array: -> ArrayType
|
9
|
-
def parse_hash: ->
|
9
|
+
def parse_hash: -> HashType
|
10
10
|
def expect!: (String) -> any
|
11
11
|
def get: -> any
|
12
12
|
def peek: -> any
|
data/yard2steep.gemspec
CHANGED
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.2"
|
27
27
|
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "pry-doc"
|
28
29
|
spec.add_development_dependency "steep", "0.4.0"
|
29
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard2steep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nao Minami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-doc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: steep
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|