code-ruby 1.3.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.node-version +1 -1
- data/.npm-version +1 -1
- data/.rubocop.yml +8 -7
- data/.ruby-version +1 -1
- data/.tool-versions +2 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +81 -65
- data/VERSION +1 -1
- data/bin/code +14 -7
- data/code-ruby.gemspec +2 -2
- data/lib/code/concerns/shared.rb +17 -61
- data/lib/code/concerns.rb +2 -0
- data/lib/code/node/code.rb +10 -0
- data/lib/code/node/dictionary.rb +34 -15
- data/lib/code/node/function_parameter.rb +1 -1
- data/lib/code/object/boolean.rb +2 -2
- data/lib/code/object/class.rb +2 -2
- data/lib/code/object/code.rb +8 -2
- data/lib/code/object/context.rb +1 -1
- data/lib/code/object/date.rb +3 -3
- data/lib/code/object/decimal.rb +3 -3
- data/lib/code/object/dictionary.rb +23 -7
- data/lib/code/object/duration.rb +3 -3
- data/lib/code/object/function.rb +2 -2
- data/lib/code/object/global.rb +7 -6
- data/lib/code/object/html.rb +4 -5
- data/lib/code/object/http.rb +0 -2
- data/lib/code/object/integer.rb +3 -3
- data/lib/code/object/list.rb +10 -3
- data/lib/code/object/nothing.rb +2 -2
- data/lib/code/object/parameter.rb +2 -2
- data/lib/code/object/range.rb +2 -2
- data/lib/code/object/string.rb +13 -12
- data/lib/code/object/time.rb +2 -6
- data/lib/code/object.rb +2 -6
- data/lib/code/parser/call.rb +11 -5
- data/lib/code/parser/class.rb +1 -34
- data/lib/code/parser/dictionary.rb +7 -5
- data/lib/code/parser/equal.rb +0 -4
- data/lib/code/parser/function.rb +24 -2
- data/lib/code/parser/group.rb +32 -2
- data/lib/code/parser/if.rb +31 -4
- data/lib/code/parser/name.rb +7 -2
- data/lib/code/parser/while.rb +32 -1
- data/lib/code/type/sig.rb +2 -2
- data/lib/code/type.rb +1 -1
- data/lib/code.rb +25 -18
- data/package-lock.json +2 -2
- data/package.json +2 -2
- data/spec/code/object/http_spec.rb +70 -66
- data/spec/code_spec.rb +6 -2
- metadata +4 -6
- data/TODO +0 -219
- data/bin/console +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23ca15ea80387f4c771b52dd51869b3be31b4a38f7e9f8e65cbfa42b29c8ae5
|
4
|
+
data.tar.gz: 596ff5205a84e50ce9d75214990a35826b9d991636f59d6baec8735bb883e7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174c9ab2b2046b7ef38e53cd974b716ed984688d9e95d0b1bbd06fabdb41d14bcfee1d2e5498a28f4a944c1633dbfcfdcd9b8e23ed40729c6bc8f05fdfdb9a3a
|
7
|
+
data.tar.gz: b8333e8f9f2bde24c722669d4ad398715daa621059f904f7b36042c65111f4b501486eafbeb10d8273dfcfc4878da695e9a201e5213d44752b8a139293b99835
|
data/.node-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
23.11.0
|
data/.npm-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
11.2.0
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
---
|
2
2
|
AllCops:
|
3
3
|
Exclude:
|
4
|
-
- "
|
5
|
-
- "
|
6
|
-
-
|
7
|
-
- vendor/**/*
|
4
|
+
- "**/node_modules/**/*"
|
5
|
+
- "**/vendor/**/*"
|
6
|
+
- "**/db/schema.rb"
|
8
7
|
NewCops: enable
|
9
|
-
TargetRubyVersion: 3.
|
8
|
+
TargetRubyVersion: 3.0
|
10
9
|
Layout/ClosingHeredocIndentation:
|
11
10
|
Enabled: false
|
12
11
|
Layout/FirstArgumentIndentation:
|
@@ -23,6 +22,8 @@ Layout/MultilineMethodCallIndentation:
|
|
23
22
|
Enabled: false
|
24
23
|
Layout/MultilineOperationIndentation:
|
25
24
|
Enabled: false
|
25
|
+
Layout/SpaceInsideHashLiteralBraces:
|
26
|
+
Enabled: false
|
26
27
|
Lint/EmptyClass:
|
27
28
|
Enabled: false
|
28
29
|
Lint/MissingSuper:
|
@@ -119,11 +120,11 @@ Style/StringLiterals:
|
|
119
120
|
Enabled: false
|
120
121
|
Style/StringLiteralsInInterpolation:
|
121
122
|
Enabled: false
|
122
|
-
|
123
|
+
plugins:
|
123
124
|
- rubocop-factory_bot
|
124
125
|
- rubocop-performance
|
125
126
|
- rubocop-rails
|
126
127
|
- rubocop-rake
|
127
128
|
- rubocop-rspec
|
128
|
-
- rubocop-rspec_rails
|
129
129
|
- rubocop-capybara
|
130
|
+
- rubocop-rspec_rails
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.4.2
|
data/.tool-versions
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
ruby 3.
|
1
|
+
ruby 3.4.2
|
2
2
|
yarn 1.22.22
|
3
|
-
nodejs
|
3
|
+
nodejs 23.11.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (1.
|
4
|
+
code-ruby (1.5.1)
|
5
5
|
activesupport
|
6
6
|
base64
|
7
7
|
bigdecimal
|
@@ -17,7 +17,7 @@ PATH
|
|
17
17
|
GEM
|
18
18
|
remote: https://rubygems.org/
|
19
19
|
specs:
|
20
|
-
activesupport (8.0.
|
20
|
+
activesupport (8.0.2)
|
21
21
|
base64
|
22
22
|
benchmark (>= 0.3)
|
23
23
|
bigdecimal
|
@@ -32,23 +32,23 @@ GEM
|
|
32
32
|
uri (>= 0.13.1)
|
33
33
|
addressable (2.8.7)
|
34
34
|
public_suffix (>= 2.0.2, < 7.0)
|
35
|
-
ast (2.4.
|
35
|
+
ast (2.4.3)
|
36
36
|
base64 (0.2.0)
|
37
37
|
benchmark (0.4.0)
|
38
|
-
bigdecimal (3.1.
|
38
|
+
bigdecimal (3.1.9)
|
39
39
|
bundler-audit (0.9.2)
|
40
40
|
bundler (>= 1.2.0, < 3)
|
41
41
|
thor (~> 1.0)
|
42
42
|
cmdparse (3.0.7)
|
43
|
-
concurrent-ruby (1.3.
|
44
|
-
connection_pool (2.
|
43
|
+
concurrent-ruby (1.3.5)
|
44
|
+
connection_pool (2.5.0)
|
45
45
|
crack (1.0.0)
|
46
46
|
bigdecimal
|
47
47
|
rexml
|
48
|
-
csv (3.3.
|
48
|
+
csv (3.3.3)
|
49
49
|
did-you-mean (0.1.1)
|
50
50
|
levenshtein (>= 0.2.0)
|
51
|
-
diff-lcs (1.
|
51
|
+
diff-lcs (1.6.1)
|
52
52
|
dorian (2.6.3)
|
53
53
|
csv
|
54
54
|
dorian-arguments
|
@@ -76,74 +76,78 @@ GEM
|
|
76
76
|
dorian-to_struct (2.0.2)
|
77
77
|
drb (2.2.1)
|
78
78
|
geom2d (0.4.1)
|
79
|
-
git (
|
79
|
+
git (3.0.0)
|
80
80
|
activesupport (>= 5.0)
|
81
81
|
addressable (~> 2.8)
|
82
|
-
process_executer (~> 1.
|
83
|
-
rchardet (~> 1.
|
82
|
+
process_executer (~> 1.3)
|
83
|
+
rchardet (~> 1.9)
|
84
84
|
haml (6.3.0)
|
85
85
|
temple (>= 0.8.2)
|
86
86
|
thor
|
87
87
|
tilt
|
88
88
|
hashdiff (1.1.2)
|
89
|
-
hexapdf (1.0
|
89
|
+
hexapdf (1.2.0)
|
90
90
|
cmdparse (~> 3.0, >= 3.0.3)
|
91
91
|
geom2d (~> 0.4, >= 0.4.1)
|
92
92
|
openssl (>= 2.2.1)
|
93
|
-
|
93
|
+
strscan (>= 3.1.2)
|
94
|
+
i18n (1.14.7)
|
94
95
|
concurrent-ruby (~> 1.0)
|
95
|
-
json (2.
|
96
|
+
json (2.10.2)
|
96
97
|
language-ruby (1.1.2)
|
97
98
|
dorian-arguments
|
98
99
|
zeitwerk
|
99
|
-
language_server-protocol (3.17.0.
|
100
|
+
language_server-protocol (3.17.0.4)
|
100
101
|
levenshtein (0.2.2)
|
101
|
-
libv8-node (
|
102
|
-
libv8-node (
|
103
|
-
libv8-node (
|
104
|
-
|
102
|
+
libv8-node (23.6.1.0)
|
103
|
+
libv8-node (23.6.1.0-arm64-darwin)
|
104
|
+
libv8-node (23.6.1.0-x86_64-linux)
|
105
|
+
lint_roller (1.1.0)
|
106
|
+
logger (1.7.0)
|
105
107
|
mini_portile2 (2.8.8)
|
106
|
-
mini_racer (0.
|
107
|
-
libv8-node (~>
|
108
|
-
minitest (5.25.
|
108
|
+
mini_racer (0.18.1)
|
109
|
+
libv8-node (~> 23.6.1.0)
|
110
|
+
minitest (5.25.5)
|
109
111
|
mustermann (3.0.3)
|
110
112
|
ruby2_keywords (~> 0.0.1)
|
111
113
|
net-http (0.6.0)
|
112
114
|
uri
|
113
|
-
nokogiri (1.18.
|
115
|
+
nokogiri (1.18.7)
|
114
116
|
mini_portile2 (~> 2.8.2)
|
115
117
|
racc (~> 1.4)
|
116
|
-
nokogiri (1.18.
|
118
|
+
nokogiri (1.18.7-arm64-darwin)
|
117
119
|
racc (~> 1.4)
|
118
|
-
nokogiri (1.18.
|
120
|
+
nokogiri (1.18.7-x86_64-linux-gnu)
|
119
121
|
racc (~> 1.4)
|
120
|
-
openssl (3.
|
122
|
+
openssl (3.3.0)
|
121
123
|
ostruct (0.6.1)
|
122
124
|
parallel (1.26.3)
|
123
|
-
parser (3.3.
|
125
|
+
parser (3.3.7.4)
|
124
126
|
ast (~> 2.4.1)
|
125
127
|
racc
|
126
128
|
prettier_print (1.2.1)
|
127
|
-
|
129
|
+
prism (1.4.0)
|
130
|
+
process_executer (1.3.0)
|
128
131
|
public_suffix (6.0.1)
|
129
132
|
racc (1.8.1)
|
130
|
-
rack (3.1.
|
133
|
+
rack (3.1.12)
|
131
134
|
rack-protection (4.1.1)
|
132
135
|
base64 (>= 0.1.0)
|
133
136
|
logger (>= 1.6.0)
|
134
137
|
rack (>= 3.0.0, < 4)
|
135
|
-
rack-session (2.
|
138
|
+
rack-session (2.1.0)
|
139
|
+
base64 (>= 0.1.0)
|
136
140
|
rack (>= 3.0.0)
|
137
141
|
rainbow (3.1.1)
|
138
142
|
rake (13.2.1)
|
139
|
-
rchardet (1.
|
140
|
-
regexp_parser (2.
|
141
|
-
rexml (3.4.
|
143
|
+
rchardet (1.9.0)
|
144
|
+
regexp_parser (2.10.0)
|
145
|
+
rexml (3.4.1)
|
142
146
|
rspec (3.13.0)
|
143
147
|
rspec-core (~> 3.13.0)
|
144
148
|
rspec-expectations (~> 3.13.0)
|
145
149
|
rspec-mocks (~> 3.13.0)
|
146
|
-
rspec-core (3.13.
|
150
|
+
rspec-core (3.13.3)
|
147
151
|
rspec-support (~> 3.13.0)
|
148
152
|
rspec-expectations (3.13.3)
|
149
153
|
diff-lcs (>= 1.2.0, < 2.0)
|
@@ -152,37 +156,46 @@ GEM
|
|
152
156
|
diff-lcs (>= 1.2.0, < 2.0)
|
153
157
|
rspec-support (~> 3.13.0)
|
154
158
|
rspec-support (3.13.2)
|
155
|
-
rubocop (1.
|
159
|
+
rubocop (1.75.2)
|
156
160
|
json (~> 2.3)
|
157
|
-
language_server-protocol (
|
161
|
+
language_server-protocol (~> 3.17.0.2)
|
162
|
+
lint_roller (~> 1.1.0)
|
158
163
|
parallel (~> 1.10)
|
159
164
|
parser (>= 3.3.0.2)
|
160
165
|
rainbow (>= 2.2.2, < 4.0)
|
161
166
|
regexp_parser (>= 2.9.3, < 3.0)
|
162
|
-
rubocop-ast (>= 1.
|
167
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
163
168
|
ruby-progressbar (~> 1.7)
|
164
169
|
unicode-display_width (>= 2.4.0, < 4.0)
|
165
|
-
rubocop-ast (1.
|
166
|
-
parser (>= 3.3.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
rubocop (~> 1.
|
171
|
-
rubocop-
|
172
|
-
|
173
|
-
rubocop
|
174
|
-
rubocop-
|
170
|
+
rubocop-ast (1.44.0)
|
171
|
+
parser (>= 3.3.7.2)
|
172
|
+
prism (~> 1.4)
|
173
|
+
rubocop-capybara (2.22.1)
|
174
|
+
lint_roller (~> 1.1)
|
175
|
+
rubocop (~> 1.72, >= 1.72.1)
|
176
|
+
rubocop-factory_bot (2.27.1)
|
177
|
+
lint_roller (~> 1.1)
|
178
|
+
rubocop (~> 1.72, >= 1.72.1)
|
179
|
+
rubocop-performance (1.25.0)
|
180
|
+
lint_roller (~> 1.1)
|
181
|
+
rubocop (>= 1.75.0, < 2.0)
|
182
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
183
|
+
rubocop-rails (2.31.0)
|
175
184
|
activesupport (>= 4.2.0)
|
185
|
+
lint_roller (~> 1.1)
|
176
186
|
rack (>= 1.1)
|
177
|
-
rubocop (>= 1.
|
178
|
-
rubocop-ast (>= 1.
|
179
|
-
rubocop-rake (0.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
rubocop (~> 1.
|
185
|
-
|
187
|
+
rubocop (>= 1.75.0, < 2.0)
|
188
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
189
|
+
rubocop-rake (0.7.1)
|
190
|
+
lint_roller (~> 1.1)
|
191
|
+
rubocop (>= 1.72.1)
|
192
|
+
rubocop-rspec (3.5.0)
|
193
|
+
lint_roller (~> 1.1)
|
194
|
+
rubocop (~> 1.72, >= 1.72.1)
|
195
|
+
rubocop-rspec_rails (2.31.0)
|
196
|
+
lint_roller (~> 1.1)
|
197
|
+
rubocop (~> 1.72, >= 1.72.1)
|
198
|
+
rubocop-rspec (~> 3.5)
|
186
199
|
ruby-prof (1.7.1)
|
187
200
|
ruby-progressbar (1.13.0)
|
188
201
|
ruby2_keywords (0.0.5)
|
@@ -194,6 +207,7 @@ GEM
|
|
194
207
|
rack-protection (= 4.1.1)
|
195
208
|
rack-session (>= 2.0.0, < 3)
|
196
209
|
tilt (~> 2.0)
|
210
|
+
strscan (3.1.2)
|
197
211
|
syntax_tree (6.2.0)
|
198
212
|
prettier_print (>= 1.2.0)
|
199
213
|
syntax_tree-haml (4.0.3)
|
@@ -204,23 +218,25 @@ GEM
|
|
204
218
|
prettier_print
|
205
219
|
syntax_tree (>= 2.0.1)
|
206
220
|
temple (0.10.3)
|
207
|
-
terminal-table (
|
208
|
-
unicode-display_width (>= 1.1.1, <
|
221
|
+
terminal-table (4.0.0)
|
222
|
+
unicode-display_width (>= 1.1.1, < 4)
|
209
223
|
thor (1.3.2)
|
210
|
-
tilt (2.
|
224
|
+
tilt (2.6.0)
|
211
225
|
tzinfo (2.0.6)
|
212
226
|
concurrent-ruby (~> 1.0)
|
213
|
-
unicode-display_width (
|
214
|
-
|
227
|
+
unicode-display_width (3.1.4)
|
228
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
229
|
+
unicode-emoji (4.0.4)
|
230
|
+
uri (1.0.3)
|
215
231
|
w_syntax_tree-erb (0.12.0)
|
216
232
|
prettier_print (~> 1.2, >= 1.2.0)
|
217
233
|
syntax_tree (~> 6.1, >= 6.1.1)
|
218
|
-
webmock (3.
|
234
|
+
webmock (3.25.1)
|
219
235
|
addressable (>= 2.8.0)
|
220
236
|
crack (>= 0.3.2)
|
221
237
|
hashdiff (>= 0.4.0, < 2.0.0)
|
222
238
|
yaml (0.4.0)
|
223
|
-
zeitwerk (2.7.
|
239
|
+
zeitwerk (2.7.2)
|
224
240
|
|
225
241
|
PLATFORMS
|
226
242
|
arm64-darwin-23
|
@@ -245,7 +261,7 @@ DEPENDENCIES
|
|
245
261
|
webmock
|
246
262
|
|
247
263
|
RUBY VERSION
|
248
|
-
ruby 3.
|
264
|
+
ruby 3.4.2p28
|
249
265
|
|
250
266
|
BUNDLED WITH
|
251
|
-
2.6.
|
267
|
+
2.6.7
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.1
|
data/bin/code
CHANGED
@@ -43,17 +43,24 @@ require "ruby-prof" if profile
|
|
43
43
|
|
44
44
|
RubyProf.start if profile
|
45
45
|
|
46
|
+
input = 'loop { print("> ") puts(evaluate(read)) }' if input.blank?
|
47
|
+
|
46
48
|
if parsed.options.parse
|
47
49
|
pp Code::Parser.parse(input).to_raw
|
48
50
|
else
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
begin
|
52
|
+
print(
|
53
|
+
Code.evaluate(
|
54
|
+
input,
|
55
|
+
output: $stdout,
|
56
|
+
error: $stderr,
|
57
|
+
input: $stdin,
|
58
|
+
timeout: parsed.options.timeout
|
59
|
+
)
|
55
60
|
)
|
56
|
-
|
61
|
+
rescue Code::Error => e
|
62
|
+
warn e.message
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
if profile
|
data/code-ruby.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.summary = "a programming language for the internet"
|
7
7
|
s.description = s.summary
|
8
8
|
s.authors = ["Dorian Marié"]
|
9
|
-
s.email = "dorian@dorianmarie.
|
9
|
+
s.email = "dorian@dorianmarie.com"
|
10
10
|
s.files = `git ls-files`.lines.map(&:strip)
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
s.homepage = "https://github.com/dorianmariecom/code-ruby"
|
@@ -27,5 +27,5 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.metadata["rubygems_mfa_required"] = "true"
|
29
29
|
|
30
|
-
s.required_ruby_version = ">= 3.
|
30
|
+
s.required_ruby_version = ">= 3.0"
|
31
31
|
end
|
data/lib/code/concerns/shared.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
module Concerns
|
3
5
|
module Shared
|
4
|
-
|
6
|
+
attr_accessor :raw, :methods
|
5
7
|
|
6
8
|
def call(**args)
|
7
9
|
code_operator = args.fetch(:operator, nil).to_code
|
@@ -101,6 +103,9 @@ class Code
|
|
101
103
|
else
|
102
104
|
code_to_json
|
103
105
|
end
|
106
|
+
when "methods"
|
107
|
+
sig(args)
|
108
|
+
code_methods
|
104
109
|
when "name"
|
105
110
|
sig(args)
|
106
111
|
code_name
|
@@ -124,7 +129,10 @@ class Code
|
|
124
129
|
|
125
130
|
code_context.code_fetch(self)
|
126
131
|
else
|
127
|
-
raise(
|
132
|
+
raise(
|
133
|
+
Error,
|
134
|
+
"#{code_operator.inspect} not defined on #{code_inspect}:#{code_name}"
|
135
|
+
)
|
128
136
|
end
|
129
137
|
end
|
130
138
|
|
@@ -208,8 +216,8 @@ class Code
|
|
208
216
|
keys.to_h { |key| [key, hash.fetch(key)] }
|
209
217
|
end
|
210
218
|
|
211
|
-
def sig(args, &)
|
212
|
-
Type::Sig.sig(args, object: self, &)
|
219
|
+
def sig(args, &block)
|
220
|
+
Type::Sig.sig(args, object: self, &block)
|
213
221
|
|
214
222
|
Object::Nothing.new
|
215
223
|
end
|
@@ -282,62 +290,6 @@ class Code
|
|
282
290
|
code_to_string.code_parameterize
|
283
291
|
end
|
284
292
|
|
285
|
-
def code_falsy?
|
286
|
-
Object::Boolean.new(falsy?)
|
287
|
-
end
|
288
|
-
|
289
|
-
def code_truthy?
|
290
|
-
Object::Boolean.new(truthy?)
|
291
|
-
end
|
292
|
-
|
293
|
-
def code_to_boolean
|
294
|
-
Object::Boolean.new(self)
|
295
|
-
end
|
296
|
-
|
297
|
-
def code_to_class
|
298
|
-
Object::Class.new(self)
|
299
|
-
end
|
300
|
-
|
301
|
-
def code_to_date
|
302
|
-
Object::Date.new(self)
|
303
|
-
end
|
304
|
-
|
305
|
-
def code_to_decimal
|
306
|
-
Object::Decimal.new(self)
|
307
|
-
end
|
308
|
-
|
309
|
-
def code_to_dictionary
|
310
|
-
Object::Dictionary.new(self)
|
311
|
-
end
|
312
|
-
|
313
|
-
def code_to_duration
|
314
|
-
Object::Duration.new(self)
|
315
|
-
end
|
316
|
-
|
317
|
-
def code_to_integer
|
318
|
-
Object::Integer.new(self)
|
319
|
-
end
|
320
|
-
|
321
|
-
def code_to_list
|
322
|
-
Object::List.new(self)
|
323
|
-
end
|
324
|
-
|
325
|
-
def code_to_nothing
|
326
|
-
Object::Nothing.new(self)
|
327
|
-
end
|
328
|
-
|
329
|
-
def code_to_range
|
330
|
-
Object::Range.new(self)
|
331
|
-
end
|
332
|
-
|
333
|
-
def code_to_string
|
334
|
-
Object::String.new(self)
|
335
|
-
end
|
336
|
-
|
337
|
-
def code_to_time
|
338
|
-
Object::Time.new(self)
|
339
|
-
end
|
340
|
-
|
341
293
|
def to_s
|
342
294
|
code_to_string.raw
|
343
295
|
end
|
@@ -411,7 +363,11 @@ class Code
|
|
411
363
|
end
|
412
364
|
|
413
365
|
def code_name
|
414
|
-
Object::String.new(name)
|
366
|
+
Object::String.new(name.to_s.split("::")[2..].join("::"))
|
367
|
+
end
|
368
|
+
|
369
|
+
def code_methods
|
370
|
+
Object::List.new(methods)
|
415
371
|
end
|
416
372
|
end
|
417
373
|
end
|
data/lib/code/concerns.rb
CHANGED
data/lib/code/node/code.rb
CHANGED
data/lib/code/node/dictionary.rb
CHANGED
@@ -4,29 +4,48 @@ class Code
|
|
4
4
|
class Node
|
5
5
|
class Dictionary < Node
|
6
6
|
class KeyValue < Node
|
7
|
+
attr_reader :resolve_key
|
8
|
+
|
7
9
|
def initialize(parsed)
|
8
10
|
return if parsed.blank?
|
9
11
|
|
10
|
-
if parsed.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
if (name_code = parsed.delete(:name_code))
|
13
|
+
if name_code.key?(:code)
|
14
|
+
@key =
|
15
|
+
Node::String.new([{ text: name_code.delete(:name).presence }])
|
16
|
+
@value = Node::Code.new(name_code.delete(:code).presence)
|
17
|
+
@resolve_key = false
|
18
|
+
else
|
19
|
+
@key = Node::Call.new({ name: name_code.delete(:name).presence })
|
20
|
+
@value = @key
|
21
|
+
@resolve_key = true
|
22
|
+
end
|
23
|
+
elsif (statement_code = parsed.delete(:statement_code))
|
24
|
+
@key =
|
25
|
+
Node::Statement.new(statement_code.delete(:statement).presence)
|
17
26
|
|
18
|
-
|
27
|
+
if statement_code.key?(:code)
|
28
|
+
@value = Node::Code.new(statement_code.delete(:code).presence)
|
29
|
+
@resolve_key = false
|
30
|
+
else
|
31
|
+
@value = @key
|
32
|
+
@resolve_key = true
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@key = @value = Node::Code.new(parsed.delete(:code).presence)
|
36
|
+
@resolve_key = true
|
37
|
+
end
|
19
38
|
end
|
20
39
|
|
21
40
|
def evaluate(**args)
|
22
|
-
key = @key&.
|
41
|
+
key = resolve_key? ? @key&.resolve(**args) : @key&.evaluate(**args)
|
42
|
+
key ||= Object::Nothing.new
|
43
|
+
value = @value.evaluate(**args)
|
44
|
+
[key, value]
|
45
|
+
end
|
23
46
|
|
24
|
-
|
25
|
-
|
26
|
-
[key, value]
|
27
|
-
else
|
28
|
-
[key, key]
|
29
|
-
end
|
47
|
+
def resolve_key?
|
48
|
+
!!resolve_key
|
30
49
|
end
|
31
50
|
end
|
32
51
|
|
data/lib/code/object/boolean.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
class Code
|
4
4
|
class Object
|
5
5
|
class Boolean < ::Code::Object
|
6
|
-
def initialize(*args, **_kargs, &)
|
7
|
-
|
6
|
+
def initialize(*args, **_kargs, &_block)
|
7
|
+
self.raw = (args.first.is_an?(Object) ? args.first.truthy? : !!args.first)
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(**args)
|
data/lib/code/object/class.rb
CHANGED
data/lib/code/object/code.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
class Code
|
4
4
|
class Object
|
5
5
|
class Code < Object
|
6
|
-
def initialize(*args, **_kargs, &)
|
7
|
-
|
6
|
+
def initialize(*args, **_kargs, &_block)
|
7
|
+
self.raw =
|
8
8
|
if args.first.is_a?(Node)
|
9
9
|
args.first
|
10
10
|
else
|
@@ -12,6 +12,12 @@ class Code
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.code_evaluate(*args, **globals)
|
16
|
+
code_args = args.to_code
|
17
|
+
|
18
|
+
new(*code_args.raw).code_evaluate(**globals)
|
19
|
+
end
|
20
|
+
|
15
21
|
def code_evaluate(...)
|
16
22
|
raw.evaluate(...)
|
17
23
|
end
|
data/lib/code/object/context.rb
CHANGED