code-ruby 2.0.0 → 2.0.2
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/node/code.rb +5 -0
- data/lib/code/object/class.rb +4 -0
- data/lib/code/object/function.rb +35 -1
- data/lib/code/parser/call.rb +6 -2
- data/lib/code/parser/dictionary.rb +5 -1
- data/lib/code/parser/function.rb +5 -1
- data/lib/code/parser/label_name.rb +14 -0
- data/lib/code/parser/string.rb +5 -1
- data/spec/code/node/call_spec.rb +10 -0
- data/spec/code/parser/dictionary_spec.rb +2 -1
- data/spec/code/parser/function_spec.rb +2 -1
- data/spec/code_spec.rb +5 -7
- metadata +2 -2
- data/spec/code/object/http_spec.rb +0 -99
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26d4b2a42933e4c3b408c6363ecbd343c106e117d469e196f5088c5db5ecfb8f
|
|
4
|
+
data.tar.gz: a888fd3dc5f2987dae06dffe0df43f00ca3c031404e48390d53d201078224808
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c3f838b4cdd9a17c18ad194dd035e281b64d8ff9c536e935f903dfbd8d6a82e64fcb04ae37d8ed0f49e764269f4d70d8f0ca44d3d6314c9bd5fe13864cb88df
|
|
7
|
+
data.tar.gz: 42435bd8fafc85bdfb3b4fd6af6b033942f7bb4e03e49e6ddc93079e2caeb6bbd08dc33214d79e2324abfb528be1debe6c82600ffebf84601a21e6a54c997e77
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.0.
|
|
1
|
+
2.0.2
|
data/lib/code/node/code.rb
CHANGED
|
@@ -6,6 +6,7 @@ class Code
|
|
|
6
6
|
def initialize(parsed)
|
|
7
7
|
return if parsed.blank?
|
|
8
8
|
|
|
9
|
+
@parsed = parsed.deep_dup
|
|
9
10
|
@statements =
|
|
10
11
|
(parsed.presence || []).map { |statement| Statement.new(statement) }
|
|
11
12
|
end
|
|
@@ -57,6 +58,10 @@ class Code
|
|
|
57
58
|
def to_code
|
|
58
59
|
@statements.blank? ? Object::Nothing.new : Object::Code.new(self)
|
|
59
60
|
end
|
|
61
|
+
|
|
62
|
+
def to_raw
|
|
63
|
+
@parsed.deep_dup
|
|
64
|
+
end
|
|
60
65
|
end
|
|
61
66
|
end
|
|
62
67
|
end
|
data/lib/code/object/class.rb
CHANGED
data/lib/code/object/function.rb
CHANGED
|
@@ -152,7 +152,18 @@ class Code
|
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
def code_to_string
|
|
155
|
-
String.new(
|
|
155
|
+
String.new(
|
|
156
|
+
Format.format(
|
|
157
|
+
[
|
|
158
|
+
{
|
|
159
|
+
function: {
|
|
160
|
+
parameters: code_parameters.raw.map { |parameter| parameter_to_raw(parameter) },
|
|
161
|
+
body: code_body.raw.to_raw
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
)
|
|
166
|
+
)
|
|
156
167
|
end
|
|
157
168
|
|
|
158
169
|
def code_extend(function)
|
|
@@ -202,6 +213,29 @@ class Code
|
|
|
202
213
|
|
|
203
214
|
nil
|
|
204
215
|
end
|
|
216
|
+
|
|
217
|
+
def parameter_to_raw(parameter)
|
|
218
|
+
code_parameter = parameter.to_code
|
|
219
|
+
raw_parameter = { name: code_parameter.code_name.to_s }
|
|
220
|
+
|
|
221
|
+
if code_parameter.keyword?
|
|
222
|
+
raw_parameter[:keyword] = ":"
|
|
223
|
+
elsif code_parameter.keyword_splat?
|
|
224
|
+
raw_parameter[:keyword_splat] = "**"
|
|
225
|
+
elsif code_parameter.regular_splat?
|
|
226
|
+
raw_parameter[:regular_splat] = "*"
|
|
227
|
+
elsif code_parameter.block?
|
|
228
|
+
raw_parameter[:block] = "&"
|
|
229
|
+
elsif code_parameter.spread?
|
|
230
|
+
raw_parameter[:spread] = "..."
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
unless code_parameter.code_default.nothing?
|
|
234
|
+
raw_parameter[:default] = code_parameter.code_default.code_to_string.raw == "nothing" ? [] : Code.parse(code_parameter.code_default.to_s)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
raw_parameter
|
|
238
|
+
end
|
|
205
239
|
end
|
|
206
240
|
end
|
|
207
241
|
end
|
data/lib/code/parser/call.rb
CHANGED
|
@@ -7,6 +7,10 @@ class Code
|
|
|
7
7
|
Name
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def label_name
|
|
11
|
+
LabelName
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def whitespace
|
|
11
15
|
Whitespace
|
|
12
16
|
end
|
|
@@ -88,7 +92,7 @@ class Code
|
|
|
88
92
|
end
|
|
89
93
|
|
|
90
94
|
def keyword_argument
|
|
91
|
-
|
|
95
|
+
label_name.aka(:name) << whitespace? << colon << code.aka(:value)
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
def regular_argument
|
|
@@ -114,7 +118,7 @@ class Code
|
|
|
114
118
|
end
|
|
115
119
|
|
|
116
120
|
def keyword_parameter
|
|
117
|
-
|
|
121
|
+
label_name.aka(:name) << whitespace? << colon.aka(:keyword) <<
|
|
118
122
|
code_present.aka(:default).maybe
|
|
119
123
|
end
|
|
120
124
|
|
|
@@ -15,6 +15,10 @@ class Code
|
|
|
15
15
|
Name
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def label_name
|
|
19
|
+
LabelName
|
|
20
|
+
end
|
|
21
|
+
|
|
18
22
|
def whitespace
|
|
19
23
|
Whitespace
|
|
20
24
|
end
|
|
@@ -48,7 +52,7 @@ class Code
|
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
def key_value
|
|
51
|
-
(
|
|
55
|
+
(label_name.aka(:name) << colon << code_present.aka(:code).maybe).aka(
|
|
52
56
|
:name_code
|
|
53
57
|
) |
|
|
54
58
|
(
|
data/lib/code/parser/function.rb
CHANGED
|
@@ -7,6 +7,10 @@ class Code
|
|
|
7
7
|
Name
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def label_name
|
|
11
|
+
LabelName
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def code
|
|
11
15
|
Code
|
|
12
16
|
end
|
|
@@ -90,7 +94,7 @@ class Code
|
|
|
90
94
|
end
|
|
91
95
|
|
|
92
96
|
def keyword_parameter
|
|
93
|
-
|
|
97
|
+
label_name.aka(:name) << whitespace? << colon.aka(:keyword) <<
|
|
94
98
|
code_present.aka(:default).maybe
|
|
95
99
|
end
|
|
96
100
|
|
data/lib/code/parser/string.rb
CHANGED
|
@@ -11,6 +11,10 @@ class Code
|
|
|
11
11
|
Name
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def label_name
|
|
15
|
+
LabelName
|
|
16
|
+
end
|
|
17
|
+
|
|
14
18
|
def single_quote
|
|
15
19
|
str("'")
|
|
16
20
|
end
|
|
@@ -69,7 +73,7 @@ class Code
|
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
def symbol
|
|
72
|
-
(colon.ignore <<
|
|
76
|
+
(colon.ignore << label_name).aka(:text).repeat(1, 1)
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
def root
|
data/spec/code/node/call_spec.rb
CHANGED
data/spec/code_spec.rb
CHANGED
|
@@ -173,6 +173,7 @@ RSpec.describe Code do
|
|
|
173
173
|
"(user = { name: :Dorian, age: 31 }).transform_values { user.name }.age",
|
|
174
174
|
":Dorian"
|
|
175
175
|
],
|
|
176
|
+
["{ end: 2 }.keys.first", ":end"],
|
|
176
177
|
%w[!!1 true],
|
|
177
178
|
%w[!!true true],
|
|
178
179
|
%w[!false true],
|
|
@@ -239,6 +240,9 @@ RSpec.describe Code do
|
|
|
239
240
|
%w[Class(Time) Time],
|
|
240
241
|
%w[Class(nothing) Nothing],
|
|
241
242
|
%w[Class(true) Boolean],
|
|
243
|
+
%w[String String],
|
|
244
|
+
%w[Time Time],
|
|
245
|
+
%w[Class Class],
|
|
242
246
|
%w[Class.new Nothing],
|
|
243
247
|
%w[Class.new Nothing],
|
|
244
248
|
%w[Class.new(2.days.ago) Time],
|
|
@@ -331,15 +335,9 @@ RSpec.describe Code do
|
|
|
331
335
|
["a = 0 [1, 2, 3].each { |i| next if i == 2 a += i } a", "4"],
|
|
332
336
|
["a = 0\nb = 0\nwhile a < 4\n a += 1\n continue if a == 2\n b += a\nend\nb", "8"],
|
|
333
337
|
["a = 0 loop a += 1 break end a", "1"],
|
|
334
|
-
["a = 1\nbegin\n a += 1\n break if a > 3\n retry\nend\na", "4"],
|
|
335
338
|
["x = loop break(42) end x", "42"],
|
|
336
|
-
["a = 0 a += 1 retry if a < 3 a", "3"],
|
|
337
339
|
["a = 0\nuntil a > 10 a += 1 end a", "11"],
|
|
338
340
|
["a = 0\nwhile a < 10 a += 1 end a", "10"],
|
|
339
|
-
[
|
|
340
|
-
"a = 0\nretried = false\nwhile a < 2\n a += 1\n retry if a == 1 && !retried && (retried = true)\nend\na",
|
|
341
|
-
"2"
|
|
342
|
-
],
|
|
343
341
|
["a = 1 3.times { a += 1 } a", "4"],
|
|
344
342
|
["a = 1 a *= 2 a", "2"],
|
|
345
343
|
["a = 1 a += 1 a", "2"],
|
|
@@ -377,7 +375,6 @@ RSpec.describe Code do
|
|
|
377
375
|
["next(7)", "7"],
|
|
378
376
|
["not not false", "false"],
|
|
379
377
|
["not true", "false"],
|
|
380
|
-
["retry(8)", "8"],
|
|
381
378
|
["return(9)", "9"],
|
|
382
379
|
["f = () => { return(3) 4 } f()", "3"],
|
|
383
380
|
["a = 1 orirginal = 2 orirginal", "2"],
|
|
@@ -488,6 +485,7 @@ RSpec.describe Code do
|
|
|
488
485
|
["", ""]
|
|
489
486
|
].each do |input, expected|
|
|
490
487
|
it "#{input} == #{expected}" do
|
|
488
|
+
puts input
|
|
491
489
|
formatted = format_input(input)
|
|
492
490
|
|
|
493
491
|
output = StringIO.new
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -306,6 +306,7 @@ files:
|
|
|
306
306
|
- lib/code/parser/group.rb
|
|
307
307
|
- lib/code/parser/if.rb
|
|
308
308
|
- lib/code/parser/if_modifier.rb
|
|
309
|
+
- lib/code/parser/label_name.rb
|
|
309
310
|
- lib/code/parser/left_operation.rb
|
|
310
311
|
- lib/code/parser/list.rb
|
|
311
312
|
- lib/code/parser/multiplication.rb
|
|
@@ -346,7 +347,6 @@ files:
|
|
|
346
347
|
- spec/code/object/decimal_spec.rb
|
|
347
348
|
- spec/code/object/dictionary_spec.rb
|
|
348
349
|
- spec/code/object/function_spec.rb
|
|
349
|
-
- spec/code/object/http_spec.rb
|
|
350
350
|
- spec/code/object/identifier_list_spec.rb
|
|
351
351
|
- spec/code/object/integer_spec.rb
|
|
352
352
|
- spec/code/object/list_spec.rb
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Code::Object::Http do
|
|
6
|
-
def self.verbs
|
|
7
|
-
%w[get head post put delete options trace patch]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.response_codes
|
|
11
|
-
{
|
|
12
|
-
continue: 100,
|
|
13
|
-
switching_protocols: 101,
|
|
14
|
-
processing: 102,
|
|
15
|
-
early_hints: 103,
|
|
16
|
-
ok: 200,
|
|
17
|
-
created: 201,
|
|
18
|
-
accepted: 202,
|
|
19
|
-
non_authoritative_information: 203,
|
|
20
|
-
no_content: 204,
|
|
21
|
-
reset_content: 205,
|
|
22
|
-
partial_content: 206,
|
|
23
|
-
multi_status: 207,
|
|
24
|
-
already_reported: 208,
|
|
25
|
-
im_used: 226,
|
|
26
|
-
multiple_choices: 300,
|
|
27
|
-
moved_permanently: 301,
|
|
28
|
-
found: 302,
|
|
29
|
-
see_other: 303,
|
|
30
|
-
not_modified: 304,
|
|
31
|
-
use_proxy: 305,
|
|
32
|
-
reserved: 306,
|
|
33
|
-
temporary_redirect: 307,
|
|
34
|
-
permanent_redirect: 308,
|
|
35
|
-
bad_request: 400,
|
|
36
|
-
unauthorized: 401,
|
|
37
|
-
payment_required: 402,
|
|
38
|
-
forbidden: 403,
|
|
39
|
-
not_found: 404,
|
|
40
|
-
method_not_allowed: 405,
|
|
41
|
-
not_acceptable: 406,
|
|
42
|
-
proxy_authentication_required: 407,
|
|
43
|
-
request_timeout: 408,
|
|
44
|
-
conflict: 409,
|
|
45
|
-
gone: 410,
|
|
46
|
-
length_required: 411,
|
|
47
|
-
precondition_failed: 412,
|
|
48
|
-
request_entity_too_large: 413,
|
|
49
|
-
request_uri_too_long: 414,
|
|
50
|
-
unsupported_media_type: 415,
|
|
51
|
-
requested_range_not_satisfiable: 416,
|
|
52
|
-
expectation_failed: 417,
|
|
53
|
-
misdirected_request: 421,
|
|
54
|
-
unprocessable_entity: 422,
|
|
55
|
-
locked: 423,
|
|
56
|
-
failed_dependency: 424,
|
|
57
|
-
too_early: 425,
|
|
58
|
-
upgrade_required: 426,
|
|
59
|
-
precondition_required: 428,
|
|
60
|
-
too_many_requests: 429,
|
|
61
|
-
request_header_fields_too_large: 431,
|
|
62
|
-
unavailable_for_legal_reasons: 451,
|
|
63
|
-
internal_server_error: 500,
|
|
64
|
-
not_implemented: 501,
|
|
65
|
-
bad_gateway: 502,
|
|
66
|
-
service_unavailable: 503,
|
|
67
|
-
gateway_timeout: 504,
|
|
68
|
-
http_version_not_supported: 505,
|
|
69
|
-
variant_also_negotiates: 506,
|
|
70
|
-
insufficient_storage: 507,
|
|
71
|
-
loop_detected: 508,
|
|
72
|
-
bandwidth_limit_exceeded: 509,
|
|
73
|
-
not_extended: 510,
|
|
74
|
-
network_authentication_required: 511
|
|
75
|
-
}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
verbs.each do |verb|
|
|
79
|
-
describe ".#{verb}" do
|
|
80
|
-
response_codes.each do |status, code|
|
|
81
|
-
it "returns #{code} as code and #{status} as status" do
|
|
82
|
-
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
|
83
|
-
response = Http.#{verb}("https://httpbin.org/status/#{code}")
|
|
84
|
-
[response.code, response.status]
|
|
85
|
-
INPUT
|
|
86
|
-
[#{code}, "#{status}"]
|
|
87
|
-
OUTPUT
|
|
88
|
-
|
|
89
|
-
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
|
90
|
-
response = Http.fetch("#{verb}", "https://httpbin.org/status/#{code}")
|
|
91
|
-
[response.code, response.status]
|
|
92
|
-
INPUT
|
|
93
|
-
[#{code}, "#{status}"]
|
|
94
|
-
OUTPUT
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|