t-ruby 0.0.1
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/LICENSE +21 -0
- data/README.md +221 -0
- data/bin/trc +6 -0
- data/lib/t_ruby/benchmark.rb +592 -0
- data/lib/t_ruby/bundler_integration.rb +569 -0
- data/lib/t_ruby/cache.rb +774 -0
- data/lib/t_ruby/cli.rb +106 -0
- data/lib/t_ruby/compiler.rb +299 -0
- data/lib/t_ruby/config.rb +53 -0
- data/lib/t_ruby/constraint_checker.rb +441 -0
- data/lib/t_ruby/declaration_generator.rb +298 -0
- data/lib/t_ruby/doc_generator.rb +474 -0
- data/lib/t_ruby/error_handler.rb +132 -0
- data/lib/t_ruby/generic_type_parser.rb +68 -0
- data/lib/t_ruby/intersection_type_parser.rb +30 -0
- data/lib/t_ruby/ir.rb +1301 -0
- data/lib/t_ruby/lsp_server.rb +994 -0
- data/lib/t_ruby/package_manager.rb +735 -0
- data/lib/t_ruby/parser.rb +245 -0
- data/lib/t_ruby/parser_combinator.rb +942 -0
- data/lib/t_ruby/rbs_generator.rb +71 -0
- data/lib/t_ruby/runtime_validator.rb +367 -0
- data/lib/t_ruby/smt_solver.rb +1076 -0
- data/lib/t_ruby/type_alias_registry.rb +102 -0
- data/lib/t_ruby/type_checker.rb +770 -0
- data/lib/t_ruby/type_erasure.rb +26 -0
- data/lib/t_ruby/type_inferencer.rb +580 -0
- data/lib/t_ruby/union_type_parser.rb +38 -0
- data/lib/t_ruby/version.rb +5 -0
- data/lib/t_ruby/watcher.rb +320 -0
- data/lib/t_ruby.rb +42 -0
- metadata +87 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a2d09e81c109f428cb4a54a04ccc0452d250a9eff67b7b9adac4e6fac6820f42
|
|
4
|
+
data.tar.gz: 0aee866da3cc83444597f253e6fc64efad43eb06b967ab4b082acf4c70650030
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ffd79b3ed0fb4add13d728b27f3f4d0d3a222d39fdfecd73dda352bdec084a7dcc85aabc7f761565afacc73fe3eae839bd7b45a53a83c9010fb45ed10956d173
|
|
7
|
+
data.tar.gz: 6ed1a4d1f6fb88b8872f8db14b9519875689583221257f9e45ffebf35b1d4d80e17c2482d11392a1167a9cf7f1ad27535cd55cfb59476afee35e2baea2f28955
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 type-ruby
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://avatars.githubusercontent.com/u/248530250" alt="T-Ruby" height="170">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">T-Ruby</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>TypeScript-style types for Ruby</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<img src="https://img.shields.io/badge/CI-passing-brightgreen" alt="CI: passing" />
|
|
13
|
+
<img src="https://img.shields.io/badge/ruby-3.0+-cc342d" alt="Ruby 3.0+" />
|
|
14
|
+
<img src="https://img.shields.io/badge/gem-v0.1.0-blue" alt="Gem: v0.1.0" />
|
|
15
|
+
<img src="https://img.shields.io/badge/downloads-0-lightgrey" alt="Downloads" />
|
|
16
|
+
<img src="https://img.shields.io/badge/coverage-90%25-brightgreen" alt="Coverage: 90%" />
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="#install">Install</a>
|
|
21
|
+
•
|
|
22
|
+
<a href="#quick-start">Quick Start</a>
|
|
23
|
+
•
|
|
24
|
+
<a href="#features">Features</a>
|
|
25
|
+
•
|
|
26
|
+
<a href="./ROADMAP.md">Roadmap</a>
|
|
27
|
+
•
|
|
28
|
+
<a href="./README.ko.md">한국어</a>
|
|
29
|
+
•
|
|
30
|
+
<a href="./README.ja.md">日本語</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## What is T-Ruby?
|
|
36
|
+
|
|
37
|
+
T-Ruby is a typed layer for Ruby, inspired by TypeScript.
|
|
38
|
+
It ships as a single executable called `trc`.
|
|
39
|
+
|
|
40
|
+
Write `.trb` files with type annotations, compile to standard `.rb` files.
|
|
41
|
+
Types are erased at compile time — your Ruby code runs everywhere Ruby runs.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
trc hello.trb # Compile to Ruby
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The `trc` compiler also generates `.rbs` signature files for tools like
|
|
48
|
+
Steep and Ruby LSP. Gradually adopt types in existing Ruby projects
|
|
49
|
+
with zero runtime overhead.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
trc --watch src/ # Watch mode
|
|
53
|
+
trc --emit-rbs src/ # Generate .rbs files
|
|
54
|
+
trc --check src/ # Type check without compiling
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Why T-Ruby?
|
|
60
|
+
|
|
61
|
+
We are friends of Ruby — Rubyists who still use and love Ruby.
|
|
62
|
+
|
|
63
|
+
We know Ruby has duck typing and dynamic types in its DNA.
|
|
64
|
+
But we couldn't ignore that static type systems are becoming
|
|
65
|
+
essential in real-world production environments.
|
|
66
|
+
|
|
67
|
+
The Ruby ecosystem has debated this for years,
|
|
68
|
+
yet hasn't quite found its answer.
|
|
69
|
+
|
|
70
|
+
### Existing Approaches
|
|
71
|
+
|
|
72
|
+
**1) Sorbet**
|
|
73
|
+
- Types are written like comments above your code.
|
|
74
|
+
- It feels like writing JSDoc and hoping the IDE catches errors.
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
# Sorbet
|
|
78
|
+
extend T::Sig
|
|
79
|
+
|
|
80
|
+
sig { params(name: String).returns(String) }
|
|
81
|
+
def greet(name)
|
|
82
|
+
"Hello, #{name}!"
|
|
83
|
+
end
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**2) RBS**
|
|
87
|
+
- Ruby's official approach, where `.rbs` files are separate type definition files like TypeScript's `.d.ts`.
|
|
88
|
+
- But in Ruby, you have to write them manually or rely on "implicit inference + manual fixes" — still cumbersome.
|
|
89
|
+
|
|
90
|
+
```rbs
|
|
91
|
+
# greet.rbs (separate file)
|
|
92
|
+
def greet: (String name) -> String
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
# greet.rb (no type info)
|
|
97
|
+
def greet(name)
|
|
98
|
+
"Hello, #{name}!"
|
|
99
|
+
end
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### T-Ruby
|
|
103
|
+
- Like TypeScript, types live inside your code.
|
|
104
|
+
- Write `.trb`, and `trc` generates both `.rb` and `.rbs`.
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
# greet.trb
|
|
108
|
+
def greet(name: String): String
|
|
109
|
+
"Hello, #{name}!"
|
|
110
|
+
end
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
trc greet.trb
|
|
115
|
+
# => build/greet.rb
|
|
116
|
+
# + build/greet.rbs
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Others...
|
|
120
|
+
There are new languages like **Crystal**, but strictly speaking, it's a different language from Ruby.
|
|
121
|
+
|
|
122
|
+
We still love Ruby, and we want this to be
|
|
123
|
+
**progress within the Ruby ecosystem, not an escape from it.**
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Install
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# with RubyGems (recommended)
|
|
131
|
+
gem install t-ruby
|
|
132
|
+
|
|
133
|
+
# from source
|
|
134
|
+
git clone https://github.com/pyhyun/t-ruby
|
|
135
|
+
cd t-ruby && bundle install
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Verify installation
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
trc --version
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Quick start
|
|
147
|
+
|
|
148
|
+
### 1. Write `.trb`
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
# hello.trb
|
|
152
|
+
def greet(name: String): String
|
|
153
|
+
"Hello, #{name}!"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
puts greet("world")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 2. Compile
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
trc hello.trb
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 3. Run
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
ruby build/hello.rb
|
|
169
|
+
# => Hello, world!
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Features
|
|
175
|
+
|
|
176
|
+
- **Type annotations** — Parameter and return types, erased at compile time
|
|
177
|
+
- **Union types** — `String | Integer | nil`
|
|
178
|
+
- **Generics** — `Array<User>`, `Hash<String, Integer>`
|
|
179
|
+
- **Interfaces** — Define contracts between objects
|
|
180
|
+
- **Type aliases** — `type UserID = Integer`
|
|
181
|
+
- **RBS generation** — Works with Steep, Ruby LSP, Sorbet
|
|
182
|
+
- **IDE support** — VS Code, Neovim with LSP
|
|
183
|
+
- **Watch mode** — Recompile on file changes
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Quick links
|
|
188
|
+
|
|
189
|
+
**Getting Started**
|
|
190
|
+
- [VS Code Extension](./docs/vscode/en/getting-started.md)
|
|
191
|
+
- [Vim Setup](./docs/vim/en/getting-started.md)
|
|
192
|
+
- [Neovim Setup](./docs/neovim/en/getting-started.md)
|
|
193
|
+
|
|
194
|
+
**Guides**
|
|
195
|
+
- [Syntax Highlighting](./docs/syntax-highlighting/en/guide.md)
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Status
|
|
200
|
+
|
|
201
|
+
> **Experimental** — T-Ruby is under active development.
|
|
202
|
+
> APIs may change. Not recommended for production use yet.
|
|
203
|
+
|
|
204
|
+
| Milestone | Status |
|
|
205
|
+
|-----------|--------|
|
|
206
|
+
| Type Parsing & Erasure | ✅ |
|
|
207
|
+
| Core Type System | ✅ |
|
|
208
|
+
| LSP & IDE Support | ✅ |
|
|
209
|
+
| Advanced Features | ✅ |
|
|
210
|
+
|
|
211
|
+
See [ROADMAP.md](./ROADMAP.md) for details.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Contributing
|
|
216
|
+
|
|
217
|
+
Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
[MIT](./LICENSE)
|