syntax_tree-rbs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eff99e85b92644bcfc8cf94291ec8e056c30cb72723bf98e571a0ffef264fcd8
4
+ data.tar.gz: 75ee446a19c76662c34bf17e323d0e26101cbb3cb173eb6546088e96e11fa867
5
+ SHA512:
6
+ metadata.gz: 3121deff5c7b0b25889b95cecbe79ca611d140d00d6ebc52d6232696f944d882431c6d41f4b669bd4ec68f2452d1a48c18c4292d97c60d155491894886c73b11
7
+ data.tar.gz: 3a05df94b6b1be4115e39ce358b3dbba4846fd39cc592fbf5b73825e17fb7054bc0e8e9b0c8db585c85a46c75789deb16626c07cb9bcd51679b8e9b1b98cf5df
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
@@ -0,0 +1,32 @@
1
+ name: Main
2
+ on:
3
+ - push
4
+ - pull_request_target
5
+ jobs:
6
+ ci:
7
+ name: CI
8
+ runs-on: ubuntu-latest
9
+ env:
10
+ CI: true
11
+ steps:
12
+ - uses: actions/checkout@master
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ bundler-cache: true
16
+ ruby-version: '3.1'
17
+ - name: Test
18
+ run: bundle exec rake test
19
+ automerge:
20
+ name: AutoMerge
21
+ needs: ci
22
+ runs-on: ubuntu-latest
23
+ if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
24
+ steps:
25
+ - uses: actions/github-script@v3
26
+ with:
27
+ script: |
28
+ github.pulls.merge({
29
+ owner: context.payload.repository.owner.login,
30
+ repo: context.payload.repository.name,
31
+ pull_number: context.payload.pull_request.number
32
+ })
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ test.rbs
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2022-04-05
10
+
11
+ ### Added
12
+
13
+ - 🎉 Initial release! 🎉
14
+
15
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.1.0...HEAD
16
+ [0.1.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/93efc7...v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ syntax_tree-rbs (0.1.0)
5
+ rbs
6
+ syntax_tree (>= 2.0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ docile (1.4.0)
12
+ minitest (5.15.0)
13
+ rake (13.0.6)
14
+ rbs (2.3.2)
15
+ simplecov (0.21.2)
16
+ docile (~> 1.1)
17
+ simplecov-html (~> 0.11)
18
+ simplecov_json_formatter (~> 0.1)
19
+ simplecov-html (0.12.3)
20
+ simplecov_json_formatter (0.1.4)
21
+ syntax_tree (2.0.1)
22
+
23
+ PLATFORMS
24
+ x86_64-darwin-21
25
+ x86_64-linux
26
+
27
+ DEPENDENCIES
28
+ bundler
29
+ minitest
30
+ rake
31
+ simplecov
32
+ syntax_tree-rbs!
33
+
34
+ BUNDLED WITH
35
+ 2.3.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022-present Kevin Newton
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,68 @@
1
+ # SyntaxTree::RBS
2
+
3
+ [![Build Status](https://github.com/ruby-syntax-tree/syntax_tree-rbs/actions/workflows/main.yml/badge.svg)](https://github.com/ruby-syntax-tree/syntax_tree-rbs/actions/workflows/main.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/syntax_tree-rbs.svg)](https://rubygems.org/gems/syntax_tree-rbs)
5
+
6
+ [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree) support for RBS.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "syntax_tree-rbs"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install syntax_tree-rbs
23
+
24
+ ## Usage
25
+
26
+ From code:
27
+
28
+ ```ruby
29
+ require "syntax_tree/rbs"
30
+
31
+ pp SyntaxTree::RBS.parse(source) # print out the AST
32
+ puts SyntaxTree::RBS.format(source) # format the AST
33
+ ```
34
+
35
+ From the CLI:
36
+
37
+ ```sh
38
+ $ stree ast --plugins=rbs file.rbs
39
+ (root declarations=[(constant name=(type-name "Hello") type=(class-instance (type-name "World")))])
40
+ ```
41
+
42
+ or
43
+
44
+ ```sh
45
+ $ stree format --plugins=rbs file.rbs
46
+ Hello: World
47
+ ```
48
+
49
+ or
50
+
51
+ ```sh
52
+ $ stree write --plugins=rbs file.rbs
53
+ file.rbs 1ms
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ 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).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-syntax-tree/syntax_tree-rbs.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "syntax_tree/rbs"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/format ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+
6
+ $:.unshift File.expand_path("../lib", __dir__)
7
+ require "syntax_tree/rbs"
8
+
9
+ puts SyntaxTree::RBS.format(ARGF.read)
data/bin/parse ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+
6
+ $:.unshift File.expand_path("../lib", __dir__)
7
+ require "syntax_tree/rbs"
8
+
9
+ pp SyntaxTree::RBS.parse(ARGF.read)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ module AST
5
+ module Declarations
6
+ class Alias
7
+ # Prints out a type alias, which is a declaration that looks like:
8
+ # type foo = String
9
+ def format(q)
10
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
11
+ SyntaxTree::RBS::Annotations.maybe_format(q, annotations)
12
+
13
+ q.group do
14
+ q.text("type ")
15
+ name.format(q)
16
+ q.text(" =")
17
+ q.group do
18
+ q.indent do
19
+ q.breakable
20
+ type.format(q)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def pretty_print(q)
27
+ q.group(2, "(constant", ")") do
28
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
29
+ SyntaxTree::RBS::Annotations.maybe_pretty_print(q, annotations)
30
+
31
+ q.breakable
32
+ q.text("name=")
33
+ q.pp(name)
34
+
35
+ q.breakable
36
+ q.text("type=")
37
+ q.pp(type)
38
+ end
39
+ end
40
+ end
41
+
42
+ class Class
43
+ # Prints out a class declarations, which looks like:
44
+ # class Foo end
45
+ def format(q)
46
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
47
+ SyntaxTree::RBS::Annotations.maybe_format(q, annotations)
48
+
49
+ q.group do
50
+ q.text("class ")
51
+ SyntaxTree::RBS::NameAndTypeParams.new(self).format(q)
52
+
53
+ if super_class
54
+ q.text(" < ")
55
+ SyntaxTree::RBS::NameAndArgs.new(super_class).format(q)
56
+ end
57
+
58
+ q.indent do
59
+ SyntaxTree::RBS::Members.new(self).format(q)
60
+ end
61
+
62
+ q.breakable(force: true)
63
+ q.text("end")
64
+ end
65
+ end
66
+
67
+ def pretty_print(q)
68
+ q.group(2, "(class", ")") do
69
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
70
+ SyntaxTree::RBS::Annotations.maybe_pretty_print(q, annotations)
71
+
72
+ q.pp(SyntaxTree::RBS::NameAndTypeParams.new(self))
73
+
74
+ if super_class
75
+ q.breakable
76
+ q.text("super_class=")
77
+ q.group(2, "(class", ")") do
78
+ q.pp(SyntaxTree::RBS::NameAndArgs.new(super_class))
79
+ end
80
+ end
81
+
82
+ q.breakable
83
+ q.text("members=")
84
+ q.pp(members)
85
+ end
86
+ end
87
+ end
88
+
89
+ class Constant
90
+ # Prints out a constant declaration, which looks like:
91
+ # Foo: String
92
+ def format(q)
93
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
94
+
95
+ q.group do
96
+ name.format(q)
97
+ q.text(": ")
98
+ type.format(q)
99
+ end
100
+ end
101
+
102
+ def pretty_print(q)
103
+ q.group(2, "(constant", ")") do
104
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
105
+
106
+ q.breakable
107
+ q.text("name=")
108
+ q.pp(name)
109
+
110
+ q.breakable
111
+ q.text("type=")
112
+ q.pp(type)
113
+ end
114
+ end
115
+ end
116
+
117
+ class Global
118
+ # Prints out a global declaration, which looks like:
119
+ # $foo: String
120
+ def format(q)
121
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
122
+
123
+ q.group do
124
+ q.text(name)
125
+ q.text(": ")
126
+ type.format(q)
127
+ end
128
+ end
129
+
130
+ def pretty_print(q)
131
+ q.group(2, "(global", ")") do
132
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
133
+
134
+ q.breakable
135
+ q.text("name=")
136
+ q.pp(name)
137
+
138
+ q.breakable
139
+ q.text("type=")
140
+ q.pp(type)
141
+ end
142
+ end
143
+ end
144
+
145
+ class Interface
146
+ # Prints out an interface declaration, which looks like:
147
+ # interface _Foo end
148
+ def format(q)
149
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
150
+ SyntaxTree::RBS::Annotations.maybe_format(q, annotations)
151
+
152
+ q.group do
153
+ q.text("interface ")
154
+ SyntaxTree::RBS::NameAndTypeParams.new(self).format(q)
155
+ q.indent { SyntaxTree::RBS::Members.new(self).format(q) }
156
+ q.breakable(force: true)
157
+ q.text("end")
158
+ end
159
+ end
160
+
161
+ def pretty_print(q)
162
+ q.group(2, "(interface", ")") do
163
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
164
+ SyntaxTree::RBS::Annotations.maybe_pretty_print(q, annotations)
165
+
166
+ q.pp(SyntaxTree::RBS::NameAndTypeParams.new(self))
167
+
168
+ q.breakable
169
+ q.text("members=")
170
+ q.pp(members)
171
+ end
172
+ end
173
+ end
174
+
175
+ class Module
176
+ # Prints out a module declaration, which looks like:
177
+ # module Foo end
178
+ def format(q)
179
+ SyntaxTree::RBS::Comment.maybe_format(q, comment)
180
+ SyntaxTree::RBS::Annotations.maybe_format(q, annotations)
181
+
182
+ q.group do
183
+ q.text("module ")
184
+ SyntaxTree::RBS::NameAndTypeParams.new(self).format(q)
185
+
186
+ if self_types.any?
187
+ q.text(" : ")
188
+ q.seplist(self_types, -> { q.text(", ") }) do |self_type|
189
+ SyntaxTree::RBS::NameAndArgs.new(self_type).format(q)
190
+ end
191
+ end
192
+
193
+ q.indent { SyntaxTree::RBS::Members.new(self).format(q) }
194
+ q.breakable(force: true)
195
+ q.text("end")
196
+ end
197
+ end
198
+
199
+ def pretty_print(q)
200
+ q.group(2, "(module", ")") do
201
+ SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
202
+ SyntaxTree::RBS::Annotations.maybe_pretty_print(q, annotations)
203
+
204
+ q.pp(SyntaxTree::RBS::NameAndTypeParams.new(self))
205
+
206
+ if self_types.any?
207
+ q.breakable
208
+ q.text("self_types=")
209
+ q.group(2, "[", "]") do
210
+ q.seplist(self_types) do |self_type|
211
+ q.group(2, "(self-type", ")") do
212
+ q.pp(SyntaxTree::RBS::NameAndArgs.new(self_type))
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ q.breakable
219
+ q.text("members=")
220
+ q.pp(members)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end