rbs_inline_data 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -1
- data/CHANGELOG.md +4 -0
- data/lib/rbs_inline_data/cli.rb +17 -9
- data/lib/rbs_inline_data/parser.rb +46 -23
- data/lib/rbs_inline_data/version.rb +1 -1
- data/sig/generated/data/lib/rbs_inline_data/parser.rbs +8 -0
- data/sig/generated/rbs_inline_data/cli.rbs +6 -0
- data/sig/generated/rbs_inline_data/parser.rbs +15 -2
- data/sig/patch.rbs +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e626cd6506b96f771d5b5e178354e6fcca38b1ee8f9eb1e8c6eaf9191ddb9074
|
4
|
+
data.tar.gz: 79cd75b8df23c3066617a5b0a6186b9dc8617b444c5c6318816714bcfc285cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a648312df3817a4e65e810f12ba3a63dd63746c00db2f289b037883563c61da31fc9d1b208aaa3d7a4149ed651d07171eb62134775b257c7e15e889e95ed3ff
|
7
|
+
data.tar.gz: 31eaf6f6f76f5995b5e9c3ce2e878a756601dfb8a04b16e6699b45e2465d7d879ca4b8ebd2cebf1cf530809ec5aca0ace9abf40c5a390e0266c20a22b0f68910
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 3.
|
2
|
+
TargetRubyVersion: 3.3
|
3
|
+
NewCops: enable
|
3
4
|
|
4
5
|
Style/StringLiterals:
|
5
6
|
EnforcedStyle: double_quotes
|
@@ -9,3 +10,16 @@ Style/StringLiteralsInInterpolation:
|
|
9
10
|
|
10
11
|
Layout/LeadingCommentSpace:
|
11
12
|
Enabled: false
|
13
|
+
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Exclude:
|
16
|
+
- 'test/**/*'
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Exclude:
|
20
|
+
- 'test/**/*'
|
21
|
+
Max: 20
|
22
|
+
|
23
|
+
Style/Style/Documentation:
|
24
|
+
Enabled: false
|
25
|
+
|
data/CHANGELOG.md
CHANGED
data/lib/rbs_inline_data/cli.rb
CHANGED
@@ -6,6 +6,7 @@ require "rbs_inline_data/parser"
|
|
6
6
|
require "rbs_inline_data/writer"
|
7
7
|
|
8
8
|
module RbsInlineData
|
9
|
+
# Process executed when running the rbs-inline-data command.
|
9
10
|
class CLI
|
10
11
|
#:: (Array[String]) -> void
|
11
12
|
def run(args)
|
@@ -18,22 +19,29 @@ module RbsInlineData
|
|
18
19
|
end
|
19
20
|
end.parse!(args)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
get_targets(args[0]).each do |target|
|
23
|
+
result = Prism.parse_file(target.to_s)
|
24
|
+
definitions = Parser.parse(result)
|
25
|
+
Writer.write(definitions, output_path ? (output_path + target).sub_ext(".rbs") : nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
#:: (String) -> Array[Pathname]
|
32
|
+
def get_targets(path)
|
33
|
+
targets = Pathname.glob(path).flat_map do |pathname|
|
34
|
+
if pathname.directory?
|
35
|
+
Pathname.glob(pathname.join("**/*.rb").to_s)
|
24
36
|
else
|
25
|
-
|
37
|
+
pathname
|
26
38
|
end
|
27
39
|
end
|
28
40
|
|
29
41
|
targets.sort!
|
30
42
|
targets.uniq!
|
31
43
|
|
32
|
-
targets
|
33
|
-
result = Prism.parse_file(target.to_s)
|
34
|
-
definitions = Parser.parse(result)
|
35
|
-
Writer.write(definitions, output_path ? (output_path + target).sub_ext(".rbs") : nil)
|
36
|
-
end
|
44
|
+
targets
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
@@ -14,21 +14,47 @@ module RbsInlineData
|
|
14
14
|
:field_name, #:: String
|
15
15
|
:type #:: String
|
16
16
|
)
|
17
|
+
# @rbs skip
|
18
|
+
Comments = Data.define(
|
19
|
+
:comment_lines #:: Hash[Integer, String]
|
20
|
+
)
|
21
|
+
class Comments
|
22
|
+
MARKER = "#::"
|
23
|
+
|
24
|
+
#:: (Array[Prism::Comment]) -> RbsInlineData::Parser::Comments
|
25
|
+
def self.from_prism_comments(comments)
|
26
|
+
# @type var comment_lines: Hash[Integer, String]
|
27
|
+
comment_lines = {}
|
28
|
+
comments.each do |comment|
|
29
|
+
sliced = comment.slice
|
30
|
+
next unless sliced.start_with?(MARKER)
|
31
|
+
|
32
|
+
comment_lines[comment.location.start_line] = sliced.sub(MARKER, "").strip
|
33
|
+
end
|
34
|
+
|
35
|
+
new(comment_lines:)
|
36
|
+
end
|
37
|
+
end
|
17
38
|
|
18
39
|
# @rbs @definitions: Array[RbsInlineData::Parser::TypedDefinition]
|
19
40
|
# @rbs @surronding_class_or_module: Array[Symbol]
|
41
|
+
# @rbs @comments: RbsInlineData::Parser::Comments
|
20
42
|
|
21
|
-
|
22
|
-
|
43
|
+
# rubocop:disable Lint/MissingSuper
|
44
|
+
#:: (Array[RbsInlineData::Parser::TypedDefinition], RbsInlineData::Parser::Comments) -> void
|
45
|
+
def initialize(definitions, comments)
|
23
46
|
@definitions = definitions
|
47
|
+
@comments = comments
|
24
48
|
@surronding_class_or_module = []
|
25
49
|
end
|
50
|
+
# rubocop:enable Lint/MissingSuper
|
26
51
|
|
27
52
|
#:: (Prism::ParseResult) -> Array[RbsInlineData::Parser::TypedDefinition]
|
28
53
|
def self.parse(result)
|
29
54
|
# @type var definitions: Array[RbsInlineData::Parser::TypedDefinition]
|
30
55
|
definitions = []
|
31
|
-
|
56
|
+
comments = Comments.from_prism_comments(result.comments)
|
57
|
+
instance = new(definitions, comments)
|
32
58
|
result.value.accept(instance)
|
33
59
|
definitions
|
34
60
|
end
|
@@ -78,30 +104,27 @@ module RbsInlineData
|
|
78
104
|
|
79
105
|
#:: (Prism::ConstantWriteNode) -> RbsInlineData::Parser::TypedDefinition?
|
80
106
|
def extract_definition(node)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
when /:(\w+),?/
|
92
|
-
[::Regexp.last_match(1), "untyped"]
|
93
|
-
end
|
94
|
-
end.compact.map do |field_name, type|
|
95
|
-
TypedField.new(
|
96
|
-
field_name: field_name,
|
97
|
-
type: type
|
98
|
-
)
|
107
|
+
arguments_node = node.value.arguments
|
108
|
+
if arguments_node
|
109
|
+
typed_fields = arguments_node.arguments.map do |sym_node|
|
110
|
+
return nil unless sym_node.is_a?(Prism::SymbolNode)
|
111
|
+
|
112
|
+
TypedField.new(
|
113
|
+
field_name: sym_node.unescaped,
|
114
|
+
type: type_of(sym_node)
|
115
|
+
)
|
116
|
+
end.compact
|
99
117
|
end
|
100
118
|
|
101
119
|
TypedDefinition.new(
|
102
|
-
class_name:
|
103
|
-
fields:
|
120
|
+
class_name: "#{@surronding_class_or_module.join("::")}::#{node.name}",
|
121
|
+
fields: typed_fields || []
|
104
122
|
)
|
105
123
|
end
|
124
|
+
|
125
|
+
#:: (Prism::SymbolNode) -> String
|
126
|
+
def type_of(node)
|
127
|
+
@comments.comment_lines[node.location.start_line] || "untyped"
|
128
|
+
end
|
106
129
|
end
|
107
130
|
end
|
@@ -15,3 +15,11 @@ class RbsInlineData::Parser::TypedField
|
|
15
15
|
| (**untyped) -> ::RbsInlineData::Parser::TypedField
|
16
16
|
| ...
|
17
17
|
end
|
18
|
+
|
19
|
+
class RbsInlineData::Parser::Comments
|
20
|
+
extend Data::_DataClass
|
21
|
+
attr_reader comment_lines: Hash[Integer, String]
|
22
|
+
def self.new: (*untyped) -> ::RbsInlineData::Parser::Comments
|
23
|
+
| (**untyped) -> ::RbsInlineData::Parser::Comments
|
24
|
+
| ...
|
25
|
+
end
|
@@ -1,8 +1,14 @@
|
|
1
1
|
# Generated from lib/rbs_inline_data/cli.rb with RBS::Inline
|
2
2
|
|
3
3
|
module RbsInlineData
|
4
|
+
# Process executed when running the rbs-inline-data command.
|
4
5
|
class CLI
|
5
6
|
# :: (Array[String]) -> void
|
6
7
|
def run: (Array[String]) -> void
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# :: (String) -> Array[Pathname]
|
12
|
+
def get_targets: (String) -> Array[Pathname]
|
7
13
|
end
|
8
14
|
end
|
@@ -2,12 +2,22 @@
|
|
2
2
|
|
3
3
|
module RbsInlineData
|
4
4
|
class Parser < Prism::Visitor
|
5
|
+
class Comments
|
6
|
+
MARKER: ::String
|
7
|
+
|
8
|
+
# :: (Array[Prism::Comment]) -> RbsInlineData::Parser::Comments
|
9
|
+
def self.from_prism_comments: (Array[Prism::Comment]) -> RbsInlineData::Parser::Comments
|
10
|
+
end
|
11
|
+
|
5
12
|
@definitions: Array[RbsInlineData::Parser::TypedDefinition]
|
6
13
|
|
7
14
|
@surronding_class_or_module: Array[Symbol]
|
8
15
|
|
9
|
-
|
10
|
-
|
16
|
+
@comments: RbsInlineData::Parser::Comments
|
17
|
+
|
18
|
+
# rubocop:disable Lint/MissingSuper
|
19
|
+
# :: (Array[RbsInlineData::Parser::TypedDefinition], RbsInlineData::Parser::Comments) -> void
|
20
|
+
def initialize: (Array[RbsInlineData::Parser::TypedDefinition], RbsInlineData::Parser::Comments) -> void
|
11
21
|
|
12
22
|
# :: (Prism::ParseResult) -> Array[RbsInlineData::Parser::TypedDefinition]
|
13
23
|
def self.parse: (Prism::ParseResult) -> Array[RbsInlineData::Parser::TypedDefinition]
|
@@ -31,5 +41,8 @@ module RbsInlineData
|
|
31
41
|
|
32
42
|
# :: (Prism::ConstantWriteNode) -> RbsInlineData::Parser::TypedDefinition?
|
33
43
|
def extract_definition: (Prism::ConstantWriteNode) -> RbsInlineData::Parser::TypedDefinition?
|
44
|
+
|
45
|
+
# :: (Prism::SymbolNode) -> String
|
46
|
+
def type_of: (Prism::SymbolNode) -> String
|
34
47
|
end
|
35
48
|
end
|
data/sig/patch.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs_inline_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Teppei Shintani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prism
|
@@ -73,6 +73,7 @@ metadata:
|
|
73
73
|
homepage_uri: https://github.com/euglena1215/rbs_inline_data
|
74
74
|
source_code_uri: https://github.com/euglena1215/rbs_inline_data
|
75
75
|
changelog_uri: https://github.com/euglena1215/rbs_inline_data/blob/main/CHANGELOG.md
|
76
|
+
rubygems_mfa_required: 'true'
|
76
77
|
post_install_message:
|
77
78
|
rdoc_options: []
|
78
79
|
require_paths:
|