gloss 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/ext/gloss/{src/lib → lib}/cr_ruby.cr +0 -0
- data/ext/gloss/lib/rbs_types.cr +3 -0
- data/ext/gloss/src/cr_ast.cr +41 -8
- data/ext/gloss/src/gloss.cr +2 -1
- data/ext/gloss/src/lexer.cr +59 -1
- data/ext/gloss/src/rb_ast.cr +80 -31
- data/lib/gloss/builder.rb +581 -412
- data/lib/gloss/cli.rb +42 -28
- data/lib/gloss/config.rb +5 -6
- data/lib/gloss/errors.rb +4 -5
- data/lib/gloss/initializer.rb +5 -6
- data/lib/gloss/parser.rb +4 -5
- data/lib/gloss/scope.rb +8 -3
- data/lib/gloss/source.rb +18 -15
- data/lib/gloss/type_checker.rb +15 -10
- data/lib/gloss/version.rb +5 -6
- data/lib/gloss/watcher.rb +7 -8
- data/lib/gloss/writer.rb +5 -7
- data/sig/listen.rbs +1 -0
- data/src/lib/gloss/builder.gl +520 -0
- data/src/lib/gloss/cli.gl +41 -0
- data/src/lib/gloss/scope.gl +9 -0
- data/src/lib/gloss/source.gl +32 -0
- data/src/lib/gloss/type_checker.gl +4 -1
- data/src/lib/gloss/version.gl +1 -1
- data/src/lib/gloss/writer.gl +3 -3
- metadata +8 -3
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module Gloss
|
6
|
+
class CLI
|
7
|
+
def initialize(argv)
|
8
|
+
@argv = argv
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
# TODO: allow destructuring: command, *files = @argv
|
13
|
+
command = @argv.first
|
14
|
+
files = @argv[1..-1]
|
15
|
+
case command
|
16
|
+
when "watch"
|
17
|
+
Watcher.new.watch
|
18
|
+
when "build"
|
19
|
+
(files.empty? ? Dir.glob("#{Config.src_dir}/**/*.gl") : files).each do |fp|
|
20
|
+
puts "=====> Building #{fp}"
|
21
|
+
content = File.read(fp)
|
22
|
+
tree_hash = Parser.new(content).run
|
23
|
+
type_checker = TypeChecker.new
|
24
|
+
rb_output = Builder.new(tree_hash, type_checker).run
|
25
|
+
type_checker.run(rb_output)
|
26
|
+
|
27
|
+
puts "=====> Writing #{fp}"
|
28
|
+
Writer.new(rb_output, fp).run
|
29
|
+
end
|
30
|
+
when "init"
|
31
|
+
force = false
|
32
|
+
OptionParser.new do |opt|
|
33
|
+
opt.on("--force", "-f") { force = true }
|
34
|
+
end.parse(@argv)
|
35
|
+
Initializer.new(force).run
|
36
|
+
else
|
37
|
+
abort "Gloss doesn't know how to #{command}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gloss
|
4
|
+
class Source < String
|
5
|
+
def initialize(@indent_level)
|
6
|
+
super()
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(*args : String)
|
10
|
+
args.each do |a|
|
11
|
+
self << a
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_indnt(*args : String)
|
17
|
+
write(*args.map { |a| "#{(" " * @indent_level)}#{a}" })
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_ln(*args : String)
|
21
|
+
write_indnt(*args.map { |a| a.strip << "\n" })
|
22
|
+
end
|
23
|
+
|
24
|
+
def increment_indent
|
25
|
+
@indent_level += 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def decrement_indent
|
29
|
+
@indent_level -= 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -29,7 +29,10 @@ module Gloss
|
|
29
29
|
when Steep::Errors::MethodBodyTypeMismatch
|
30
30
|
"Invalid method body type - expected: #{e.expected}, actual: #{e.actual}"
|
31
31
|
when Steep::Errors::IncompatibleArguments
|
32
|
-
|
32
|
+
<<-ERR
|
33
|
+
Invalid argmuents - method type: #{e.method_type}
|
34
|
+
method name: #{e.method_type.method_decls.first.method_name}
|
35
|
+
ERR
|
33
36
|
when Steep::Errors::ReturnTypeMismatch
|
34
37
|
"Invalid return type - expected: #{e.expected}, actual: #{e.actual}"
|
35
38
|
when Steep::Errors::IncompatibleAssignment
|
data/src/lib/gloss/version.gl
CHANGED
data/src/lib/gloss/writer.gl
CHANGED
@@ -7,7 +7,7 @@ module Gloss
|
|
7
7
|
module Utils
|
8
8
|
module_function
|
9
9
|
|
10
|
-
def src_path_to_output_path(src_path)
|
10
|
+
def src_path_to_output_path(src_path : String) : String
|
11
11
|
src_path.sub(%r{\A(?:\./)?#{Config.src_dir}/?}, "")
|
12
12
|
.sub(/\.gl$/, ".rb")
|
13
13
|
end
|
@@ -18,8 +18,8 @@ module Gloss
|
|
18
18
|
|
19
19
|
def initialize(
|
20
20
|
@content,
|
21
|
-
src_path : String
|
22
|
-
@output_path : Pathname = Pathname.new(src_path_to_output_path(src_path))
|
21
|
+
src_path : String,
|
22
|
+
@output_path : Pathname? = Pathname.new(src_path_to_output_path(src_path))
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johansenja
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_blank
|
@@ -145,13 +145,14 @@ files:
|
|
145
145
|
- exe/gloss
|
146
146
|
- ext/gloss/Makefile
|
147
147
|
- ext/gloss/extconf.rb
|
148
|
+
- ext/gloss/lib/cr_ruby.cr
|
149
|
+
- ext/gloss/lib/rbs_types.cr
|
148
150
|
- ext/gloss/shard.yml
|
149
151
|
- ext/gloss/spec/parser_spec.cr
|
150
152
|
- ext/gloss/spec/spec_helper.cr
|
151
153
|
- ext/gloss/src/cr_ast.cr
|
152
154
|
- ext/gloss/src/gloss.cr
|
153
155
|
- ext/gloss/src/lexer.cr
|
154
|
-
- ext/gloss/src/lib/cr_ruby.cr
|
155
156
|
- ext/gloss/src/parser.cr
|
156
157
|
- ext/gloss/src/rb_ast.cr
|
157
158
|
- gloss.gemspec
|
@@ -170,10 +171,14 @@ files:
|
|
170
171
|
- lib/gloss/writer.rb
|
171
172
|
- sig/gloss.rbs
|
172
173
|
- sig/listen.rbs
|
174
|
+
- src/lib/gloss/builder.gl
|
175
|
+
- src/lib/gloss/cli.gl
|
173
176
|
- src/lib/gloss/config.gl
|
174
177
|
- src/lib/gloss/errors.gl
|
175
178
|
- src/lib/gloss/initializer.gl
|
176
179
|
- src/lib/gloss/parser.gl
|
180
|
+
- src/lib/gloss/scope.gl
|
181
|
+
- src/lib/gloss/source.gl
|
177
182
|
- src/lib/gloss/type_checker.gl
|
178
183
|
- src/lib/gloss/version.gl
|
179
184
|
- src/lib/gloss/watcher.gl
|