gloss 0.0.1 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +3 -0
  3. data/.github/workflows/crystal_specs.yml +26 -0
  4. data/.github/workflows/ruby_specs.yml +33 -0
  5. data/.gitignore +2 -1
  6. data/.rspec +1 -0
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +26 -34
  9. data/LICENSE +21 -0
  10. data/README.md +59 -7
  11. data/Rakefile +4 -0
  12. data/exe/gloss +15 -1
  13. data/ext/gloss/Makefile +27 -5
  14. data/ext/gloss/extconf.rb +3 -25
  15. data/ext/gloss/{src/lib → lib}/cr_ruby.cr +0 -0
  16. data/ext/gloss/lib/rbs_types.cr +3 -0
  17. data/ext/gloss/spec/parser_spec.cr +124 -0
  18. data/ext/gloss/spec/spec_helper.cr +2 -0
  19. data/ext/gloss/src/cr_ast.cr +129 -31
  20. data/ext/gloss/src/gloss.cr +12 -18
  21. data/ext/gloss/src/lexer.cr +59 -1
  22. data/ext/gloss/src/parser.cr +548 -254
  23. data/ext/gloss/src/rb_ast.cr +153 -27
  24. data/gloss.gemspec +1 -0
  25. data/lib/gloss.rb +4 -1
  26. data/lib/gloss/builder.rb +607 -409
  27. data/lib/gloss/cli.rb +64 -24
  28. data/lib/gloss/config.rb +16 -10
  29. data/lib/gloss/errors.rb +13 -7
  30. data/lib/gloss/initializer.rb +11 -6
  31. data/lib/gloss/logger.rb +34 -0
  32. data/lib/gloss/parser.rb +35 -0
  33. data/lib/gloss/scope.rb +8 -3
  34. data/lib/gloss/source.rb +18 -15
  35. data/lib/gloss/type_checker.rb +96 -0
  36. data/lib/gloss/version.rb +6 -1
  37. data/lib/gloss/watcher.rb +63 -19
  38. data/lib/gloss/writer.rb +18 -12
  39. data/sig/gloss.rbs +3 -0
  40. data/sig/listen.rbs +1 -0
  41. data/src/lib/gloss/builder.gl +546 -0
  42. data/src/lib/gloss/cli.gl +55 -0
  43. data/src/lib/gloss/config.gl +21 -0
  44. data/src/lib/gloss/errors.gl +11 -0
  45. data/src/lib/gloss/initializer.gl +20 -0
  46. data/src/lib/gloss/logger.gl +26 -0
  47. data/src/lib/gloss/parser.gl +31 -0
  48. data/src/lib/gloss/scope.gl +9 -0
  49. data/src/lib/gloss/source.gl +32 -0
  50. data/src/lib/gloss/type_checker.gl +101 -0
  51. data/src/lib/gloss/version.gl +3 -0
  52. data/src/lib/gloss/watcher.gl +67 -0
  53. data/src/lib/gloss/writer.gl +33 -0
  54. metadata +42 -6
  55. data/lib/gloss.bundle.dwarf +0 -0
  56. data/src/lib/hrb/initializer.gl +0 -22
  57. data/src/lib/hrb/watcher.gl +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efa5107f463e2776911f8897141a352305c964561f4d64f5002d21ad2f3e25cf
4
- data.tar.gz: 0c65ac9ffd1a26ebd10c9e68eeb31e754c19fb22e9afb652e3a659c51b844217
3
+ metadata.gz: 9315ca2d8d487ca5729f7665abcba9e922ec4e0ee85ac54787248d07b54b7ed5
4
+ data.tar.gz: 78928faa1a7e77e0184594a31786c0befdc796a4a9b46c5f509adb95c39d37c3
5
5
  SHA512:
6
- metadata.gz: 48e4df3d238b7b322baff5b7a30ceb037fb0bc2a067ee4318a1e3876f876d2e0a3bdf82e779295c6f76239c0c92f9e7b5e7eab8242384b4a052f610a866e2f15
7
- data.tar.gz: c456de971b4ffed42a5a67dbc628dd6bdc793c9eb97a50e9bfc85433121ab634e35b920af8fd4adc64d20f7e600f7628f51179b54cc2f080c163b8688bfbc954
6
+ metadata.gz: c3178c5cf74e3946e327cbe97b5c5f421090e7b678d331c34ce5c8a45aea137cdc9628f91481425e18f66cf3245983d1e5bf965feaae211d619d8d9f5ed55647
7
+ data.tar.gz: 9d9b5ef709cffe8efb6b0124762bbe025948caa51772cf33a38143862003048f15ee83198c2fd0f6a05128f14da65a9feb22b45205563b686bacb70d51dd5741
data/.gitattributes ADDED
@@ -0,0 +1,3 @@
1
+ lib/gloss/**/*.rb linguist-generated
2
+ # this will basically cover 99% of the syntax anyway
3
+ **/*.gl linguist-language=Crystal
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,33 @@
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
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
- *.bundle
1
+ *.bundle*
2
2
  *.o
3
3
  ext/.shards/
4
4
  tmp/
5
5
  *.log
6
+ pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
- gem "rbs", git: "git@github.com:duderman/rbs.git", branch: "file-open-block"
data/Gemfile.lock CHANGED
@@ -1,45 +1,38 @@
1
- GIT
2
- remote: git@github.com:duderman/rbs.git
3
- revision: cb347ab605c6409d5ad38ba7439b170ed5996fae
4
- branch: file-open-block
5
- specs:
6
- rbs (1.0.0)
7
-
8
1
  PATH
9
2
  remote: .
10
3
  specs:
11
- gloss (0.0.1)
4
+ gloss (0.0.6)
12
5
  fast_blank
13
6
  listen
7
+ rbs
14
8
  steep
15
9
 
16
10
  GEM
17
11
  remote: https://rubygems.org/
18
12
  specs:
19
- activesupport (6.1.0)
13
+ activesupport (6.1.1)
20
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
15
  i18n (>= 1.6, < 2)
22
16
  minitest (>= 5.1)
23
17
  tzinfo (~> 2.0)
24
18
  zeitwerk (~> 2.3)
25
19
  ast (2.4.1)
26
- ast_utils (0.3.0)
27
- parser (~> 2.4)
28
- thor (>= 0.19)
20
+ ast_utils (0.4.0)
21
+ parser (>= 2.7.0)
29
22
  byebug (11.1.3)
30
23
  coderay (1.1.3)
31
- concurrent-ruby (1.1.7)
24
+ concurrent-ruby (1.1.8)
32
25
  diff-lcs (1.4.4)
33
26
  fast_blank (1.0.0)
34
27
  ffi (1.14.2)
35
- i18n (1.8.5)
28
+ i18n (1.8.7)
36
29
  concurrent-ruby (~> 1.0)
37
30
  language_server-protocol (3.15.0.1)
38
- listen (3.3.3)
31
+ listen (3.4.1)
39
32
  rb-fsevent (~> 0.10, >= 0.10.3)
40
33
  rb-inotify (~> 0.9, >= 0.9.10)
41
34
  method_source (1.0.0)
42
- minitest (5.14.2)
35
+ minitest (5.14.3)
43
36
  parallel (1.20.1)
44
37
  parser (2.7.2.0)
45
38
  ast (~> 2.4.1)
@@ -50,48 +43,48 @@ GEM
50
43
  byebug (~> 11.0)
51
44
  pry (~> 0.13.0)
52
45
  rainbow (3.0.0)
53
- rake (13.0.1)
46
+ rake (13.0.3)
54
47
  rake-compiler (1.1.1)
55
48
  rake
56
49
  rb-fsevent (0.10.4)
57
50
  rb-inotify (0.10.1)
58
51
  ffi (~> 1.0)
59
- regexp_parser (2.0.0)
52
+ rbs (1.0.4)
53
+ regexp_parser (2.0.3)
60
54
  rexml (3.2.4)
61
55
  rspec (3.10.0)
62
56
  rspec-core (~> 3.10.0)
63
57
  rspec-expectations (~> 3.10.0)
64
58
  rspec-mocks (~> 3.10.0)
65
- rspec-core (3.10.0)
59
+ rspec-core (3.10.1)
66
60
  rspec-support (~> 3.10.0)
67
- rspec-expectations (3.10.0)
61
+ rspec-expectations (3.10.1)
68
62
  diff-lcs (>= 1.2.0, < 2.0)
69
63
  rspec-support (~> 3.10.0)
70
- rspec-mocks (3.10.0)
64
+ rspec-mocks (3.10.1)
71
65
  diff-lcs (>= 1.2.0, < 2.0)
72
66
  rspec-support (~> 3.10.0)
73
- rspec-support (3.10.0)
74
- rubocop (1.5.1)
67
+ rspec-support (3.10.1)
68
+ rubocop (1.7.0)
75
69
  parallel (~> 1.10)
76
70
  parser (>= 2.7.1.5)
77
71
  rainbow (>= 2.2.2, < 4.0)
78
- regexp_parser (>= 2.0)
72
+ regexp_parser (>= 1.8, < 3.0)
79
73
  rexml
80
- rubocop-ast (>= 1.2.0)
74
+ rubocop-ast (>= 1.2.0, < 2.0)
81
75
  ruby-progressbar (~> 1.7)
82
76
  unicode-display_width (>= 1.4.0, < 2.0)
83
- rubocop-ast (1.3.0)
77
+ rubocop-ast (1.4.0)
84
78
  parser (>= 2.7.1.5)
85
- ruby-progressbar (1.10.1)
86
- steep (0.39.0)
79
+ ruby-progressbar (1.11.0)
80
+ steep (0.40.0)
87
81
  activesupport (>= 5.1)
88
- ast_utils (~> 0.3.0)
82
+ ast_utils (>= 0.4.0)
89
83
  language_server-protocol (~> 3.15.0.1)
90
84
  listen (~> 3.0)
91
- parser (~> 2.7.0)
85
+ parser (>= 2.7)
92
86
  rainbow (>= 2.2.2, < 4.0)
93
- rbs (~> 1.0.0)
94
- thor (1.0.1)
87
+ rbs (~> 1.0.3)
95
88
  tzinfo (2.0.4)
96
89
  concurrent-ruby (~> 1.0)
97
90
  unicode-display_width (1.7.0)
@@ -104,9 +97,8 @@ DEPENDENCIES
104
97
  gloss!
105
98
  pry-byebug
106
99
  rake-compiler
107
- rbs!
108
100
  rspec
109
101
  rubocop
110
102
 
111
103
  BUNDLED WITH
112
- 2.1.4
104
+ 2.2.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Joseph Johansen
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 CHANGED
@@ -1,7 +1,15 @@
1
1
  # Gloss
2
+ [![Gem Version](https://badge.fury.io/rb/gloss.svg)](https://rubygems.org/gems/gloss)
3
+ [![Ruby Specs](https://github.com/johansenja/gloss/workflows/Ruby%20Specs/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3A%22Ruby+Specs%22)
4
+ [![Crystal Specs](https://github.com/johansenja/gloss/workflows/Crystal%20Specs/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3A%22Crystal+Specs%22)
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)
6
+ [![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)
2
8
 
3
- Gloss 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,
4
- efficiency, and to enhance ruby's goal of developer happiness and productivity. Some of the features include:
9
+ [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
+ efficiency, and to enhance ruby's goal of developer happiness and productivity.
11
+
12
+ ### Current features
5
13
 
6
14
  - Type checking, via optional type annotations
7
15
  - Compile-time macros
@@ -10,11 +18,26 @@ efficiency, and to enhance ruby's goal of developer happiness and productivity.
10
18
  - All ruby files are valid gloss files (a small exceptions for now; workarounds are mostly available)
11
19
  - Other syntactic sugar
12
20
 
13
- Coming soon:
14
- - abstract classes
21
+ ### Current Status
22
+
23
+ This project is at a stage where the core non-crystal parts are written in Gloss and compile to ruby (essentially self-hosting), albeit with the type checking being fairly loose. However the project is still in the very early stages; with (as of yet) no Linux support nor error handling (see roadmap below). Use at your own discretion!
24
+
25
+ ### Approx. roadmap:
26
+
27
+ - Improve error handling and logging (currently almost non-existant)
28
+ - Address Linux compatibility (currently more or less non-existant)
29
+ - Implement different strictnesses of type checking
30
+ - Metaprogramming helpers/safety:*
31
+ - Abstract classes and methods
32
+ - Method lookup/existence checking at compile time
33
+ - Method overloading
34
+
35
+ #### Related items:
36
+
37
+ - Rails helpers; probably some time away*
38
+ - Editor plugins/syntax highlighting/langserver; probably some time away*
15
39
 
16
- Maybe on the roadmap:
17
- - Method overloading
40
+ *__Dependent on popularity__
18
41
 
19
42
  ## Examples:
20
43
 
@@ -38,7 +61,7 @@ result.length # OK => 11
38
61
  #### Macros:
39
62
 
40
63
  ```crystal
41
- # src/lib/http_client.gloss
64
+ # src/lib/http_client.gl
42
65
 
43
66
  class HttpClient
44
67
 
@@ -119,6 +142,8 @@ class Language
119
142
  puts "my favourite language is #{language}"
120
143
  end
121
144
  end
145
+
146
+ Language.new.favourite_language(Language::Lang::R)
122
147
  ```
123
148
 
124
149
  #### Tuples + Named Tuples:
@@ -183,6 +208,25 @@ when String
183
208
  end
184
209
  ```
185
210
 
211
+ #### Abstract classes (roadmap)
212
+
213
+ ```crystal
214
+ abstract class BaseClass
215
+ attr_reader :var
216
+
217
+ def initialize(@var); end
218
+ end
219
+
220
+ class Child < BaseClass
221
+ def what_is_var
222
+ "var is #{var}"
223
+ end
224
+ end
225
+
226
+ BaseClass.new(123) # Error - can't instantiate abstract class
227
+ Child.new(123).what_is_var # Ok - "var is 123"
228
+ ```
229
+
186
230
  ## Usage:
187
231
 
188
232
  ```ruby
@@ -202,4 +246,12 @@ then
202
246
 
203
247
  then
204
248
 
249
+ `mkdir src && echo "puts 'hello world'" > src/hello_world.gl`
250
+
251
+ then
252
+
205
253
  `gloss build`
254
+
255
+ then
256
+
257
+ `ruby ./hello_world.rb`
data/Rakefile CHANGED
@@ -17,4 +17,8 @@ RSpec::Core::RakeTask.new :spec do |spec|
17
17
  spec.pattern = 'spec/**/*_spec.rb'
18
18
  end
19
19
 
20
+ task :build do
21
+ `cd ext/gloss && make && cd -`
22
+ end
23
+
20
24
  task :default => [:spec]
data/exe/gloss CHANGED
@@ -3,4 +3,18 @@
3
3
  require "bundler/setup"
4
4
  require "gloss"
5
5
 
6
- Gloss::CLI.new(ARGV).run
6
+ begin
7
+ Gloss::CLI.new(ARGV).run
8
+ rescue SystemExit
9
+ # raised by `abort` or `exit`; no op
10
+ rescue => e
11
+ Gloss.logger.fatal <<~MSG
12
+ Unexpected error: #{e.class.name}
13
+ Message: #{e.message}
14
+ Trace:
15
+ #{e.backtrace.join("\n")}
16
+
17
+ This is probably a bug and may warrant a bug report at https://github.com/johansenja/gloss/issues
18
+ MSG
19
+ exit 1
20
+ end
data/ext/gloss/Makefile CHANGED
@@ -1,15 +1,37 @@
1
1
  CRYSTAL = crystal
2
- TARGET = ../../lib/gloss.bundle
2
+ TARGET = ../../lib/gls
3
3
 
4
+ PLATFORM = $(shell uname -s)
5
+
6
+ ifeq "$(PLATFORM)" "Darwin"
7
+ install: all
8
+
9
+ all: clean shards build
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
20
+ endif
21
+
22
+ ifeq "$(PLATFORM)" "Linux"
23
+ LLVM_TARGET = "$(shell uname -m)-unknown-linux-gnu"
4
24
  install: all
5
25
 
6
- all: clean shards $(TARGET)
26
+ all: clean shards build
7
27
 
8
28
  shards:
9
29
  shards
10
30
 
11
- $(TARGET): ./src/gloss.cr
12
- $(CRYSTAL) build --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" $< -o $(TARGET)
31
+ build: ./src/gloss.cr
32
+ $(CRYSTAL) build $< --cross-compile --target $(LLVM_TARGET) --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o $(TARGET)
13
33
 
14
34
  clean:
15
- rm -f ../../**/*.bundle*
35
+ rm -f $(TARGET).o
36
+ rm -f $(TARGET).so
37
+ endif
data/ext/gloss/extconf.rb CHANGED
@@ -1,32 +1,10 @@
1
1
  require "mkmf"
2
- # $makefile_created = true
3
2
  find_executable("crystal") or abort <<~ERR
4
3
  You need crystal installed to use this gem.
5
4
  Please check out https://crystal-lang.org/ for information on how to install it.
6
5
  ERR
7
- # $LDFLAGS = "-rdynamic -L/usr/local/Cellar/crystal/0.35.1_1/embedded/lib -L/usr/local/lib -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.35.1_1/src/ext/libcrystal.a -L/usr/local/Cellar/libevent/2.1.12/lib -levent -liconv -ldl -Llib -lgloss"
8
- # $LDFLAGS << " -Wl,-undefined,dynamic_lookup -Llib -lgloss "
9
6
 
10
- create_makefile "gloss"
11
- # $(CRYSTAL) $< --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o $(TARGET)
12
-
13
- # I feel like a bad person
14
- # File.open(File.join(__dir__, "Makefile"), "w") do |f|
15
- # f.write <<~MAKEFILE
16
- # CRYSTAL = crystal
17
- # TARGET = ../../lib/gloss.bundle
18
-
19
- # install: all
20
-
21
- # all: clean shards $(TARGET)
7
+ # patch it to be no-op
8
+ def create_makefile(_, _ = nil); end
22
9
 
23
- # shards:
24
- # shards
25
-
26
- # $(TARGET): ./src/gloss.cr
27
- # $(CRYSTAL) build --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" $< -o $(TARGET)
28
-
29
- # clean:
30
- # rm -f ../../**/*.bundle*
31
- # MAKEFILE
32
- # end
10
+ create_makefile "gloss"