t-ruby 0.0.34 → 0.0.36
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/README.md +71 -9
- data/lib/t_ruby/benchmark.rb +16 -16
- data/lib/t_ruby/bundler_integration.rb +33 -35
- data/lib/t_ruby/cache.rb +46 -43
- data/lib/t_ruby/cli.rb +3 -3
- data/lib/t_ruby/compiler.rb +25 -27
- data/lib/t_ruby/config.rb +15 -11
- data/lib/t_ruby/constraint_checker.rb +14 -8
- data/lib/t_ruby/declaration_generator.rb +8 -8
- data/lib/t_ruby/doc_generator.rb +33 -33
- data/lib/t_ruby/docs_badge_generator.rb +8 -8
- data/lib/t_ruby/docs_example_verifier.rb +5 -6
- data/lib/t_ruby/error_handler.rb +21 -22
- data/lib/t_ruby/generic_type_parser.rb +3 -3
- data/lib/t_ruby/intersection_type_parser.rb +2 -2
- data/lib/t_ruby/ir.rb +21 -24
- data/lib/t_ruby/lsp_server.rb +128 -138
- data/lib/t_ruby/package_manager.rb +16 -18
- data/lib/t_ruby/parser.rb +7 -7
- data/lib/t_ruby/parser_combinator.rb +22 -22
- data/lib/t_ruby/rbs_generator.rb +2 -4
- data/lib/t_ruby/runtime_validator.rb +41 -37
- data/lib/t_ruby/smt_solver.rb +31 -29
- data/lib/t_ruby/type_alias_registry.rb +1 -0
- data/lib/t_ruby/type_checker.rb +64 -63
- data/lib/t_ruby/type_erasure.rb +2 -4
- data/lib/t_ruby/type_inferencer.rb +22 -26
- data/lib/t_ruby/union_type_parser.rb +3 -3
- data/lib/t_ruby/version.rb +1 -1
- data/lib/t_ruby/watcher.rb +18 -14
- metadata +4 -3
data/lib/t_ruby/compiler.rb
CHANGED
|
@@ -42,7 +42,7 @@ module TRuby
|
|
|
42
42
|
FileUtils.mkdir_p(out_dir)
|
|
43
43
|
|
|
44
44
|
base_filename = File.basename(input_path, ".trb")
|
|
45
|
-
output_path = File.join(out_dir, base_filename
|
|
45
|
+
output_path = File.join(out_dir, "#{base_filename}.rb")
|
|
46
46
|
|
|
47
47
|
File.write(output_path, output)
|
|
48
48
|
|
|
@@ -98,19 +98,19 @@ module TRuby
|
|
|
98
98
|
{
|
|
99
99
|
ruby: ruby_output,
|
|
100
100
|
rbs: rbs_output,
|
|
101
|
-
errors: []
|
|
101
|
+
errors: [],
|
|
102
102
|
}
|
|
103
103
|
rescue ParseError => e
|
|
104
104
|
{
|
|
105
105
|
ruby: "",
|
|
106
106
|
rbs: "",
|
|
107
|
-
errors: [e.message]
|
|
107
|
+
errors: [e.message],
|
|
108
108
|
}
|
|
109
109
|
rescue StandardError => e
|
|
110
110
|
{
|
|
111
111
|
ruby: "",
|
|
112
112
|
rbs: "",
|
|
113
|
-
errors: ["Compilation error: #{e.message}"]
|
|
113
|
+
errors: ["Compilation error: #{e.message}"],
|
|
114
114
|
}
|
|
115
115
|
end
|
|
116
116
|
|
|
@@ -202,7 +202,7 @@ module TRuby
|
|
|
202
202
|
generator = IR::RBSGenerator.new
|
|
203
203
|
rbs_content = generator.generate(ir_program)
|
|
204
204
|
|
|
205
|
-
rbs_path = File.join(out_dir, base_filename
|
|
205
|
+
rbs_path = File.join(out_dir, "#{base_filename}.rbs")
|
|
206
206
|
File.write(rbs_path, rbs_content) unless rbs_content.strip.empty?
|
|
207
207
|
end
|
|
208
208
|
|
|
@@ -214,7 +214,7 @@ module TRuby
|
|
|
214
214
|
parse_result[:type_aliases] || []
|
|
215
215
|
)
|
|
216
216
|
|
|
217
|
-
rbs_path = File.join(out_dir, base_filename
|
|
217
|
+
rbs_path = File.join(out_dir, "#{base_filename}.rbs")
|
|
218
218
|
File.write(rbs_path, rbs_content) unless rbs_content.empty?
|
|
219
219
|
end
|
|
220
220
|
|
|
@@ -233,7 +233,7 @@ module TRuby
|
|
|
233
233
|
FileUtils.mkdir_p(out_dir)
|
|
234
234
|
|
|
235
235
|
base_filename = File.basename(input_path, ".rb")
|
|
236
|
-
output_path = File.join(out_dir, base_filename
|
|
236
|
+
output_path = File.join(out_dir, "#{base_filename}.rb")
|
|
237
237
|
|
|
238
238
|
# Copy the .rb file to output directory
|
|
239
239
|
FileUtils.cp(input_path, output_path)
|
|
@@ -250,7 +250,7 @@ module TRuby
|
|
|
250
250
|
|
|
251
251
|
# Generate RBS from Ruby file using rbs prototype
|
|
252
252
|
def generate_rbs_from_ruby(base_filename, out_dir, input_path)
|
|
253
|
-
rbs_path = File.join(out_dir, base_filename
|
|
253
|
+
rbs_path = File.join(out_dir, "#{base_filename}.rbs")
|
|
254
254
|
result = `rbs prototype rb #{input_path} 2>/dev/null`
|
|
255
255
|
File.write(rbs_path, result) unless result.strip.empty?
|
|
256
256
|
end
|
|
@@ -273,20 +273,20 @@ module TRuby
|
|
|
273
273
|
result = source.dup
|
|
274
274
|
|
|
275
275
|
# Collect type alias names to remove
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
program.declarations
|
|
277
|
+
.select { |d| d.is_a?(IR::TypeAlias) }
|
|
278
|
+
.map(&:name)
|
|
279
279
|
|
|
280
280
|
# Collect interface names to remove
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
program.declarations
|
|
282
|
+
.select { |d| d.is_a?(IR::Interface) }
|
|
283
|
+
.map(&:name)
|
|
284
284
|
|
|
285
285
|
# Remove type alias definitions
|
|
286
|
-
result = result.gsub(/^\s*type\s+\w+\s*=\s*.+?$\n?/,
|
|
286
|
+
result = result.gsub(/^\s*type\s+\w+\s*=\s*.+?$\n?/, "")
|
|
287
287
|
|
|
288
288
|
# Remove interface definitions (multi-line)
|
|
289
|
-
result = result.gsub(/^\s*interface\s+\w+.*?^\s*end\s*$/m,
|
|
289
|
+
result = result.gsub(/^\s*interface\s+\w+.*?^\s*end\s*$/m, "")
|
|
290
290
|
|
|
291
291
|
# Remove parameter type annotations using IR info
|
|
292
292
|
# Enhanced: Handle complex types (generics, unions, etc.)
|
|
@@ -296,9 +296,7 @@ module TRuby
|
|
|
296
296
|
result = erase_return_types(result)
|
|
297
297
|
|
|
298
298
|
# Clean up extra blank lines
|
|
299
|
-
result
|
|
300
|
-
|
|
301
|
-
result
|
|
299
|
+
result.gsub(/\n{3,}/, "\n\n")
|
|
302
300
|
end
|
|
303
301
|
|
|
304
302
|
private
|
|
@@ -308,11 +306,11 @@ module TRuby
|
|
|
308
306
|
result = source.dup
|
|
309
307
|
|
|
310
308
|
# Match function definitions and remove type annotations from parameters
|
|
311
|
-
result.gsub!(/^(\s*def\s+\w+\s*\()([^)]+)(\)\s*)(?::\s*[^\n]+)?(\s*$)/) do |
|
|
312
|
-
indent =
|
|
313
|
-
params =
|
|
314
|
-
close_paren =
|
|
315
|
-
ending =
|
|
309
|
+
result.gsub!(/^(\s*def\s+\w+\s*\()([^)]+)(\)\s*)(?::\s*[^\n]+)?(\s*$)/) do |_match|
|
|
310
|
+
indent = ::Regexp.last_match(1)
|
|
311
|
+
params = ::Regexp.last_match(2)
|
|
312
|
+
close_paren = ::Regexp.last_match(3)
|
|
313
|
+
ending = ::Regexp.last_match(4)
|
|
316
314
|
|
|
317
315
|
# Remove type annotations from each parameter
|
|
318
316
|
cleaned_params = remove_param_types(params)
|
|
@@ -340,7 +338,7 @@ module TRuby
|
|
|
340
338
|
depth -= 1
|
|
341
339
|
current += char
|
|
342
340
|
when ","
|
|
343
|
-
if depth
|
|
341
|
+
if depth.zero?
|
|
344
342
|
params << clean_param(current.strip)
|
|
345
343
|
current = ""
|
|
346
344
|
else
|
|
@@ -358,7 +356,7 @@ module TRuby
|
|
|
358
356
|
# Clean a single parameter (remove type annotation)
|
|
359
357
|
def clean_param(param)
|
|
360
358
|
# Match: name: Type or name
|
|
361
|
-
if match = param.match(/^(\w+)\s*:/)
|
|
359
|
+
if (match = param.match(/^(\w+)\s*:/))
|
|
362
360
|
match[1]
|
|
363
361
|
else
|
|
364
362
|
param
|
|
@@ -370,7 +368,7 @@ module TRuby
|
|
|
370
368
|
result = source.dup
|
|
371
369
|
|
|
372
370
|
# Remove return type: ): Type or ): Type<Foo> etc.
|
|
373
|
-
result.gsub!(/\)\s*:\s*[^\n]+?(?=\s*$)/m) do |
|
|
371
|
+
result.gsub!(/\)\s*:\s*[^\n]+?(?=\s*$)/m) do |_match|
|
|
374
372
|
")"
|
|
375
373
|
end
|
|
376
374
|
|
data/lib/t_ruby/config.rb
CHANGED
|
@@ -14,13 +14,13 @@ module TRuby
|
|
|
14
14
|
"source" => {
|
|
15
15
|
"include" => ["src"],
|
|
16
16
|
"exclude" => [],
|
|
17
|
-
"extensions" => [".trb"]
|
|
17
|
+
"extensions" => [".trb"],
|
|
18
18
|
},
|
|
19
19
|
"output" => {
|
|
20
20
|
"ruby_dir" => "build",
|
|
21
21
|
"rbs_dir" => nil,
|
|
22
22
|
"preserve_structure" => true,
|
|
23
|
-
"clean_before_build" => false
|
|
23
|
+
"clean_before_build" => false,
|
|
24
24
|
},
|
|
25
25
|
"compiler" => {
|
|
26
26
|
"strictness" => "standard",
|
|
@@ -30,15 +30,15 @@ module TRuby
|
|
|
30
30
|
"checks" => {
|
|
31
31
|
"no_implicit_any" => false,
|
|
32
32
|
"no_unused_vars" => false,
|
|
33
|
-
"strict_nil" => false
|
|
34
|
-
}
|
|
33
|
+
"strict_nil" => false,
|
|
34
|
+
},
|
|
35
35
|
},
|
|
36
36
|
"watch" => {
|
|
37
37
|
"paths" => [],
|
|
38
38
|
"debounce" => 100,
|
|
39
39
|
"clear_screen" => false,
|
|
40
|
-
"on_success" => nil
|
|
41
|
-
}
|
|
40
|
+
"on_success" => nil,
|
|
41
|
+
},
|
|
42
42
|
}.freeze
|
|
43
43
|
|
|
44
44
|
# Legacy keys for migration detection
|
|
@@ -249,7 +249,7 @@ module TRuby
|
|
|
249
249
|
value = strictness
|
|
250
250
|
return if VALID_STRICTNESS.include?(value)
|
|
251
251
|
|
|
252
|
-
raise ConfigError, "Invalid compiler.strictness: '#{value}'. Must be one of: #{VALID_STRICTNESS.join(
|
|
252
|
+
raise ConfigError, "Invalid compiler.strictness: '#{value}'. Must be one of: #{VALID_STRICTNESS.join(", ")}"
|
|
253
253
|
end
|
|
254
254
|
|
|
255
255
|
def load_raw_config(config_path)
|
|
@@ -308,8 +308,8 @@ module TRuby
|
|
|
308
308
|
result = deep_dup(DEFAULT_CONFIG)
|
|
309
309
|
|
|
310
310
|
# Migrate emit -> compiler.generate_rbs
|
|
311
|
-
if raw_config["emit"]
|
|
312
|
-
result["compiler"]["generate_rbs"] = raw_config["emit"]["rbs"]
|
|
311
|
+
if raw_config["emit"]&.key?("rbs")
|
|
312
|
+
result["compiler"]["generate_rbs"] = raw_config["emit"]["rbs"]
|
|
313
313
|
end
|
|
314
314
|
|
|
315
315
|
# Migrate paths -> source.include and output.ruby_dir
|
|
@@ -344,8 +344,12 @@ module TRuby
|
|
|
344
344
|
end
|
|
345
345
|
|
|
346
346
|
def deep_dup(hash)
|
|
347
|
-
hash.
|
|
348
|
-
|
|
347
|
+
hash.transform_values do |value|
|
|
348
|
+
if value.is_a?(Hash)
|
|
349
|
+
deep_dup(value)
|
|
350
|
+
else
|
|
351
|
+
(value.is_a?(Array) ? value.dup : value)
|
|
352
|
+
end
|
|
349
353
|
end
|
|
350
354
|
end
|
|
351
355
|
|
|
@@ -42,7 +42,7 @@ module TRuby
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def satisfied?(value_type)
|
|
45
|
-
@left_type
|
|
45
|
+
[@left_type, @right_type].include?(value_type)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -62,6 +62,7 @@ module TRuby
|
|
|
62
62
|
return false unless value.is_a?(Numeric)
|
|
63
63
|
return false if @min && value < @min
|
|
64
64
|
return false if @max && value > @max
|
|
65
|
+
|
|
65
66
|
true
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -78,6 +79,7 @@ module TRuby
|
|
|
78
79
|
return "#{@min}..#{@max}" if @min && @max
|
|
79
80
|
return ">= #{@min}" if @min
|
|
80
81
|
return "<= #{@max}" if @max
|
|
82
|
+
|
|
81
83
|
""
|
|
82
84
|
end
|
|
83
85
|
end
|
|
@@ -94,6 +96,7 @@ module TRuby
|
|
|
94
96
|
|
|
95
97
|
def satisfied?(value)
|
|
96
98
|
return false unless value.is_a?(String)
|
|
99
|
+
|
|
97
100
|
@pattern.match?(value)
|
|
98
101
|
end
|
|
99
102
|
|
|
@@ -145,10 +148,12 @@ module TRuby
|
|
|
145
148
|
|
|
146
149
|
def satisfied?(value)
|
|
147
150
|
return false unless value.respond_to?(:length)
|
|
151
|
+
|
|
148
152
|
len = value.length
|
|
149
153
|
return len == @exact_length if @exact_length
|
|
150
154
|
return false if @min_length && len < @min_length
|
|
151
155
|
return false if @max_length && len > @max_length
|
|
156
|
+
|
|
152
157
|
true
|
|
153
158
|
end
|
|
154
159
|
|
|
@@ -167,6 +172,7 @@ module TRuby
|
|
|
167
172
|
|
|
168
173
|
def build_condition
|
|
169
174
|
return "length == #{@exact_length}" if @exact_length
|
|
175
|
+
|
|
170
176
|
parts = []
|
|
171
177
|
parts << "length >= #{@min_length}" if @min_length
|
|
172
178
|
parts << "length <= #{@max_length}" if @max_length
|
|
@@ -187,7 +193,7 @@ module TRuby
|
|
|
187
193
|
def register(name, base_type:, constraints: [])
|
|
188
194
|
@constraints[name] = {
|
|
189
195
|
base_type: base_type,
|
|
190
|
-
constraints: constraints
|
|
196
|
+
constraints: constraints,
|
|
191
197
|
}
|
|
192
198
|
end
|
|
193
199
|
|
|
@@ -213,7 +219,7 @@ module TRuby
|
|
|
213
219
|
return {
|
|
214
220
|
name: name,
|
|
215
221
|
base_type: base_type,
|
|
216
|
-
constraints: [BoundsConstraint.new(subtype: name, supertype: base_type)]
|
|
222
|
+
constraints: [BoundsConstraint.new(subtype: name, supertype: base_type)],
|
|
217
223
|
}
|
|
218
224
|
end
|
|
219
225
|
|
|
@@ -325,8 +331,8 @@ module TRuby
|
|
|
325
331
|
end
|
|
326
332
|
|
|
327
333
|
# Pattern: /regex/
|
|
328
|
-
if condition.match?(
|
|
329
|
-
match = condition.match(
|
|
334
|
+
if condition.match?(%r{^/(.+)/$})
|
|
335
|
+
match = condition.match(%r{^/(.+)/$})
|
|
330
336
|
constraints << PatternConstraint.new(base_type: base_type, pattern: match[1])
|
|
331
337
|
end
|
|
332
338
|
|
|
@@ -353,7 +359,7 @@ module TRuby
|
|
|
353
359
|
# Predicate: positive?, negative?, empty?, etc.
|
|
354
360
|
if condition.match?(/^(\w+)\?$/)
|
|
355
361
|
match = condition.match(/^(\w+)\?$/)
|
|
356
|
-
constraints << PredicateConstraint.new(base_type: base_type, predicate: "#{match[1]}?"
|
|
362
|
+
constraints << PredicateConstraint.new(base_type: base_type, predicate: :"#{match[1]}?")
|
|
357
363
|
end
|
|
358
364
|
|
|
359
365
|
constraints
|
|
@@ -367,7 +373,7 @@ module TRuby
|
|
|
367
373
|
when "Numeric" then value.is_a?(Numeric)
|
|
368
374
|
when "Array" then value.is_a?(Array)
|
|
369
375
|
when "Hash" then value.is_a?(Hash)
|
|
370
|
-
when "Boolean" then
|
|
376
|
+
when "Boolean" then [true, false].include?(value)
|
|
371
377
|
when "Symbol" then value.is_a?(Symbol)
|
|
372
378
|
else true # Unknown types pass through
|
|
373
379
|
end
|
|
@@ -388,7 +394,7 @@ module TRuby
|
|
|
388
394
|
@types[name] = {
|
|
389
395
|
base_type: base_type,
|
|
390
396
|
constraints: constraints,
|
|
391
|
-
defined_at: caller_locations(1, 1).first
|
|
397
|
+
defined_at: caller_locations(1, 1).first,
|
|
392
398
|
}
|
|
393
399
|
@checker.register(name, base_type: base_type, constraints: constraints)
|
|
394
400
|
end
|
|
@@ -195,7 +195,7 @@ module TRuby
|
|
|
195
195
|
{
|
|
196
196
|
type_aliases: @type_aliases,
|
|
197
197
|
interfaces: @interfaces,
|
|
198
|
-
functions: @functions
|
|
198
|
+
functions: @functions,
|
|
199
199
|
}
|
|
200
200
|
end
|
|
201
201
|
|
|
@@ -230,13 +230,13 @@ module TRuby
|
|
|
230
230
|
|
|
231
231
|
@search_paths.each do |path|
|
|
232
232
|
full_path = File.join(path, file_name)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
next unless File.exist?(full_path) && !@loaded_files.include?(full_path)
|
|
234
|
+
|
|
235
|
+
parser = DeclarationParser.new
|
|
236
|
+
parser.parse_file(full_path)
|
|
237
|
+
@loaded_declarations.merge(parser)
|
|
238
|
+
@loaded_files.add(full_path)
|
|
239
|
+
return true
|
|
240
240
|
end
|
|
241
241
|
|
|
242
242
|
false
|
data/lib/t_ruby/doc_generator.rb
CHANGED
|
@@ -14,7 +14,7 @@ module TRuby
|
|
|
14
14
|
types: {},
|
|
15
15
|
interfaces: {},
|
|
16
16
|
functions: {},
|
|
17
|
-
modules: {}
|
|
17
|
+
modules: {},
|
|
18
18
|
}
|
|
19
19
|
@parser = nil
|
|
20
20
|
end
|
|
@@ -84,7 +84,7 @@ module TRuby
|
|
|
84
84
|
md << ""
|
|
85
85
|
|
|
86
86
|
if info[:type_params]&.any?
|
|
87
|
-
md << "**Type Parameters:** `<#{info[:type_params].join(
|
|
87
|
+
md << "**Type Parameters:** `<#{info[:type_params].join(", ")}>`"
|
|
88
88
|
md << ""
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -94,7 +94,7 @@ module TRuby
|
|
|
94
94
|
md << "| Name | Type | Description |"
|
|
95
95
|
md << "|------|------|-------------|"
|
|
96
96
|
info[:members].each do |member|
|
|
97
|
-
md << "| `#{member[:name]}` | `#{member[:type]}` | #{member[:description] ||
|
|
97
|
+
md << "| `#{member[:name]}` | `#{member[:type]}` | #{member[:description] || "-"} |"
|
|
98
98
|
end
|
|
99
99
|
md << ""
|
|
100
100
|
end
|
|
@@ -114,9 +114,9 @@ module TRuby
|
|
|
114
114
|
|
|
115
115
|
# Signature
|
|
116
116
|
params = info[:params]&.map { |p| "#{p[:name]}: #{p[:type]}" }&.join(", ") || ""
|
|
117
|
-
type_params = info[:type_params]&.any? ? "<#{info[:type_params].join(
|
|
117
|
+
type_params = info[:type_params]&.any? ? "<#{info[:type_params].join(", ")}>" : ""
|
|
118
118
|
md << "```ruby"
|
|
119
|
-
md << "def #{name}#{type_params}(#{params}): #{info[:return_type] ||
|
|
119
|
+
md << "def #{name}#{type_params}(#{params}): #{info[:return_type] || "void"}"
|
|
120
120
|
md << "```"
|
|
121
121
|
md << ""
|
|
122
122
|
|
|
@@ -126,7 +126,7 @@ module TRuby
|
|
|
126
126
|
md << "| Name | Type | Description |"
|
|
127
127
|
md << "|------|------|-------------|"
|
|
128
128
|
info[:params].each do |param|
|
|
129
|
-
md << "| `#{param[:name]}` | `#{param[:type]}` | #{param[:description] ||
|
|
129
|
+
md << "| `#{param[:name]}` | `#{param[:type]}` | #{param[:description] || "-"} |"
|
|
130
130
|
end
|
|
131
131
|
md << ""
|
|
132
132
|
end
|
|
@@ -147,13 +147,13 @@ module TRuby
|
|
|
147
147
|
files.each { |file| parse_file(file) }
|
|
148
148
|
|
|
149
149
|
File.write(output_path, JSON.pretty_generate({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
generated_at: Time.now.iso8601,
|
|
151
|
+
version: TRuby::VERSION,
|
|
152
|
+
types: @docs[:types],
|
|
153
|
+
interfaces: @docs[:interfaces],
|
|
154
|
+
functions: @docs[:functions],
|
|
155
|
+
modules: @docs[:modules],
|
|
156
|
+
}))
|
|
157
157
|
|
|
158
158
|
puts "JSON documentation generated: #{output_path}"
|
|
159
159
|
end
|
|
@@ -191,7 +191,7 @@ module TRuby
|
|
|
191
191
|
type_params: type_params&.split(/\s*,\s*/),
|
|
192
192
|
definition: definition.strip,
|
|
193
193
|
description: doc_comments["type:#{name}"],
|
|
194
|
-
source: relative_path
|
|
194
|
+
source: relative_path,
|
|
195
195
|
}
|
|
196
196
|
end
|
|
197
197
|
|
|
@@ -240,11 +240,11 @@ module TRuby
|
|
|
240
240
|
content.scan(/interface\s+(\w+)(?:<([^>]+)>)?\s*\n((?:(?!^end).)*?)^end/m) do |name, type_params, body|
|
|
241
241
|
members = []
|
|
242
242
|
|
|
243
|
-
body.scan(/^\s*(\w+[
|
|
243
|
+
body.scan(/^\s*(\w+[?!]?)\s*:\s*(.+)$/) do |member_name, member_type|
|
|
244
244
|
members << {
|
|
245
245
|
name: member_name,
|
|
246
246
|
type: member_type.strip,
|
|
247
|
-
description: doc_comments["member:#{name}.#{member_name}"]
|
|
247
|
+
description: doc_comments["member:#{name}.#{member_name}"],
|
|
248
248
|
}
|
|
249
249
|
end
|
|
250
250
|
|
|
@@ -253,21 +253,21 @@ module TRuby
|
|
|
253
253
|
type_params: type_params&.split(/\s*,\s*/),
|
|
254
254
|
members: members,
|
|
255
255
|
description: doc_comments["interface:#{name}"],
|
|
256
|
-
source: source
|
|
256
|
+
source: source,
|
|
257
257
|
}
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
def parse_functions(content, source, doc_comments)
|
|
262
262
|
# Match function definitions
|
|
263
|
-
content.scan(/def\s+(\w+[
|
|
263
|
+
content.scan(/def\s+(\w+[?!]?)(?:<([^>]+)>)?\s*\(([^)]*)\)(?:\s*:\s*(.+?))?(?:\n|$)/) do |name, type_params, params_str, return_type|
|
|
264
264
|
params = []
|
|
265
265
|
|
|
266
266
|
params_str.scan(/(\w+)\s*:\s*([^,]+)/) do |param_name, param_type|
|
|
267
267
|
params << {
|
|
268
268
|
name: param_name,
|
|
269
269
|
type: param_type.strip,
|
|
270
|
-
description: doc_comments["param:#{name}.#{param_name}"]
|
|
270
|
+
description: doc_comments["param:#{name}.#{param_name}"],
|
|
271
271
|
}
|
|
272
272
|
end
|
|
273
273
|
|
|
@@ -277,7 +277,7 @@ module TRuby
|
|
|
277
277
|
params: params,
|
|
278
278
|
return_type: return_type&.strip,
|
|
279
279
|
description: doc_comments["def:#{name}"],
|
|
280
|
-
source: source
|
|
280
|
+
source: source,
|
|
281
281
|
}
|
|
282
282
|
end
|
|
283
283
|
end
|
|
@@ -360,15 +360,15 @@ module TRuby
|
|
|
360
360
|
def generate_search_index(output_dir)
|
|
361
361
|
search_data = []
|
|
362
362
|
|
|
363
|
-
@docs[:types].
|
|
363
|
+
@docs[:types].each_key do |name|
|
|
364
364
|
search_data << { type: "type", name: name, url: "types/#{name}.html" }
|
|
365
365
|
end
|
|
366
366
|
|
|
367
|
-
@docs[:interfaces].
|
|
367
|
+
@docs[:interfaces].each_key do |name|
|
|
368
368
|
search_data << { type: "interface", name: name, url: "interfaces/#{name}.html" }
|
|
369
369
|
end
|
|
370
370
|
|
|
371
|
-
@docs[:functions].
|
|
371
|
+
@docs[:functions].each_key do |name|
|
|
372
372
|
search_data << { type: "function", name: name, url: "functions/#{name}.html" }
|
|
373
373
|
end
|
|
374
374
|
|
|
@@ -392,8 +392,8 @@ module TRuby
|
|
|
392
392
|
<body>
|
|
393
393
|
<a href="../index.html">← Back to Index</a>
|
|
394
394
|
<h1>type #{name}</h1>
|
|
395
|
-
#{
|
|
396
|
-
<pre>type #{name}#{
|
|
395
|
+
#{"<p>#{info[:description]}</p>" if info[:description]}
|
|
396
|
+
<pre>type #{name}#{"<#{info[:type_params].join(", ")}>" if info[:type_params]} = #{info[:definition]}</pre>
|
|
397
397
|
<p class="meta">Source: <code>#{info[:source]}</code></p>
|
|
398
398
|
</body>
|
|
399
399
|
</html>
|
|
@@ -402,7 +402,7 @@ module TRuby
|
|
|
402
402
|
|
|
403
403
|
def generate_interface_html(name, info)
|
|
404
404
|
members_html = info[:members]&.map do |m|
|
|
405
|
-
"<tr><td><code>#{m[:name]}</code></td><td><code>#{m[:type]}</code></td><td>#{m[:description] ||
|
|
405
|
+
"<tr><td><code>#{m[:name]}</code></td><td><code>#{m[:type]}</code></td><td>#{m[:description] || "-"}</td></tr>"
|
|
406
406
|
end&.join || ""
|
|
407
407
|
|
|
408
408
|
<<~HTML
|
|
@@ -423,8 +423,8 @@ module TRuby
|
|
|
423
423
|
</head>
|
|
424
424
|
<body>
|
|
425
425
|
<a href="../index.html">← Back to Index</a>
|
|
426
|
-
<h1>interface #{name}#{
|
|
427
|
-
#{
|
|
426
|
+
<h1>interface #{name}#{"<#{info[:type_params].join(", ")}>" if info[:type_params]}</h1>
|
|
427
|
+
#{"<p>#{info[:description]}</p>" if info[:description]}
|
|
428
428
|
#{"<h2>Members</h2><table><tr><th>Name</th><th>Type</th><th>Description</th></tr>#{members_html}</table>" unless members_html.empty?}
|
|
429
429
|
<p class="meta">Source: <code>#{info[:source]}</code></p>
|
|
430
430
|
</body>
|
|
@@ -434,11 +434,11 @@ module TRuby
|
|
|
434
434
|
|
|
435
435
|
def generate_function_html(name, info)
|
|
436
436
|
params_html = info[:params]&.map do |p|
|
|
437
|
-
"<tr><td><code>#{p[:name]}</code></td><td><code>#{p[:type]}</code></td><td>#{p[:description] ||
|
|
437
|
+
"<tr><td><code>#{p[:name]}</code></td><td><code>#{p[:type]}</code></td><td>#{p[:description] || "-"}</td></tr>"
|
|
438
438
|
end&.join || ""
|
|
439
439
|
|
|
440
440
|
params_sig = info[:params]&.map { |p| "#{p[:name]}: #{p[:type]}" }&.join(", ") || ""
|
|
441
|
-
type_params = info[:type_params]&.any? ? "<#{info[:type_params].join(
|
|
441
|
+
type_params = info[:type_params]&.any? ? "<#{info[:type_params].join(", ")}>" : ""
|
|
442
442
|
|
|
443
443
|
<<~HTML
|
|
444
444
|
<!DOCTYPE html>
|
|
@@ -459,12 +459,12 @@ module TRuby
|
|
|
459
459
|
<body>
|
|
460
460
|
<a href="../index.html">← Back to Index</a>
|
|
461
461
|
<h1>#{name}</h1>
|
|
462
|
-
#{
|
|
462
|
+
#{"<p>#{info[:description]}</p>" if info[:description]}
|
|
463
463
|
<h2>Signature</h2>
|
|
464
|
-
<pre>def #{name}#{type_params}(#{params_sig}): #{info[:return_type] ||
|
|
464
|
+
<pre>def #{name}#{type_params}(#{params_sig}): #{info[:return_type] || "void"}</pre>
|
|
465
465
|
#{"<h2>Parameters</h2><table><tr><th>Name</th><th>Type</th><th>Description</th></tr>#{params_html}</table>" unless params_html.empty?}
|
|
466
466
|
<h2>Returns</h2>
|
|
467
|
-
<p><code>#{info[:return_type] ||
|
|
467
|
+
<p><code>#{info[:return_type] || "void"}</code></p>
|
|
468
468
|
<p class="meta">Source: <code>#{info[:source]}</code></p>
|
|
469
469
|
</body>
|
|
470
470
|
</html>
|
|
@@ -148,16 +148,16 @@ module TRuby
|
|
|
148
148
|
markdown += "Pass rate: #{file_summary[:pass_rate]}% (#{file_summary[:passed]}/#{file_summary[:total]})\n\n"
|
|
149
149
|
|
|
150
150
|
failed_results = file_results.select(&:fail?)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
next unless failed_results.any?
|
|
152
|
+
|
|
153
|
+
markdown += "**Failed examples:**\n\n"
|
|
154
|
+
failed_results.each do |result|
|
|
155
|
+
markdown += "- Line #{result.line_number}:\n"
|
|
156
|
+
result.errors.each do |error|
|
|
157
|
+
markdown += " - #{error}\n"
|
|
158
158
|
end
|
|
159
|
-
markdown += "\n"
|
|
160
159
|
end
|
|
160
|
+
markdown += "\n"
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
File.write(output_path, markdown)
|
|
@@ -173,12 +173,11 @@ module TRuby
|
|
|
173
173
|
|
|
174
174
|
def verify_ruby_example(example)
|
|
175
175
|
# For Ruby examples, just validate syntax
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
end
|
|
176
|
+
|
|
177
|
+
RubyVM::InstructionSequence.compile(example.code)
|
|
178
|
+
pass_result(example)
|
|
179
|
+
rescue SyntaxError => e
|
|
180
|
+
fail_result(example, ["Ruby syntax error: #{e.message}"])
|
|
182
181
|
end
|
|
183
182
|
|
|
184
183
|
def verify_rbs_example(example)
|