gloss 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.gloss.yml +3 -0
- data/.rubocop.yml +147 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +112 -0
- data/README.md +205 -0
- data/Rakefile +20 -0
- data/bin/console +14 -0
- data/exe/gloss +6 -0
- data/ext/gloss/Makefile +15 -0
- data/ext/gloss/extconf.rb +32 -0
- data/ext/gloss/shard.yml +18 -0
- data/ext/gloss/src/cr_ast.cr +382 -0
- data/ext/gloss/src/gloss.cr +31 -0
- data/ext/gloss/src/lexer.cr +1186 -0
- data/ext/gloss/src/lib/cr_ruby.cr +35 -0
- data/ext/gloss/src/parser.cr +340 -0
- data/ext/gloss/src/rb_ast.cr +491 -0
- data/gloss.gemspec +26 -0
- data/lib/gloss.bundle.dwarf +0 -0
- data/lib/gloss.rb +22 -0
- data/lib/gloss/builder.rb +442 -0
- data/lib/gloss/cli.rb +35 -0
- data/lib/gloss/config.rb +15 -0
- data/lib/gloss/errors.rb +11 -0
- data/lib/gloss/initializer.rb +20 -0
- data/lib/gloss/scope.rb +9 -0
- data/lib/gloss/source.rb +32 -0
- data/lib/gloss/version.rb +3 -0
- data/lib/gloss/watcher.rb +32 -0
- data/lib/gloss/writer.rb +26 -0
- data/sig/listen.rbs +48 -0
- data/src/lib/hrb/initializer.gl +22 -0
- data/src/lib/hrb/watcher.gl +32 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: efa5107f463e2776911f8897141a352305c964561f4d64f5002d21ad2f3e25cf
|
4
|
+
data.tar.gz: 0c65ac9ffd1a26ebd10c9e68eeb31e754c19fb22e9afb652e3a659c51b844217
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48e4df3d238b7b322baff5b7a30ceb037fb0bc2a067ee4318a1e3876f876d2e0a3bdf82e779295c6f76239c0c92f9e7b5e7eab8242384b4a052f610a866e2f15
|
7
|
+
data.tar.gz: c456de971b4ffed42a5a67dbc628dd6bdc793c9eb97a50e9bfc85433121ab634e35b920af8fd4adc64d20f7e600f7628f51179b54cc2f080c163b8688bfbc954
|
data/.gloss.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "bin/**/*"
|
4
|
+
- "db/**/*"
|
5
|
+
- "config/**/*"
|
6
|
+
- "node_modules/**/*"
|
7
|
+
- "spec/**/*"
|
8
|
+
- "support/**/*"
|
9
|
+
- "tmp/**/*"
|
10
|
+
- "test/**/*"
|
11
|
+
|
12
|
+
# probably don't need this yet - more useful to have them grouped by category/use than alphabetical anyway
|
13
|
+
Bundler/OrderedGems:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 100
|
18
|
+
Layout/SpaceAroundMethodCallOperator:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Lint/RaiseException:
|
22
|
+
Enabled: true
|
23
|
+
Lint/StructNewOverride:
|
24
|
+
Enabled: true
|
25
|
+
Lint/SuppressedException: # this is sometimes useful in a rails context
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/AbcSize:
|
29
|
+
Enabled: false
|
30
|
+
Metrics/BlockLength:
|
31
|
+
Enabled: false
|
32
|
+
Metrics/ClassLength:
|
33
|
+
Enabled: false
|
34
|
+
Metrics/CyclomaticComplexity:
|
35
|
+
Enabled: false
|
36
|
+
Metrics/MethodLength:
|
37
|
+
Max: 50
|
38
|
+
|
39
|
+
Style/RedundantReturn:
|
40
|
+
Enabled: false
|
41
|
+
Style/Documentation:
|
42
|
+
Enabled: false
|
43
|
+
Style/StringLiterals:
|
44
|
+
EnforcedStyle: double_quotes # consistency across ts and rb
|
45
|
+
Style/ConditionalAssignment:
|
46
|
+
Enabled: false
|
47
|
+
Style/EmptyMethod:
|
48
|
+
Enabled: false
|
49
|
+
# sometimes it is good to have else with just `nil` in it for clarity eg. it is a return value
|
50
|
+
Style/EmptyElse:
|
51
|
+
EnforcedStyle: empty
|
52
|
+
Style/HashEachMethods:
|
53
|
+
Enabled: true
|
54
|
+
Style/HashTransformKeys:
|
55
|
+
Enabled: true
|
56
|
+
Style/HashTransformValues:
|
57
|
+
Enabled: true
|
58
|
+
Style/AsciiComments:
|
59
|
+
Enabled: false # Emojis and comments on foreign characters 👌
|
60
|
+
Style/FrozenStringLiteralComment:
|
61
|
+
Enabled: false
|
62
|
+
Style/Alias:
|
63
|
+
EnforcedStyle: prefer_alias_method
|
64
|
+
Style/ParallelAssignment:
|
65
|
+
Enabled: false
|
66
|
+
Style/ExponentialNotation:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
|
70
|
+
Enabled: true
|
71
|
+
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
|
72
|
+
Enabled: true
|
73
|
+
Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
Lint/DuplicateElsifCondition: # (new in 0.88)
|
77
|
+
Enabled: true
|
78
|
+
Lint/DuplicateRequire: # (new in 0.90)
|
79
|
+
Enabled: true
|
80
|
+
Lint/DuplicateRescueException: # (new in 0.89)
|
81
|
+
Enabled: true
|
82
|
+
Lint/EmptyConditionalBody: # (new in 0.89)
|
83
|
+
Enabled: true
|
84
|
+
Lint/EmptyFile: # (new in 0.90)
|
85
|
+
Enabled: true
|
86
|
+
Lint/FloatComparison: # (new in 0.89)
|
87
|
+
Enabled: true
|
88
|
+
Lint/MissingSuper: # (new in 0.89)
|
89
|
+
Enabled: true
|
90
|
+
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
|
91
|
+
Enabled: true
|
92
|
+
Lint/OutOfRangeRegexpRef: # (new in 0.89)
|
93
|
+
Enabled: true
|
94
|
+
Lint/SelfAssignment: # (new in 0.89)
|
95
|
+
Enabled: true
|
96
|
+
Lint/TopLevelReturnWithArgument: # (new in 0.89)
|
97
|
+
Enabled: true
|
98
|
+
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
|
99
|
+
Enabled: true
|
100
|
+
Lint/UnreachableLoop: # (new in 0.89)
|
101
|
+
Enabled: true
|
102
|
+
Lint/UselessMethodDefinition: # (new in 0.90)
|
103
|
+
Enabled: true
|
104
|
+
Style/AccessorGrouping: # (new in 0.87)
|
105
|
+
Enabled: true
|
106
|
+
Style/ArrayCoercion: # (new in 0.88)
|
107
|
+
Enabled: true
|
108
|
+
Style/BisectedAttrAccessor: # (new in 0.87)
|
109
|
+
Enabled: true
|
110
|
+
Style/CaseLikeIf: # (new in 0.88)
|
111
|
+
Enabled: true
|
112
|
+
Style/CombinableLoops: # (new in 0.90)
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/ExplicitBlockArgument: # (new in 0.89)
|
116
|
+
Enabled: true
|
117
|
+
Style/GlobalStdStream: # (new in 0.89)
|
118
|
+
Enabled: true
|
119
|
+
Style/HashAsLastArrayItem: # (new in 0.88)
|
120
|
+
Enabled: true
|
121
|
+
Style/HashLikeCase: # (new in 0.88)
|
122
|
+
Enabled: true
|
123
|
+
Style/KeywordParametersOrder: # (new in 0.90)
|
124
|
+
Enabled: true
|
125
|
+
Style/OptionalBooleanParameter: # (new in 0.89)
|
126
|
+
Enabled: true
|
127
|
+
Style/RedundantAssignment: # (new in 0.87)
|
128
|
+
Enabled: true
|
129
|
+
Style/RedundantFetchBlock: # (new in 0.86)
|
130
|
+
Enabled: true
|
131
|
+
Style/RedundantFileExtensionInRequire: # (new in 0.88)
|
132
|
+
Enabled: true
|
133
|
+
|
134
|
+
Style/RedundantRegexpCharacterClass: # (new in 0.85)
|
135
|
+
Enabled: true
|
136
|
+
Style/RedundantRegexpEscape: # (new in 0.85)
|
137
|
+
Enabled: true
|
138
|
+
Style/RedundantSelfAssignment: # (new in 0.90)
|
139
|
+
Enabled: true
|
140
|
+
Style/SingleArgumentDig: # (new in 0.89)
|
141
|
+
Enabled: true
|
142
|
+
Style/SlicingWithRange: # (new in 0.83)
|
143
|
+
Enabled: true
|
144
|
+
Style/SoleNestedConditional: # (new in 0.89)
|
145
|
+
Enabled: true
|
146
|
+
Style/StringConcatenation: # (new in 0.89)
|
147
|
+
Enabled: true
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,112 @@
|
|
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
|
+
PATH
|
9
|
+
remote: .
|
10
|
+
specs:
|
11
|
+
gloss (0.0.1)
|
12
|
+
fast_blank
|
13
|
+
listen
|
14
|
+
steep
|
15
|
+
|
16
|
+
GEM
|
17
|
+
remote: https://rubygems.org/
|
18
|
+
specs:
|
19
|
+
activesupport (6.1.0)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 1.6, < 2)
|
22
|
+
minitest (>= 5.1)
|
23
|
+
tzinfo (~> 2.0)
|
24
|
+
zeitwerk (~> 2.3)
|
25
|
+
ast (2.4.1)
|
26
|
+
ast_utils (0.3.0)
|
27
|
+
parser (~> 2.4)
|
28
|
+
thor (>= 0.19)
|
29
|
+
byebug (11.1.3)
|
30
|
+
coderay (1.1.3)
|
31
|
+
concurrent-ruby (1.1.7)
|
32
|
+
diff-lcs (1.4.4)
|
33
|
+
fast_blank (1.0.0)
|
34
|
+
ffi (1.14.2)
|
35
|
+
i18n (1.8.5)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
language_server-protocol (3.15.0.1)
|
38
|
+
listen (3.3.3)
|
39
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
40
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
41
|
+
method_source (1.0.0)
|
42
|
+
minitest (5.14.2)
|
43
|
+
parallel (1.20.1)
|
44
|
+
parser (2.7.2.0)
|
45
|
+
ast (~> 2.4.1)
|
46
|
+
pry (0.13.1)
|
47
|
+
coderay (~> 1.1)
|
48
|
+
method_source (~> 1.0)
|
49
|
+
pry-byebug (3.9.0)
|
50
|
+
byebug (~> 11.0)
|
51
|
+
pry (~> 0.13.0)
|
52
|
+
rainbow (3.0.0)
|
53
|
+
rake (13.0.1)
|
54
|
+
rake-compiler (1.1.1)
|
55
|
+
rake
|
56
|
+
rb-fsevent (0.10.4)
|
57
|
+
rb-inotify (0.10.1)
|
58
|
+
ffi (~> 1.0)
|
59
|
+
regexp_parser (2.0.0)
|
60
|
+
rexml (3.2.4)
|
61
|
+
rspec (3.10.0)
|
62
|
+
rspec-core (~> 3.10.0)
|
63
|
+
rspec-expectations (~> 3.10.0)
|
64
|
+
rspec-mocks (~> 3.10.0)
|
65
|
+
rspec-core (3.10.0)
|
66
|
+
rspec-support (~> 3.10.0)
|
67
|
+
rspec-expectations (3.10.0)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.10.0)
|
70
|
+
rspec-mocks (3.10.0)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.10.0)
|
73
|
+
rspec-support (3.10.0)
|
74
|
+
rubocop (1.5.1)
|
75
|
+
parallel (~> 1.10)
|
76
|
+
parser (>= 2.7.1.5)
|
77
|
+
rainbow (>= 2.2.2, < 4.0)
|
78
|
+
regexp_parser (>= 2.0)
|
79
|
+
rexml
|
80
|
+
rubocop-ast (>= 1.2.0)
|
81
|
+
ruby-progressbar (~> 1.7)
|
82
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
83
|
+
rubocop-ast (1.3.0)
|
84
|
+
parser (>= 2.7.1.5)
|
85
|
+
ruby-progressbar (1.10.1)
|
86
|
+
steep (0.39.0)
|
87
|
+
activesupport (>= 5.1)
|
88
|
+
ast_utils (~> 0.3.0)
|
89
|
+
language_server-protocol (~> 3.15.0.1)
|
90
|
+
listen (~> 3.0)
|
91
|
+
parser (~> 2.7.0)
|
92
|
+
rainbow (>= 2.2.2, < 4.0)
|
93
|
+
rbs (~> 1.0.0)
|
94
|
+
thor (1.0.1)
|
95
|
+
tzinfo (2.0.4)
|
96
|
+
concurrent-ruby (~> 1.0)
|
97
|
+
unicode-display_width (1.7.0)
|
98
|
+
zeitwerk (2.4.2)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
gloss!
|
105
|
+
pry-byebug
|
106
|
+
rake-compiler
|
107
|
+
rbs!
|
108
|
+
rspec
|
109
|
+
rubocop
|
110
|
+
|
111
|
+
BUNDLED WITH
|
112
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
# Gloss
|
2
|
+
|
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:
|
5
|
+
|
6
|
+
- Type checking, via optional type annotations
|
7
|
+
- Compile-time macros
|
8
|
+
- Enums
|
9
|
+
- Tuples and Named Tuples
|
10
|
+
- All ruby files are valid gloss files (a small exceptions for now; workarounds are mostly available)
|
11
|
+
- Other syntactic sugar
|
12
|
+
|
13
|
+
Coming soon:
|
14
|
+
- abstract classes
|
15
|
+
|
16
|
+
Maybe on the roadmap:
|
17
|
+
- Method overloading
|
18
|
+
|
19
|
+
## Examples:
|
20
|
+
|
21
|
+
#### Type checking:
|
22
|
+
|
23
|
+
```crystal
|
24
|
+
class HelloWorld
|
25
|
+
def perform : String
|
26
|
+
str = "Hello world"
|
27
|
+
puts str
|
28
|
+
str
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
result : String = HelloWorld.perform # Error => No singleton method `perform` for HelloWorld
|
33
|
+
result : Integer = HelloWorld.new.perform # Incompatible assignment => can't assign string to integer
|
34
|
+
result : String = HelloWorld.new.perform # OK
|
35
|
+
result.length # OK => 11
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Macros:
|
39
|
+
|
40
|
+
```crystal
|
41
|
+
# src/lib/http_client.gloss
|
42
|
+
|
43
|
+
class HttpClient
|
44
|
+
|
45
|
+
@base_url : String
|
46
|
+
|
47
|
+
def initialize(@base_url); end
|
48
|
+
|
49
|
+
{% for verb in %w[get post put patch delete] %}
|
50
|
+
def {{verb}}(path : String, headers : Hash[untyped, untyped]?, body : Hash[untyped, untyped]?)
|
51
|
+
{% if verb == "get" %}
|
52
|
+
warn "ignoring body #{body} for get request" unless body.nil?
|
53
|
+
# business logic
|
54
|
+
{% elsif %w[post patch put].include? verb %}
|
55
|
+
body : String = body.to_json
|
56
|
+
# business logic
|
57
|
+
{% else %}
|
58
|
+
# delete request business logic
|
59
|
+
{% end %}
|
60
|
+
end
|
61
|
+
{% end %}
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
compiles to:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
# lib/http_client.rb
|
69
|
+
# frozen_string_literal: true
|
70
|
+
|
71
|
+
class HttpClient
|
72
|
+
# @type ivar base_url: String
|
73
|
+
|
74
|
+
def initialize(base_url)
|
75
|
+
@base_url = base_url
|
76
|
+
end
|
77
|
+
|
78
|
+
def get(path, headers, body)
|
79
|
+
warn "ignoring body #{body} for get request" unless body.nil?
|
80
|
+
# business logic
|
81
|
+
end
|
82
|
+
|
83
|
+
def post(path, headers, body)
|
84
|
+
# @type var body: String
|
85
|
+
body = body.to_json
|
86
|
+
# business logic
|
87
|
+
end
|
88
|
+
|
89
|
+
def put(path, headers, body)
|
90
|
+
# @type var body: String
|
91
|
+
body = body.to_json
|
92
|
+
# business logic
|
93
|
+
end
|
94
|
+
|
95
|
+
def patch(path, headers, body)
|
96
|
+
# @type var body: String
|
97
|
+
body = body.to_json
|
98
|
+
# business logic
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete(path, headers, body)
|
102
|
+
# delete request business logic
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
#### Enums:
|
108
|
+
|
109
|
+
```crystal
|
110
|
+
class Language
|
111
|
+
enum Lang
|
112
|
+
R = "Ruby"
|
113
|
+
C = "Crystal"
|
114
|
+
TS = "TypeScript"
|
115
|
+
P = "Python"
|
116
|
+
end
|
117
|
+
|
118
|
+
def favourite_language(language : Lang)
|
119
|
+
puts "my favourite language is #{language}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
#### Tuples + Named Tuples:
|
125
|
+
|
126
|
+
Currently, named tuples can only have symbols as keys, and are distinguished from hashes by the use of the post ruby-1.9 syntax `key: value` (for named tuple) vs `:key => value` (for hash) - see example below. **This is liable to change to ensure maximum compatibility with existing ruby code**.
|
127
|
+
|
128
|
+
```crystal
|
129
|
+
tuple = {"hello", "world"}
|
130
|
+
array = ["hello", "world"]
|
131
|
+
named_tuple = { hello: "world" }
|
132
|
+
hash = { :hello => "world" }
|
133
|
+
|
134
|
+
array << "!" # OK
|
135
|
+
tuple << "!" # Error
|
136
|
+
hash["key"] = "value" # OK
|
137
|
+
named_tuple["key"] = "value" # Error
|
138
|
+
```
|
139
|
+
|
140
|
+
#### Other syntactic suger:
|
141
|
+
|
142
|
+
```crystal
|
143
|
+
class MyClass
|
144
|
+
def initialize(@var1, @@var2)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
compiles to
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
class MyClass
|
153
|
+
def initialize(var1, var2)
|
154
|
+
@var1 = var1
|
155
|
+
@var2 = var2
|
156
|
+
end
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
```crystal
|
161
|
+
str = "abc"
|
162
|
+
case str
|
163
|
+
when "a"
|
164
|
+
"only a"
|
165
|
+
when .start_with?("a")
|
166
|
+
"starts with a"
|
167
|
+
when String
|
168
|
+
"definitely a string"
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
compiles to
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
str = "abc"
|
176
|
+
case str
|
177
|
+
when "a"
|
178
|
+
"only a"
|
179
|
+
when ->(x) { x.start_with?("a") }
|
180
|
+
"starts with a"
|
181
|
+
when String
|
182
|
+
"any other string"
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
186
|
+
## Usage:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
# Gemfile
|
190
|
+
group :development do
|
191
|
+
gem "gloss"
|
192
|
+
end
|
193
|
+
```
|
194
|
+
|
195
|
+
then
|
196
|
+
|
197
|
+
`bundle install`
|
198
|
+
|
199
|
+
then
|
200
|
+
|
201
|
+
`gloss init # create .gloss.yml config file`
|
202
|
+
|
203
|
+
then
|
204
|
+
|
205
|
+
`gloss build`
|