code-ruby 1.5.7 → 1.6.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/.rubocop.yml +2 -0
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/docs/precedence.txt +36 -0
- data/lib/code/node/if.rb +5 -0
- data/lib/code/object/date.rb +670 -46
- data/lib/code/object/decimal.rb +722 -78
- data/lib/code/object/dictionary.rb +415 -44
- data/lib/code/object/global.rb +8 -1
- data/lib/code/object/http.rb +1 -1
- data/lib/code/object/integer.rb +724 -87
- data/lib/code/object/list.rb +545 -101
- data/lib/code/object/number.rb +8 -0
- data/lib/code/object/parameter.rb +7 -11
- data/lib/code/object/range.rb +5 -0
- data/lib/code/object/string.rb +7 -0
- data/lib/code/object/time.rb +647 -116
- data/lib/code/parser/equal.rb +1 -1
- data/lib/code/parser/equality.rb +1 -1
- data/lib/code/parser/if.rb +7 -2
- data/lib/code/parser/name.rb +41 -6
- data/lib/code.rb +1 -1
- data/spec/code/object/decimal_spec.rb +0 -1
- data/spec/code/object/http_spec.rb +72 -68
- data/spec/code/object/integer_spec.rb +0 -1
- data/spec/code/parser/if_modifier_spec.rb +2 -2
- data/spec/code_spec.rb +3 -2
- metadata +4 -2
data/lib/code/parser/equal.rb
CHANGED
data/lib/code/parser/equality.rb
CHANGED
@@ -32,7 +32,7 @@ class Code
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def operator
|
35
|
-
(exclamation_mark
|
35
|
+
(exclamation_mark << equal << equal) | (equal << equal << equal) |
|
36
36
|
(equal << equal) | (lesser << equal << greater) |
|
37
37
|
(exclamation_mark << equal) | (equal << tilde) | (tilde << equal) |
|
38
38
|
(exclamation_mark << tilde)
|
data/lib/code/parser/if.rb
CHANGED
@@ -51,6 +51,10 @@ class Code
|
|
51
51
|
str("elsif")
|
52
52
|
end
|
53
53
|
|
54
|
+
def elsunless_keyword
|
55
|
+
str("elsunless")
|
56
|
+
end
|
57
|
+
|
54
58
|
def else_keyword
|
55
59
|
str("else")
|
56
60
|
end
|
@@ -76,8 +80,9 @@ class Code
|
|
76
80
|
statement.aka(:first_statement) << body.aka(:first_body) <<
|
77
81
|
(
|
78
82
|
(
|
79
|
-
elsif_keyword.aka(
|
80
|
-
|
83
|
+
(elsif_keyword | elsunless_keyword).aka(
|
84
|
+
:operator
|
85
|
+
) << whitespace << statement.aka(:statement) << body.aka(:body)
|
81
86
|
) |
|
82
87
|
(
|
83
88
|
else_keyword << whitespace <<
|
data/lib/code/parser/name.rb
CHANGED
@@ -99,6 +99,38 @@ class Code
|
|
99
99
|
str("else")
|
100
100
|
end
|
101
101
|
|
102
|
+
def while_keyword
|
103
|
+
str("while")
|
104
|
+
end
|
105
|
+
|
106
|
+
def until_keyword
|
107
|
+
str("until")
|
108
|
+
end
|
109
|
+
|
110
|
+
def if_keyword
|
111
|
+
str("if")
|
112
|
+
end
|
113
|
+
|
114
|
+
def unless_keyword
|
115
|
+
str("unless")
|
116
|
+
end
|
117
|
+
|
118
|
+
def elsunless_keyword
|
119
|
+
str("elsunless")
|
120
|
+
end
|
121
|
+
|
122
|
+
def true_keyword
|
123
|
+
str("true")
|
124
|
+
end
|
125
|
+
|
126
|
+
def false_keyword
|
127
|
+
str("false")
|
128
|
+
end
|
129
|
+
|
130
|
+
def nothing_keyword
|
131
|
+
str("nothing")
|
132
|
+
end
|
133
|
+
|
102
134
|
def exclamation_mark
|
103
135
|
str("!")
|
104
136
|
end
|
@@ -127,13 +159,16 @@ class Code
|
|
127
159
|
exclamation_mark | question_mark
|
128
160
|
end
|
129
161
|
|
162
|
+
def keyword
|
163
|
+
do_keyword | begin_keyword | end_keyword | while_keyword |
|
164
|
+
until_keyword | if_keyword | elsif_keyword | else_keyword |
|
165
|
+
unless_keyword | elsunless_keyword | true_keyword | false_keyword |
|
166
|
+
nothing_keyword
|
167
|
+
end
|
168
|
+
|
130
169
|
def root
|
131
|
-
(
|
132
|
-
|
133
|
-
).absent << (else_keyword << separator).absent <<
|
134
|
-
(elsif_keyword << separator).absent <<
|
135
|
-
(end_keyword << separator).absent <<
|
136
|
-
special_characters.absent << character.repeat(1)
|
170
|
+
(keyword << separator).absent << special_characters.absent <<
|
171
|
+
character.repeat(1)
|
137
172
|
end
|
138
173
|
end
|
139
174
|
end
|
data/lib/code.rb
CHANGED
@@ -3,77 +3,81 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Code::Object::Http do
|
6
|
-
|
6
|
+
def self.verbs
|
7
|
+
%w[get head post put delete options trace patch]
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
73
77
|
|
74
|
-
|
78
|
+
verbs.each do |verb|
|
75
79
|
describe ".#{verb}" do
|
76
|
-
|
80
|
+
response_codes.each do |status, code|
|
77
81
|
it "returns #{code} as code and #{status} as status" do
|
78
82
|
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
79
83
|
response = Http.#{verb}("https://httpbin.org/status/#{code}")
|
@@ -8,8 +8,8 @@ RSpec.describe Code::Parser::IfModifier do
|
|
8
8
|
["1 if false", "nothing"],
|
9
9
|
["1 unless true", "nothing"],
|
10
10
|
["1 unless false", "1"],
|
11
|
-
["a = 0 a += 1 while a < 10 a", "10"],
|
12
|
-
["a = 0 a += 1 until a > 10 a", "11"]
|
11
|
+
["a = 0 (a += 1) while a < 10 a", "10"],
|
12
|
+
["a = 0 (a += 1) until a > 10 a", "11"]
|
13
13
|
].each do |input, expected|
|
14
14
|
it "#{input} == #{expected}" do
|
15
15
|
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
data/spec/code_spec.rb
CHANGED
@@ -13,6 +13,7 @@ RSpec.describe Code do
|
|
13
13
|
"Object.new !== Object.new"
|
14
14
|
] +
|
15
15
|
%w[
|
16
|
+
:abc.size
|
16
17
|
Date.new.change
|
17
18
|
{}.zero?
|
18
19
|
{}.any?
|
@@ -267,8 +268,8 @@ RSpec.describe Code do
|
|
267
268
|
["Class(true, 1)", "Boolean"],
|
268
269
|
["Class.new(Boolean, Time)", "Boolean"],
|
269
270
|
["Class.new(Time, Boolean)", "Time"],
|
270
|
-
[
|
271
|
-
[
|
271
|
+
['Date("2024-3-2").to_string', ":2024-03-02"],
|
272
|
+
['Date("2024-3-2").to_string', ":2024-03-02"],
|
272
273
|
["Decimal(1, :2)", "100"],
|
273
274
|
["Decimal(:1, 2)", "100.0"],
|
274
275
|
["Decimal.new(1, :2)", "100"],
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-06-
|
10
|
+
date: 2025-06-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- bin/rubocop
|
224
224
|
- bin/test
|
225
225
|
- code-ruby.gemspec
|
226
|
+
- docs/precedence.txt
|
226
227
|
- lib/code-ruby.rb
|
227
228
|
- lib/code.rb
|
228
229
|
- lib/code/concerns.rb
|
@@ -275,6 +276,7 @@ files:
|
|
275
276
|
- lib/code/object/json.rb
|
276
277
|
- lib/code/object/list.rb
|
277
278
|
- lib/code/object/nothing.rb
|
279
|
+
- lib/code/object/number.rb
|
278
280
|
- lib/code/object/parameter.rb
|
279
281
|
- lib/code/object/range.rb
|
280
282
|
- lib/code/object/smtp.rb
|