gloss 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +41 -0
- data/.gloss.yml +1 -0
- data/Gemfile.lock +10 -8
- data/README.md +5 -7
- data/Rakefile +5 -3
- data/ext/gloss/Makefile +6 -21
- data/ext/gloss/lib/cr_ruby.cr +5 -4
- data/ext/gloss/src/gloss.cr +7 -2
- data/gloss.gemspec +4 -3
- data/lib/gloss.rb +1 -5
- data/lib/gloss/config.rb +13 -8
- data/lib/gloss/logger.rb +5 -0
- data/lib/gloss/prog_loader.rb +30 -23
- data/lib/gloss/type_checker.rb +16 -6
- data/lib/gloss/utils.rb +5 -11
- data/lib/gloss/version.rb +1 -1
- data/lib/gloss/visitor.rb +11 -3
- data/lib/gloss/watcher.rb +12 -5
- data/lib/gloss/writer.rb +3 -0
- data/logo.svg +6 -0
- data/src/lib/gloss.gl +1 -2
- data/src/lib/gloss/config.gl +13 -7
- data/src/lib/gloss/logger.gl +3 -1
- data/src/lib/gloss/prog_loader.gl +20 -13
- data/src/lib/gloss/type_checker.gl +17 -6
- data/src/lib/gloss/utils.gl +2 -5
- data/src/lib/gloss/version.gl +1 -1
- data/src/lib/gloss/visitor.gl +12 -4
- data/src/lib/gloss/watcher.gl +10 -4
- data/src/lib/gloss/writer.gl +3 -0
- metadata +26 -12
- data/.github/workflows/crystal_specs.yml +0 -26
- data/.github/workflows/ruby_specs.yml +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 622926d0bd44e5bd9b93cfa75ea54dc67d976a63c91a5a60f17c859987ee2fce
|
4
|
+
data.tar.gz: 789917be6b264be0108cb03371b797c4ebc865e01fcb7218589808ccd68bdf83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5fe3cf7f37aa5eec834b806c1f80083dde5be4b15000f18ae4807cb0d2ee5e3f378eaa271ffe3cb4d61b58feb98c3ac0586ab65da5ef2bb3df5dad1e4a02b2e
|
7
|
+
data.tar.gz: b2f55defed2e6ba5d3dec55dd7b6795a3f3ff54fa1e94532bc0bda6d91f099200d5ec40926c6c3b001a27809477016bdd8a59d24a6472419b0958647df6b5c00
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
env:
|
9
|
+
ImageOS: ubuntu18
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
container:
|
14
|
+
image: johansenja/gloss:latest
|
15
|
+
steps:
|
16
|
+
- name: Checkout
|
17
|
+
uses: actions/checkout@v2
|
18
|
+
- uses: actions/cache@v2
|
19
|
+
id: gems-cache
|
20
|
+
with:
|
21
|
+
path: vendor/bundle
|
22
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
23
|
+
restore-keys: |
|
24
|
+
${{ runner.os }}-gems-
|
25
|
+
- name: install Bundler
|
26
|
+
run: gem install bundler:2.2.3
|
27
|
+
- name: install gems
|
28
|
+
run: bundle install --jobs 4 --retry 3
|
29
|
+
- name: Compile extension
|
30
|
+
run: make
|
31
|
+
working-directory: ext/gloss
|
32
|
+
- name: Run tests
|
33
|
+
run: rake
|
34
|
+
- name: Install dependencies
|
35
|
+
run: shards install
|
36
|
+
working-directory: ext/gloss
|
37
|
+
- name: Run tests
|
38
|
+
run: crystal spec
|
39
|
+
working-directory: ext/gloss
|
40
|
+
- name: Build self with current state
|
41
|
+
run: exe/gloss build
|
data/.gloss.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gloss (0.1.
|
4
|
+
gloss (0.1.5)
|
5
5
|
fast_blank
|
6
6
|
listen
|
7
|
-
rbs
|
8
|
-
steep
|
7
|
+
rbs (= 1.0.4)
|
8
|
+
steep (= 0.41.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.1.
|
13
|
+
activesupport (6.1.3)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
17
17
|
tzinfo (~> 2.0)
|
18
18
|
zeitwerk (~> 2.3)
|
19
|
-
ast (2.4.
|
19
|
+
ast (2.4.2)
|
20
20
|
ast_utils (0.4.0)
|
21
21
|
parser (>= 2.7.0)
|
22
22
|
byebug (11.1.3)
|
@@ -24,15 +24,15 @@ GEM
|
|
24
24
|
concurrent-ruby (1.1.8)
|
25
25
|
diff-lcs (1.4.4)
|
26
26
|
fast_blank (1.0.0)
|
27
|
-
ffi (1.
|
28
|
-
i18n (1.8.
|
27
|
+
ffi (1.15.0)
|
28
|
+
i18n (1.8.9)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
language_server-protocol (3.15.0.1)
|
31
31
|
listen (3.4.1)
|
32
32
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
33
33
|
rb-inotify (~> 0.9, >= 0.9.10)
|
34
34
|
method_source (1.0.0)
|
35
|
-
minitest (5.14.
|
35
|
+
minitest (5.14.4)
|
36
36
|
parallel (1.20.1)
|
37
37
|
parser (2.7.2.0)
|
38
38
|
ast (~> 2.4.1)
|
@@ -77,6 +77,7 @@ GEM
|
|
77
77
|
rubocop-ast (1.4.0)
|
78
78
|
parser (>= 2.7.1.5)
|
79
79
|
ruby-progressbar (1.11.0)
|
80
|
+
rufo (0.12.0)
|
80
81
|
steep (0.41.0)
|
81
82
|
activesupport (>= 5.1)
|
82
83
|
ast_utils (>= 0.4.0)
|
@@ -99,6 +100,7 @@ DEPENDENCIES
|
|
99
100
|
rake-compiler
|
100
101
|
rspec
|
101
102
|
rubocop
|
103
|
+
rufo
|
102
104
|
|
103
105
|
BUNDLED WITH
|
104
106
|
2.2.3
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
# Gloss
|
1
|
+
# ![Gloss](./logo.svg "Gloss")
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/gloss.svg)](https://rubygems.org/gems/gloss)
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&metric=true&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
|
3
|
+
[![Tests](https://github.com/johansenja/gloss/workflows/Tests/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3ATests)
|
4
|
+
[![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
|
6
5
|
[![Current Version](http://ruby-gem-downloads-badge.herokuapp.com/gloss?color=green&label=downloads%20(current%20version)&metric=true)](https://rubygems.org/gems/gloss)
|
7
|
-
[![Total Views](https://counter.gofiber.io/badge/johansenja/gloss)](https://rubygems.org/gems/gloss)
|
8
6
|
|
9
7
|
[Gloss](https://en.wikipedia.org/wiki/Gloss_(annotation)) is a high-level programming language based on [Ruby](https://github.com/ruby/ruby) and [Crystal](https://github.com/crystal-lang/crystal), which compiles to ruby; its aims are on transparency,
|
10
8
|
efficiency, and to enhance ruby's goal of developer happiness and productivity.
|
@@ -137,7 +135,7 @@ class Language
|
|
137
135
|
TS = "TypeScript"
|
138
136
|
P = "Python"
|
139
137
|
end
|
140
|
-
|
138
|
+
|
141
139
|
def favourite_language(language : Lang)
|
142
140
|
puts "my favourite language is #{language}"
|
143
141
|
end
|
@@ -213,7 +211,7 @@ end
|
|
213
211
|
```crystal
|
214
212
|
abstract class BaseClass
|
215
213
|
attr_reader :var
|
216
|
-
|
214
|
+
|
217
215
|
def initialize(@var); end
|
218
216
|
end
|
219
217
|
|
data/Rakefile
CHANGED
@@ -17,8 +17,10 @@ RSpec::Core::RakeTask.new :spec do |spec|
|
|
17
17
|
spec.pattern = 'spec/**/*_spec.rb'
|
18
18
|
end
|
19
19
|
|
20
|
-
task :
|
21
|
-
|
20
|
+
task :build_gem do
|
21
|
+
sh "cd", "ext/gloss", "&&", "make", "all", "&&", "cd", "-"
|
22
22
|
end
|
23
23
|
|
24
|
-
task :
|
24
|
+
task build: [:build_gem]
|
25
|
+
|
26
|
+
task default: [:spec]
|
data/ext/gloss/Makefile
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
CRYSTAL = crystal
|
2
|
-
TARGET = ../../lib/gls
|
3
|
-
|
4
2
|
PLATFORM = $(shell uname -s)
|
5
3
|
|
6
4
|
ifeq "$(PLATFORM)" "Darwin"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
shards:
|
12
|
-
shards
|
13
|
-
|
14
|
-
build: ./src/gloss.cr
|
15
|
-
$(CRYSTAL) build --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" $< -o $(TARGET).bundle
|
16
|
-
|
17
|
-
clean:
|
18
|
-
rm -f $(TARGET).bundle
|
19
|
-
rm -f $(TARGET).bundle.dwarf
|
5
|
+
TARGET = ../../lib/gls.bundle
|
6
|
+
else
|
7
|
+
TARGET = ../../lib/gls.so
|
20
8
|
endif
|
21
9
|
|
22
|
-
ifeq "$(PLATFORM)" "Linux"
|
23
|
-
LLVM_TARGET = "$(shell uname -m)-unknown-linux-gnu"
|
24
10
|
install: all
|
25
11
|
|
26
12
|
all: clean shards build
|
@@ -29,9 +15,8 @@ shards:
|
|
29
15
|
shards
|
30
16
|
|
31
17
|
build: ./src/gloss.cr
|
32
|
-
$(CRYSTAL) build
|
18
|
+
$(CRYSTAL) build --link-flags "-shared -Wl,-undefined,dynamic_lookup" $< -o $(TARGET) --release
|
33
19
|
|
34
20
|
clean:
|
35
|
-
rm -f $(TARGET)
|
36
|
-
rm -f $(TARGET).
|
37
|
-
endif
|
21
|
+
rm -f $(TARGET)
|
22
|
+
rm -f $(TARGET).dwarf
|
data/ext/gloss/lib/cr_ruby.cr
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
lib CrRuby
|
2
2
|
# every ruby Object is a VALUE
|
3
3
|
type VALUE = Void*
|
4
|
-
# ruby method typing
|
5
|
-
type METHOD_FUNC = VALUE, VALUE -> VALUE
|
6
4
|
|
7
5
|
# a ruby Class is a VALUE
|
8
6
|
$rb_cObject : VALUE
|
@@ -28,8 +26,11 @@ lib CrRuby
|
|
28
26
|
fun rb_define_module(name: UInt8*) : VALUE
|
29
27
|
|
30
28
|
# define ruby method in C
|
31
|
-
fun rb_define_method(klass: VALUE, name: UInt8*, func:
|
29
|
+
fun rb_define_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE, CrRuby::VALUE,
|
30
|
+
CrRuby::VALUE), argc: Int32)
|
32
31
|
|
33
32
|
# define singleton ruby method in C
|
34
|
-
fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func:
|
33
|
+
fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE,
|
34
|
+
CrRuby::VALUE,
|
35
|
+
CrRuby::VALUE), argc: Int32)
|
35
36
|
end
|
data/ext/gloss/src/gloss.cr
CHANGED
@@ -4,7 +4,7 @@ require "./cr_ast"
|
|
4
4
|
require "./rb_ast"
|
5
5
|
require "./parser"
|
6
6
|
|
7
|
-
def parse_string(
|
7
|
+
def parse_string(_self : CrRuby::VALUE, str : CrRuby::VALUE)
|
8
8
|
st = CrRuby.rb_str_to_str(str)
|
9
9
|
string = String.new(CrRuby.rb_string_value_cstr(pointerof(st)))
|
10
10
|
|
@@ -21,5 +21,10 @@ fun init = Init_gls
|
|
21
21
|
GC.init
|
22
22
|
LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null)
|
23
23
|
gloss = CrRuby.rb_define_module("Gloss");
|
24
|
-
CrRuby.rb_define_singleton_method(
|
24
|
+
CrRuby.rb_define_singleton_method(
|
25
|
+
gloss,
|
26
|
+
"parse_buffer",
|
27
|
+
->parse_string(CrRuby::VALUE, CrRuby::VALUE),
|
28
|
+
1
|
29
|
+
);
|
25
30
|
end
|
data/gloss.gemspec
CHANGED
@@ -17,11 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_runtime_dependency "fast_blank"
|
19
19
|
s.add_runtime_dependency "listen"
|
20
|
-
s.add_runtime_dependency "rbs"
|
21
|
-
s.add_runtime_dependency "steep"
|
20
|
+
s.add_runtime_dependency "rbs", "1.0.4"
|
21
|
+
s.add_runtime_dependency "steep", "0.41.0"
|
22
22
|
|
23
|
+
s.add_development_dependency "pry-byebug"
|
23
24
|
s.add_development_dependency "rake-compiler"
|
24
25
|
s.add_development_dependency "rspec"
|
25
|
-
s.add_development_dependency "pry-byebug"
|
26
26
|
s.add_development_dependency "rubocop"
|
27
|
+
s.add_development_dependency "rufo"
|
27
28
|
end
|
data/lib/gloss.rb
CHANGED
@@ -22,11 +22,7 @@ require "gloss/errors"
|
|
22
22
|
require "gloss/logger"
|
23
23
|
require "gloss/prog_loader"
|
24
24
|
require "gloss/utils"
|
25
|
-
|
26
|
-
false}
|
27
|
-
unless is_ci
|
28
|
-
require "gls"
|
29
|
-
end
|
25
|
+
require "gls"
|
30
26
|
EMPTY_ARRAY = Array.new
|
31
27
|
.freeze
|
32
28
|
EMPTY_HASH = {}.freeze
|
data/lib/gloss/config.rb
CHANGED
@@ -10,14 +10,19 @@ module Gloss
|
|
10
10
|
Config = OpenStruct.new(default_config: {:frozen_string_literals => true,
|
11
11
|
:src_dir => "src",
|
12
12
|
:entrypoint => nil,
|
13
|
-
:strict_require => false
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
:strict_require => false,
|
14
|
+
:type_checking_strictness => "strict",
|
15
|
+
:prettify_output_executable_path => nil}.freeze)
|
16
|
+
def self.load_config()
|
17
|
+
user_config = (if File.exist?(File.absolute_path(File.join(Dir.pwd, CONFIG_PATH)))
|
18
|
+
YAML.safe_load(File.read(CONFIG_PATH))
|
19
|
+
else
|
20
|
+
Config.default_config
|
21
|
+
end)
|
17
22
|
Config.default_config
|
18
|
-
end)
|
19
|
-
Config.default_config
|
20
23
|
.each() { |k, v|
|
21
|
-
|
22
|
-
|
24
|
+
Config.send(:"#{k}=", user_config.[](k.to_s) || v)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
load_config
|
23
28
|
end
|
data/lib/gloss/logger.rb
CHANGED
data/lib/gloss/prog_loader.rb
CHANGED
@@ -7,6 +7,7 @@ require "rubygems/gem_runner"
|
|
7
7
|
module Gloss
|
8
8
|
OUTPUT_BY_PATH = Hash.new
|
9
9
|
class ProgLoader
|
10
|
+
attr_reader(:"type_checker")
|
10
11
|
def initialize()
|
11
12
|
entrypoint = Config.entrypoint
|
12
13
|
(if entrypoint.==(nil) || entrypoint.==("")
|
@@ -18,25 +19,31 @@ module Gloss
|
|
18
19
|
end
|
19
20
|
def run()
|
20
21
|
@files_to_process.each() { |path_string|
|
21
|
-
|
22
|
-
|
22
|
+
(if path_string.end_with?(".rbs")
|
23
|
+
@type_checker.load_sig_path(path_string)
|
24
|
+
else
|
25
|
+
(if !@processed_files.member?(path_string) || !OUTPUT_BY_PATH.[](path_string)
|
26
|
+
Gloss.logger
|
23
27
|
.debug("Loading #{path_string}")
|
24
|
-
|
25
|
-
|
28
|
+
path = Utils.absolute_path(path_string)
|
29
|
+
file_contents = File.open(path)
|
26
30
|
.read
|
27
|
-
|
31
|
+
contents_tree = Parser.new(file_contents)
|
28
32
|
.run
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
on_new_file_referenced = proc() { |ps, relative|
|
34
|
+
ps.each() { |pa|
|
35
|
+
(if relative
|
36
|
+
handle_require_relative(pa, path_string)
|
37
|
+
else
|
38
|
+
handle_require(pa)
|
39
|
+
end)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
OUTPUT_BY_PATH.[]=(path_string, Visitor.new(contents_tree, @type_checker, on_new_file_referenced)
|
37
43
|
.run)
|
38
|
-
|
39
|
-
|
44
|
+
@processed_files.add(path_string)
|
45
|
+
end)
|
46
|
+
end)
|
40
47
|
}
|
41
48
|
@type_checker
|
42
49
|
end
|
@@ -60,7 +67,7 @@ return
|
|
60
67
|
pathn = Pathname.new("#{File.join(Dir.pwd, "sig", path)}.rbs")
|
61
68
|
gem_path = Utils.gem_path_for(path)
|
62
69
|
(if gem_path
|
63
|
-
sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "
|
70
|
+
sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "sig", "**", "*.rbs")))
|
64
71
|
(if sig_files.length
|
65
72
|
.positive?
|
66
73
|
sig_files.each() { |fp|
|
@@ -81,7 +88,7 @@ return
|
|
81
88
|
@type_checker.load_sig_path(pathn.to_s)
|
82
89
|
@processed_files.add(pathn.to_s)
|
83
90
|
else
|
84
|
-
rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "
|
91
|
+
rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", path))
|
85
92
|
(if Pathname.new(rbs_stdlib_dir)
|
86
93
|
.exist?
|
87
94
|
load_rbs_from_require_path(path)
|
@@ -103,12 +110,12 @@ nil }
|
|
103
110
|
end)
|
104
111
|
end)
|
105
112
|
end
|
106
|
-
private def handle_require_relative(path)
|
107
|
-
base = File.join(
|
113
|
+
private def handle_require_relative(path, source_file)
|
114
|
+
base = File.join(source_file, "..", path)
|
108
115
|
# @type var pn: String?
|
109
116
|
pn = nil
|
110
|
-
Gem.suffixes
|
111
|
-
.each() { |ext|
|
117
|
+
exts = [".gl"].concat(Gem.suffixes)
|
118
|
+
exts.each() { |ext|
|
112
119
|
full = File.absolute_path(base.+(ext))
|
113
120
|
(if File.exist?(full)
|
114
121
|
pn = full
|
@@ -120,7 +127,7 @@ nil }
|
|
120
127
|
end
|
121
128
|
else
|
122
129
|
(if Config.strict_require
|
123
|
-
throw(:"error", "Cannot resolve
|
130
|
+
throw(:"error", "Cannot resolve relative path for #{path}")
|
124
131
|
else
|
125
132
|
Gloss.logger
|
126
133
|
.debug("No path found for #{path}")
|
@@ -128,7 +135,7 @@ nil }
|
|
128
135
|
end)
|
129
136
|
end
|
130
137
|
private def rbs_stdlib_path_for(libr)
|
131
|
-
File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "
|
138
|
+
File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", libr))
|
132
139
|
end
|
133
140
|
private def load_rbs_from_require_path(path)
|
134
141
|
Dir.glob(File.join(rbs_stdlib_path_for(path), "**", "*.rbs"))
|
data/lib/gloss/type_checker.rb
CHANGED
@@ -6,13 +6,23 @@
|
|
6
6
|
require "set"
|
7
7
|
module Gloss
|
8
8
|
class TypeChecker
|
9
|
-
Project = Struct.new(:"targets")
|
10
9
|
attr_reader(:"steep_target", :"top_level_decls", :"env", :"rbs_gem_dir")
|
10
|
+
module Strictness
|
11
|
+
Strict = "strict"
|
12
|
+
Lenient = "lenient"
|
13
|
+
Default = "default"
|
14
|
+
end
|
11
15
|
def initialize()
|
12
|
-
|
13
|
-
.
|
14
|
-
|
15
|
-
|
16
|
+
options = Steep::Project::Options.new
|
17
|
+
case Config.type_checking_strictness
|
18
|
+
when Strictness::Strict
|
19
|
+
options.apply_strict_typing_options!
|
20
|
+
when Strictness::Lenient
|
21
|
+
options.apply_lenient_typing_options!
|
22
|
+
else
|
23
|
+
options.apply_default_typing_options!
|
24
|
+
end
|
25
|
+
@steep_target = Steep::Project::Target.new(name: "gloss", options: options, source_patterns: ["**/*.rb"], ignore_patterns: Array.new, signature_patterns: ["sig"])
|
16
26
|
@top_level_decls = Set.new
|
17
27
|
@rbs_gem_dir = Utils.gem_path_for("rbs")
|
18
28
|
env_loader = RBS::EnvironmentLoader.new
|
@@ -51,7 +61,7 @@ case e
|
|
51
61
|
when Steep::Diagnostic::Ruby::UnexpectedBlockGiven
|
52
62
|
"Unexpected block given"
|
53
63
|
else
|
54
|
-
"#{e.header_line}\n#{e
|
64
|
+
"#{e.header_line}\n#{e}"
|
55
65
|
end
|
56
66
|
}
|
57
67
|
.join("\n")
|
data/lib/gloss/utils.rb
CHANGED
@@ -21,17 +21,11 @@ module Gloss
|
|
21
21
|
end)
|
22
22
|
end
|
23
23
|
def gem_path_for(gem_name)
|
24
|
-
|
25
|
-
|
26
|
-
.
|
27
|
-
|
28
|
-
|
29
|
-
Gem.ui
|
30
|
-
.outs
|
31
|
-
.string
|
32
|
-
rescue SystemExit => e
|
33
|
-
nil
|
34
|
-
end
|
24
|
+
spec = Gem::Specification.find_by_path(gem_name)
|
25
|
+
(if spec
|
26
|
+
spec.full_require_paths
|
27
|
+
.first
|
28
|
+
end)
|
35
29
|
end
|
36
30
|
def with_file_header(str)
|
37
31
|
"#{Visitor::FILE_HEADER}\n\n#{str}"
|
data/lib/gloss/version.rb
CHANGED
data/lib/gloss/visitor.rb
CHANGED
@@ -184,6 +184,7 @@ EMPTY_ARRAY }
|
|
184
184
|
else
|
185
185
|
nil
|
186
186
|
end)
|
187
|
+
name = node.[](:"name")
|
187
188
|
block = (if node.[](:"block")
|
188
189
|
" #{visit_node(node.[](:"block"))}"
|
189
190
|
else
|
@@ -195,14 +196,21 @@ EMPTY_ARRAY }
|
|
195
196
|
else
|
196
197
|
nil
|
197
198
|
end)
|
198
|
-
name = node.[](:"name")
|
199
199
|
call = "#{obj}#{name}#{opening_delimiter}#{args}#{(if has_parens
|
200
200
|
")"
|
201
201
|
end)}#{block}"
|
202
202
|
case name
|
203
203
|
when "require_relative"
|
204
204
|
(if @on_new_file_referenced
|
205
|
-
|
205
|
+
paths = arg_arr.map() { |a|
|
206
|
+
unless a.[](:"type")
|
207
|
+
.==("LiteralNode")
|
208
|
+
throw(:"error", "Dynamic file paths are not allowed in require_relative")
|
209
|
+
end
|
210
|
+
eval(visit_node(a, scope)
|
211
|
+
.strip)
|
212
|
+
}
|
213
|
+
@on_new_file_referenced.call(paths, true)
|
206
214
|
end)
|
207
215
|
when "module_function"
|
208
216
|
@after_module_function = true
|
@@ -254,7 +262,7 @@ case name
|
|
254
262
|
path = node.[](:"value")
|
255
263
|
src.write_ln("require \"#{path}\"")
|
256
264
|
(if @on_new_file_referenced
|
257
|
-
@on_new_file_referenced.call(path, false)
|
265
|
+
@on_new_file_referenced.call([path], false)
|
258
266
|
end)
|
259
267
|
when "Assign", "OpAssign"
|
260
268
|
src.write_ln("#{visit_node(node.[](:"target"))} #{node.[](:"op")}= #{visit_node(node.[](:"value"))
|
data/lib/gloss/watcher.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
require "listen"
|
7
7
|
module Gloss
|
8
8
|
class Watcher
|
9
|
+
# @type var @listener: Listen?
|
10
|
+
@listener
|
9
11
|
def initialize(paths)
|
10
12
|
@paths = paths
|
11
13
|
(if @paths.empty?
|
@@ -32,7 +34,7 @@ module Gloss
|
|
32
34
|
def watch()
|
33
35
|
Gloss.logger
|
34
36
|
.info("Now listening for changes in #{@paths.join(", ")}")
|
35
|
-
listener
|
37
|
+
@listener ||= Listen.to(*@paths, latency: 2, only: @only) { |modified, added, removed|
|
36
38
|
modified.+(added)
|
37
39
|
.each() { |f|
|
38
40
|
Gloss.logger
|
@@ -64,13 +66,18 @@ nil }
|
|
64
66
|
}
|
65
67
|
}
|
66
68
|
begin
|
67
|
-
listener.start
|
69
|
+
@listener.start
|
68
70
|
sleep
|
69
71
|
rescue Interrupt
|
70
|
-
|
71
|
-
.info("Interrupt signal received, shutting down")
|
72
|
-
exit(0)
|
72
|
+
kill
|
73
73
|
end
|
74
74
|
end
|
75
|
+
def kill()
|
76
|
+
Gloss.logger
|
77
|
+
.info("Interrupt signal received, shutting down")
|
78
|
+
(if @listener
|
79
|
+
@listener.stop
|
80
|
+
end)
|
81
|
+
end
|
75
82
|
end
|
76
83
|
end
|
data/lib/gloss/writer.rb
CHANGED
data/logo.svg
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
<svg width="171px" height="100px" xmlns="http://www.w3.org/2000/svg" viewBox="175 25 150 150" style="background-color: transparent;" preserveAspectRatio="xMidYMid"><defs><filter id="editing-golden" x="-100%" y="-100%" width="300%" height="300%"><feFlood flood-color="#000000" result="flood"></feFlood><feFlood flood-color="#eaa5a5" result="flood-light"></feFlood><feComposite operator="in" in="flood" in2="SourceAlpha" result="flood-comp"></feComposite><feGaussianBlur in="flood-comp" stdDeviation="3" result="blur"></feGaussianBlur><feOffset in="blur" dy="3" result="offset-blur"></feOffset><feComponentTransfer in="offset-blur" result="comp-blur"><feFuncA type="linear" slope="0.7" intercept="-0.1"></feFuncA></feComponentTransfer><feSpecularLighting surfaceScale="200" specularConstant="20" specularExponent="1" lighting-color="#fff" in="blur" result="specular"><fePointLight x="-250" y="-250" z="3500"></fePointLight></feSpecularLighting><feComponentTransfer in="specular" result="inspecular"><feFuncA type="linear" slope="-1" intercept="1"></feFuncA></feComponentTransfer><feComposite operator="in" in="flood-light" in2="inspecular" result="inspecular2"></feComposite><feComposite operator="in" in="inspecular2" in2="SourceAlpha" result="light"></feComposite><feMerge><feMergeNode in="comp-blur"></feMergeNode><feMergeNode in="SourceGraphic"></feMergeNode><feMergeNode in="light"></feMergeNode></feMerge></filter></defs><g filter="url(#editing-golden)"><g transform="translate(119.08499717712402, 130.10500073432922)"><path d="M27.50-50.40L27.50-50.40L27.50-50.40Q23.22-39.91 23.22-30.87L23.22-30.87L23.22-30.87Q23.22-21.83 26.91-17.55L26.91-17.55L26.91-17.55Q30.60-13.27 38.84-13.27L38.84-13.27L38.84-13.27Q43.76-13.27 47.51-16.80L47.51-16.80L47.51-16.80Q48.69-25.57 49.43-28.46L49.43-28.46L49.43-28.46Q51.25-35.52 55.00-35.52L55.00-35.52L55.00-35.52Q57.99-35.52 60.67-31.40L60.67-31.40L60.67-31.40Q63.34-27.29 63.24-24.40L63.24-24.40L63.24-24.40Q63.24-19.58 59.38-6.53L59.38-6.53L59.38-6.53Q66.88-12.20 76.61-23.33L76.61-23.33L76.61-23.33Q78.00-24.93 78.97-24.93L78.97-24.93L78.97-24.93Q80.46-24.93 80.46-21.40L80.46-21.40L80.46-21.40Q80.46-14.55 73.62-6.79L73.62-6.79L73.62-6.79Q66.77 0.96 55.43 5.56L55.43 5.56L55.43 5.56Q54.57 7.60 54.03 9.42L54.03 9.42L54.03 9.42Q53.50 11.23 52.64 13.80L52.64 13.80L52.64 13.80Q51.79 16.37 49.65 19.42L49.65 19.42L49.65 19.42Q47.51 22.47 44.30 24.61L44.30 24.61L44.30 24.61Q37.45 29.32 28.62 29.32L28.62 29.32L28.62 29.32Q19.79 29.32 13.86 25.41L13.86 25.41L13.86 25.41Q7.92 21.51 7.92 14.66L7.92 14.66L7.92 14.66Q7.92 11.34 11.13 9.20L11.13 9.20L11.13 9.20Q14.34 7.06 19.47 5.51L19.47 5.51L19.47 5.51Q24.61 3.96 31.03 2.78L31.03 2.78L31.03 2.78Q37.45 1.60 43.87 0.11L43.87 0.11L43.87 0.11Q44.73-2.35 45.15-4.49L45.15-4.49L45.15-4.49Q40.98-1.28 34.88-1.28L34.88-1.28L34.88-1.28Q22.15-1.28 14.87-6.53L14.87-6.53L14.87-6.53Q6.42-12.63 6.42-25.57L6.42-25.57L6.42-25.57Q6.42-42.48 14.98-57.67L14.98-57.67L14.98-57.67Q12.41-60.67 10.81-63.93L10.81-63.93L10.81-63.93Q9.20-67.20 9.20-68.91L9.20-68.91L9.20-68.91Q9.20-71.90 11.34-71.80L11.34-71.80L11.34-71.80Q12.73-71.80 14.55-70.08L14.55-70.08L14.55-70.08Q16.37-68.37 17.49-67.20L17.49-67.20L17.49-67.20Q18.62-66.02 19.90-65.06L19.90-65.06L19.90-65.06Q25.47-72.12 32.96-76.50L32.96-76.50L32.96-76.50Q40.45-80.89 49.43-80.89L49.43-80.89L49.43-80.89Q58.42-80.89 63.45-77.58L63.45-77.58L63.45-77.58Q68.48-74.26 68.48-66.02L68.48-66.02L68.48-66.02Q68.48-57.78 62.11-52.32L62.11-52.32L62.11-52.32Q55.75-46.87 44.41-46.87L44.41-46.87L44.41-46.87Q36.59-46.87 27.50-50.40ZM31.03-57.67L31.03-57.67L31.03-57.67Q36.91-55.10 45.26-55.10L45.26-55.10L45.26-55.10Q50.40-55.10 53.50-57.89L53.50-57.89L53.50-57.89Q56.60-60.67 56.60-63.93L56.60-63.93L56.60-63.93Q56.60-67.20 54.52-68.75L54.52-68.75L54.52-68.75Q52.43-70.30 49.01-70.30L49.01-70.30L49.01-70.30Q38.73-70.30 31.03-57.67ZM27.39 21.08L27.39 21.08L27.39 21.08Q34.67 21.08 40.13 10.16L40.13 10.16L40.13 10.16Q34.24 11.66 30.17 12.52L30.17 12.52L30.17 12.52Q26.11 13.38 23.59 14.02L23.59 14.02L23.59 14.02Q21.08 14.66 19.96 15.30L19.96 15.30L19.96 15.30Q18.83 15.94 18.83 17.12L18.83 17.12L18.83 17.12Q18.83 19.15 21.56 20.06L21.56 20.06L21.56 20.06Q24.29 20.97 27.39 21.08ZM98.97 0.32L98.97 0.32L98.97 0.32Q83.67 0.43 78.11-11.13L78.11-11.13L78.11-11.13Q76.18-15.19 76.18-21.35L76.18-21.35L76.18-21.35Q76.18-27.50 77.25-34.45L77.25-34.45L77.25-34.45Q79.39-48.36 85.49-60.13L85.49-60.13L85.49-60.13Q88.60-66.13 92.45-70.41L92.45-70.41L92.45-70.41Q100.90-79.82 111.28-79.72L111.28-79.72L111.28-79.72Q115.88-79.72 118.50-77.20L118.50-77.20L118.50-77.20Q121.12-74.69 121.12-69.98L121.12-69.98L121.12-69.98Q121.12-65.27 118.34-60.51L118.34-60.51L118.34-60.51Q115.56-55.75 111.23-50.66L111.23-50.66L111.23-50.66Q106.89-45.58 101.65-40.02L101.65-40.02L101.65-40.02Q96.41-34.45 91.38-27.93L91.38-27.93L91.38-23.65L91.38-23.65Q91.38-17.66 93.95-14.87L93.95-14.87L93.95-14.87Q96.51-12.09 99.94-12.09L99.94-12.09L99.94-12.09Q109.14-12.09 116.20-21.19L116.20-21.19L116.20-21.19Q119.09-24.93 120.59-24.93L120.59-24.93L120.59-24.93Q122.09-24.93 122.09-21.29L122.09-21.29L122.09-21.29Q122.09-17.66 120.11-13.86L120.11-13.86L120.11-13.86Q118.13-10.06 114.92-6.90L114.92-6.90L114.92-6.90Q111.71-3.75 107.53-1.71L107.53-1.71L107.53-1.71Q103.36 0.32 98.97 0.32ZM104.75-57.14L104.75-57.14L104.75-57.14Q107-59.92 108.28-62.17L108.28-62.17L108.28-62.17Q109.57-64.41 109.57-66.82L109.57-66.82L109.57-66.82Q109.57-69.23 107.86-69.23L107.86-69.23L107.86-69.23Q104.11-69.23 99.56-61.52L99.56-61.52L99.56-61.52Q95.02-53.82 92.77-41.30L92.77-41.30L92.77-41.30Q96.41-46.87 99.46-50.61L99.46-50.61L99.46-50.61Q102.51-54.36 104.75-57.14ZM159.00-9.10L159.00-9.10L159.00-9.10Q150.55 0.86 138.73 0.86L138.73 0.86L138.73 0.86Q126.90 0.86 121.02-5.19L121.02-5.19L121.02-5.19Q115.13-11.23 115.24-20.22L115.24-20.22L115.24-20.22Q115.13-32.96 123.26-42.16L123.26-42.16L123.26-42.16Q131.40-51.36 144.56-51.36L144.56-51.36L144.56-51.36Q150.55-51.36 154.19-49.86L154.19-49.86L154.19-49.86Q160.50-47.29 160.50-45.05L160.50-45.05L160.50-45.05Q160.50-43.34 151.67-43.28L151.67-43.28L151.67-43.28Q142.84-43.23 136.91-37.18L136.91-37.18L136.91-37.18Q130.97-31.14 130.97-21.93L130.97-21.93L130.97-21.93Q130.97-17.12 133.80-13.86L133.80-13.86L133.80-13.86Q136.64-10.59 141.83-10.59L141.83-10.59L141.83-10.59Q147.02-10.59 150.44-12.73L150.44-12.73L150.44-12.73Q142.84-17.87 142.84-27.61L142.84-27.61L142.84-27.61Q142.74-32.74 146.54-36.97L146.54-36.97L146.54-36.97Q150.33-41.20 156.27-41.25L156.27-41.25L156.27-41.25Q162.21-41.30 164.78-37.98L164.78-37.98L164.78-37.98Q167.35-34.67 167.35-29.48L167.35-29.48L167.35-29.48Q167.35-24.29 164.89-18.51L164.89-18.51L165.53-18.51L165.53-18.51Q170.24-18.62 173.66-21.83L173.66-21.83L173.66-21.83Q174.94-23.11 175.85-24.07L175.85-24.07L175.85-24.07Q176.76-25.04 177.73-25.04L177.73-25.04L177.73-25.04Q179.22-25.04 179.22-21.51L179.22-21.51L179.22-21.51Q179.22-14.98 175.37-11.72L175.37-11.72L175.37-11.72Q171.52-8.45 166.87-8.45L166.87-8.45L166.87-8.45Q162.21-8.45 159.00-9.10ZM158.04-21.51L158.04-21.51L158.04-21.51Q159.86-25.36 159.86-29.00L159.86-29.00L159.86-29.00Q159.86-32.63 157.50-32.63L157.50-32.63L157.50-32.63Q156.54-32.63 155.90-31.24L155.90-31.24L155.90-31.24Q155.26-29.85 155.26-28.57L155.26-28.57L155.26-28.57Q155.26-24.29 158.04-21.51ZM198.27-51.84L198.27-51.84L198.27-51.84Q205.44-51.89 208.97-49.17L208.97-49.17L208.97-49.17Q212.50-46.44 212.50-41.36L212.50-41.36L212.50-41.36Q212.50-36.27 209.45-32.69L209.45-32.69L209.45-32.69Q206.40-29.10 202.02-27.61L202.02-27.61L202.02-27.61Q205.12-24.40 207.63-21.08L207.63-21.08L207.63-21.08Q210.15-17.76 210.15-14.12L210.15-14.12L210.15-14.12Q210.15-6.96 204.48-3.05L204.48-3.05L204.48-3.05Q198.81 0.86 188.69 0.86L188.69 0.86L188.69 0.86Q178.58 0.86 173.55-3.16L173.55-3.16L173.55-3.16Q168.53-7.17 168.53-12.25L168.53-12.25L168.53-12.25Q168.53-17.33 171.04-21.51L171.04-21.51L171.04-21.51Q173.55-25.68 176.44-25.68L176.44-25.68L176.44-25.68Q178.16-25.68 178.90-24.45L178.90-24.45L178.90-24.45Q179.65-23.22 181.69-17.33L181.69-17.33L181.69-17.33Q182.44-15.19 184.15-13.27L184.15-13.27L184.15-13.27Q188.11-8.88 196.67-8.88L196.67-8.88L196.67-8.88Q195.38-12.95 192.55-15.89L192.55-15.89L192.55-15.89Q189.71-18.83 186.93-21.61L186.93-21.61L186.93-21.61Q184.15-24.40 182.01-27.55L182.01-27.55L182.01-27.55Q179.87-30.71 179.87-34.99L179.87-34.99L179.87-34.99Q179.87-42.69 185.64-47.51L185.64-47.51L185.64-47.51Q191.10-51.79 198.27-51.84ZM197.84-31.99L197.84-31.99L197.84-31.99Q202.12-36.59 202.12-39.38L202.12-39.38L202.12-39.38Q202.12-40.66 201.21-41.68L201.21-41.68L201.21-41.68Q200.30-42.69 198.59-42.69L198.59-42.69L198.59-42.69Q196.88-42.69 195.33-42.27L195.33-42.27L195.33-42.27Q193.78-41.84 192.81-41.62L192.81-41.62L192.81-41.62Q192.81-37.56 197.84-31.99ZM241.18-51.84L241.18-51.84L241.18-51.84Q248.35-51.89 251.88-49.17L251.88-49.17L251.88-49.17Q255.41-46.44 255.41-41.36L255.41-41.36L255.41-41.36Q255.41-36.27 252.36-32.69L252.36-32.69L252.36-32.69Q249.31-29.10 244.92-27.61L244.92-27.61L244.92-27.61Q248.03-24.40 250.54-21.08L250.54-21.08L250.54-21.08Q253.06-17.76 253.06-14.12L253.06-14.12L253.06-14.12Q253.06-6.96 247.38-3.05L247.38-3.05L247.38-3.05Q241.71 0.86 231.60 0.86L231.60 0.86L231.60 0.86Q221.49 0.86 216.46-3.16L216.46-3.16L216.46-3.16Q211.43-7.17 211.43-12.25L211.43-12.25L211.43-12.25Q211.43-17.33 213.95-21.51L213.95-21.51L213.95-21.51Q216.46-25.68 219.35-25.68L219.35-25.68L219.35-25.68Q221.06-25.68 221.81-24.45L221.81-24.45L221.81-24.45Q222.56-23.22 224.59-17.33L224.59-17.33L224.59-17.33Q225.34-15.19 227.05-13.27L227.05-13.27L227.05-13.27Q231.01-8.88 239.57-8.88L239.57-8.88L239.57-8.88Q238.29-12.95 235.45-15.89L235.45-15.89L235.45-15.89Q232.62-18.83 229.84-21.61L229.84-21.61L229.84-21.61Q227.05-24.40 224.91-27.55L224.91-27.55L224.91-27.55Q222.77-30.71 222.77-34.99L222.77-34.99L222.77-34.99Q222.77-42.69 228.55-47.51L228.55-47.51L228.55-47.51Q234.01-51.79 241.18-51.84ZM240.75-31.99L240.75-31.99L240.75-31.99Q245.03-36.59 245.03-39.38L245.03-39.38L245.03-39.38Q245.03-40.66 244.12-41.68L244.12-41.68L244.12-41.68Q243.21-42.69 241.50-42.69L241.50-42.69L241.50-42.69Q239.79-42.69 238.24-42.27L238.24-42.27L238.24-42.27Q236.68-41.84 235.72-41.62L235.72-41.62L235.72-41.62Q235.72-37.56 240.75-31.99Z" fill="#ae0606"></path></g></g><style>text {
|
2
|
+
font-size: 64px;
|
3
|
+
font-family: Arial Black;
|
4
|
+
dominant-baseline: central;
|
5
|
+
text-anchor: middle;
|
6
|
+
}</style></svg>
|
data/src/lib/gloss.gl
CHANGED
data/src/lib/gloss/config.gl
CHANGED
@@ -8,14 +8,20 @@ module Gloss
|
|
8
8
|
frozen_string_literals: true,
|
9
9
|
src_dir: "src",
|
10
10
|
entrypoint: nil,
|
11
|
-
strict_require: false
|
11
|
+
strict_require: false,
|
12
|
+
type_checking_strictness: "strict",
|
13
|
+
prettify_output_executable_path: nil
|
12
14
|
}
|
13
15
|
)
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def self.load_config
|
18
|
+
user_config = if File.exist?(File.absolute_path(File.join(Dir.pwd, CONFIG_PATH)))
|
19
|
+
YAML.safe_load(File.read(CONFIG_PATH))
|
20
|
+
else
|
21
|
+
Config.default_config
|
22
|
+
end
|
23
|
+
Config.default_config.each { |k, v| Config.send(:"#{k}=", user_config[k.to_s] || v) }
|
24
|
+
end
|
25
|
+
|
26
|
+
load_config
|
21
27
|
end
|
data/src/lib/gloss/logger.gl
CHANGED
@@ -15,7 +15,9 @@ module Gloss
|
|
15
15
|
nil => nil,
|
16
16
|
"" => nil
|
17
17
|
}.fetch env_log_level
|
18
|
-
@logger = Logger.new(real_log_level ? STDOUT : IO::NULL)
|
18
|
+
@logger = Logger.new(real_log_level ? STDOUT : IO::NULL).tap do |l|
|
19
|
+
l.level = real_log_level if real_log_level
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -4,6 +4,8 @@ module Gloss
|
|
4
4
|
OUTPUT_BY_PATH = Hash.new
|
5
5
|
|
6
6
|
class ProgLoader
|
7
|
+
attr_reader :type_checker
|
8
|
+
|
7
9
|
def initialize
|
8
10
|
entrypoint = Config.entrypoint
|
9
11
|
if entrypoint == nil || entrypoint == ""
|
@@ -21,16 +23,20 @@ module Gloss
|
|
21
23
|
def run
|
22
24
|
@files_to_process.each do |path_string|
|
23
25
|
# currently steep would give an `unexpected jump` if next was used
|
24
|
-
|
26
|
+
if path_string.end_with? ".rbs"
|
27
|
+
@type_checker.load_sig_path path_string
|
28
|
+
elsif !@processed_files.member?(path_string) || !OUTPUT_BY_PATH.[](path_string)
|
25
29
|
Gloss.logger.debug "Loading #{path_string}"
|
26
30
|
path = Utils.absolute_path(path_string)
|
27
31
|
file_contents = File.open(path).read
|
28
32
|
contents_tree = Parser.new(file_contents).run
|
29
|
-
on_new_file_referenced = proc do |
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
on_new_file_referenced = proc do |ps, relative|
|
34
|
+
ps.each do |pa|
|
35
|
+
if relative
|
36
|
+
handle_require_relative pa, path_string
|
37
|
+
else
|
38
|
+
handle_require pa
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
OUTPUT_BY_PATH.[](path_string) = Visitor.new(contents_tree, @type_checker, on_new_file_referenced).run
|
@@ -68,7 +74,7 @@ module Gloss
|
|
68
74
|
pathn = Pathname.new("#{File.join(Dir.pwd, "sig", path)}.rbs")
|
69
75
|
gem_path = Utils.gem_path_for(path)
|
70
76
|
if gem_path
|
71
|
-
sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "
|
77
|
+
sig_files = Dir.glob(File.absolute_path(File.join(gem_path, "..", "sig", "**", "*.rbs")))
|
72
78
|
if sig_files.length.positive?
|
73
79
|
sig_files.each do |fp|
|
74
80
|
@type_checker.load_sig_path fp
|
@@ -86,7 +92,7 @@ module Gloss
|
|
86
92
|
@type_checker.load_sig_path(pathn.to_s)
|
87
93
|
@processed_files.add pathn.to_s
|
88
94
|
else
|
89
|
-
rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "
|
95
|
+
rbs_stdlib_dir = File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", path))
|
90
96
|
if Pathname.new(rbs_stdlib_dir).exist?
|
91
97
|
load_rbs_from_require_path(path)
|
92
98
|
rbs_type_deps = STDLIB_TYPE_DEPENDENCIES.fetch(path) { nil }
|
@@ -102,10 +108,11 @@ module Gloss
|
|
102
108
|
end
|
103
109
|
end
|
104
110
|
|
105
|
-
private def handle_require_relative(path)
|
106
|
-
base = File.join(
|
111
|
+
private def handle_require_relative(path, source_file)
|
112
|
+
base = File.join(source_file, "..", path)
|
107
113
|
pn : String? = nil
|
108
|
-
Gem.suffixes
|
114
|
+
exts = %w[.gl].concat(Gem.suffixes)
|
115
|
+
exts.each do |ext|
|
109
116
|
full = File.absolute_path(base + ext)
|
110
117
|
pn = full if File.exist?(full)
|
111
118
|
end
|
@@ -113,14 +120,14 @@ module Gloss
|
|
113
120
|
if pn
|
114
121
|
@files_to_process << pn unless @files_to_process.include? pn
|
115
122
|
elsif Config.strict_require
|
116
|
-
throw :error, "Cannot resolve
|
123
|
+
throw :error, "Cannot resolve relative path for #{path}"
|
117
124
|
else
|
118
125
|
Gloss.logger.debug "No path found for #{path}"
|
119
126
|
end
|
120
127
|
end
|
121
128
|
|
122
129
|
private def rbs_stdlib_path_for(libr)
|
123
|
-
File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "
|
130
|
+
File.absolute_path(File.join(@type_checker.rbs_gem_dir, "..", "stdlib", libr))
|
124
131
|
end
|
125
132
|
|
126
133
|
private def load_rbs_from_require_path(path)
|
@@ -2,16 +2,27 @@ require "set"
|
|
2
2
|
|
3
3
|
module Gloss
|
4
4
|
class TypeChecker
|
5
|
-
Project = Struct.new :targets
|
6
|
-
|
7
5
|
attr_reader :steep_target, :top_level_decls, :env, :rbs_gem_dir
|
8
6
|
|
7
|
+
enum Strictness
|
8
|
+
Strict = "strict"
|
9
|
+
Lenient = "lenient"
|
10
|
+
Default = "default"
|
11
|
+
end
|
12
|
+
|
9
13
|
def initialize
|
14
|
+
options = Steep::Project::Options.new
|
15
|
+
case Config.type_checking_strictness
|
16
|
+
when Strictness::Strict
|
17
|
+
options.apply_strict_typing_options!
|
18
|
+
when Strictness::Lenient
|
19
|
+
options.apply_lenient_typing_options!
|
20
|
+
else
|
21
|
+
options.apply_default_typing_options!
|
22
|
+
end
|
10
23
|
@steep_target = Steep::Project::Target.new(
|
11
24
|
name: "gloss",
|
12
|
-
options:
|
13
|
-
o.allow_unknown_constant_assignment = true
|
14
|
-
end,
|
25
|
+
options: options,
|
15
26
|
source_patterns: ["**/*.rb"],
|
16
27
|
ignore_patterns: Array.new,
|
17
28
|
signature_patterns: ["sig"]
|
@@ -54,7 +65,7 @@ module Gloss
|
|
54
65
|
when Steep::Diagnostic::Ruby::UnexpectedBlockGiven
|
55
66
|
"Unexpected block given"
|
56
67
|
else
|
57
|
-
"#{e.header_line}\n#{e
|
68
|
+
"#{e.header_line}\n#{e}"
|
58
69
|
end
|
59
70
|
}.join("\n")
|
60
71
|
throw :error, errors
|
data/src/lib/gloss/utils.gl
CHANGED
@@ -19,11 +19,8 @@ module Gloss
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def gem_path_for(gem_name)
|
22
|
-
|
23
|
-
|
24
|
-
Gem.ui.outs.string
|
25
|
-
rescue SystemExit => e
|
26
|
-
nil
|
22
|
+
spec = Gem::Specification.find_by_path(gem_name)
|
23
|
+
spec.full_require_paths.first if spec
|
27
24
|
end
|
28
25
|
|
29
26
|
def with_file_header(str)
|
data/src/lib/gloss/version.gl
CHANGED
data/src/lib/gloss/visitor.gl
CHANGED
@@ -102,7 +102,7 @@ module Gloss
|
|
102
102
|
members: Array.new, # TODO
|
103
103
|
annotations: Array.new, # TODO
|
104
104
|
location: build_location(node),
|
105
|
-
comment: node[:comment]
|
105
|
+
comment: node[:comment],
|
106
106
|
)
|
107
107
|
old_parent_scope = @current_scope
|
108
108
|
@current_scope = module_type
|
@@ -202,6 +202,7 @@ module Gloss
|
|
202
202
|
else
|
203
203
|
nil
|
204
204
|
end
|
205
|
+
name = node[:name]
|
205
206
|
block = node[:block] ? " #{visit_node(node[:block])}" : nil
|
206
207
|
has_parens = !!(node[:has_parentheses] || args || block)
|
207
208
|
opening_delimiter = if has_parens
|
@@ -209,11 +210,18 @@ module Gloss
|
|
209
210
|
else
|
210
211
|
nil
|
211
212
|
end
|
212
|
-
name = node[:name]
|
213
213
|
call = "#{obj}#{name}#{opening_delimiter}#{args}#{")" if has_parens}#{block}"
|
214
214
|
case name
|
215
215
|
when "require_relative"
|
216
|
-
|
216
|
+
if @on_new_file_referenced
|
217
|
+
paths = arg_arr.map do |a|
|
218
|
+
unless a[:type] == "LiteralNode"
|
219
|
+
throw :error, "Dynamic file paths are not allowed in require_relative"
|
220
|
+
end
|
221
|
+
eval(visit_node(a, scope).strip)
|
222
|
+
end
|
223
|
+
@on_new_file_referenced.call(paths, true)
|
224
|
+
end
|
217
225
|
when "module_function"
|
218
226
|
@after_module_function = true
|
219
227
|
end
|
@@ -264,7 +272,7 @@ module Gloss
|
|
264
272
|
path = node[:value]
|
265
273
|
src.write_ln %(require "#{path}")
|
266
274
|
|
267
|
-
@on_new_file_referenced.call(path, false) if @on_new_file_referenced
|
275
|
+
@on_new_file_referenced.call([path], false) if @on_new_file_referenced
|
268
276
|
when "Assign", "OpAssign"
|
269
277
|
|
270
278
|
src.write_ln "#{visit_node(node[:target])} #{node[:op]}= #{visit_node(node[:value]).strip}"
|
data/src/lib/gloss/watcher.gl
CHANGED
@@ -2,6 +2,8 @@ require "listen"
|
|
2
2
|
|
3
3
|
module Gloss
|
4
4
|
class Watcher
|
5
|
+
@listener: Listen?
|
6
|
+
|
5
7
|
def initialize(@paths : Array[String])
|
6
8
|
if @paths.empty?
|
7
9
|
@paths = [File.join(Dir.pwd, Config.src_dir)]
|
@@ -22,7 +24,7 @@ module Gloss
|
|
22
24
|
|
23
25
|
def watch
|
24
26
|
Gloss.logger.info "Now listening for changes in #{@paths.join(', ')}"
|
25
|
-
listener
|
27
|
+
@listener ||= Listen.to(
|
26
28
|
*@paths,
|
27
29
|
latency: 2,
|
28
30
|
only: @only
|
@@ -55,12 +57,16 @@ module Gloss
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
begin
|
58
|
-
listener.start
|
60
|
+
@listener.start
|
59
61
|
sleep
|
60
62
|
rescue Interrupt
|
61
|
-
|
62
|
-
exit 0
|
63
|
+
kill
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
67
|
+
def kill
|
68
|
+
Gloss.logger.info "Interrupt signal received, shutting down"
|
69
|
+
@listener.stop if @listener
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
data/src/lib/gloss/writer.gl
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johansenja
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_blank
|
@@ -42,24 +42,38 @@ dependencies:
|
|
42
42
|
name: rbs
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.0.4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.0.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: steep
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.41.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.41.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
|
-
type: :
|
76
|
+
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
@@ -95,7 +109,7 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rubocop
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: rufo
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -132,8 +146,7 @@ extensions:
|
|
132
146
|
extra_rdoc_files: []
|
133
147
|
files:
|
134
148
|
- ".gitattributes"
|
135
|
-
- ".github/workflows/
|
136
|
-
- ".github/workflows/ruby_specs.yml"
|
149
|
+
- ".github/workflows/tests.yml"
|
137
150
|
- ".gitignore"
|
138
151
|
- ".gloss.yml"
|
139
152
|
- ".rspec"
|
@@ -174,6 +187,7 @@ files:
|
|
174
187
|
- lib/gloss/visitor.rb
|
175
188
|
- lib/gloss/watcher.rb
|
176
189
|
- lib/gloss/writer.rb
|
190
|
+
- logo.svg
|
177
191
|
- sig/core.rbs
|
178
192
|
- sig/fast_blank.rbs
|
179
193
|
- sig/gls.rbs
|
@@ -217,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
231
|
- !ruby/object:Gem::Version
|
218
232
|
version: '0'
|
219
233
|
requirements: []
|
220
|
-
rubygems_version: 3.
|
234
|
+
rubygems_version: 3.2.3
|
221
235
|
signing_key:
|
222
236
|
specification_version: 4
|
223
237
|
summary: A superset of ruby
|
@@ -1,26 +0,0 @@
|
|
1
|
-
name: Crystal Specs
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ master ]
|
8
|
-
|
9
|
-
defaults:
|
10
|
-
run:
|
11
|
-
working-directory: ext/gloss
|
12
|
-
|
13
|
-
jobs:
|
14
|
-
build:
|
15
|
-
|
16
|
-
runs-on: ubuntu-latest
|
17
|
-
|
18
|
-
container:
|
19
|
-
image: crystallang/crystal
|
20
|
-
|
21
|
-
steps:
|
22
|
-
- uses: actions/checkout@v2
|
23
|
-
- name: Install dependencies
|
24
|
-
run: shards install
|
25
|
-
- name: Run tests
|
26
|
-
run: crystal spec
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby Specs
|
9
|
-
|
10
|
-
on:
|
11
|
-
push:
|
12
|
-
branches: [ master ]
|
13
|
-
pull_request:
|
14
|
-
branches: [ master ]
|
15
|
-
|
16
|
-
jobs:
|
17
|
-
test:
|
18
|
-
|
19
|
-
runs-on: ubuntu-latest
|
20
|
-
|
21
|
-
steps:
|
22
|
-
- uses: actions/checkout@v2
|
23
|
-
- name: Set up Ruby
|
24
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
-
# uses: ruby/setup-ruby@v1
|
27
|
-
uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
|
28
|
-
with:
|
29
|
-
ruby-version: 2.7
|
30
|
-
- name: Install dependencies
|
31
|
-
run: bundle install
|
32
|
-
- name: Run tests
|
33
|
-
run: bundle exec rake build && bundle exec rake spec
|