code-ruby 1.5.6 → 1.5.7
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/concerns/shared.rb +33 -6
- data/lib/code/object/date.rb +9 -7
- data/lib/code/object/dictionary.rb +20 -16
- data/lib/code/object/function.rb +4 -3
- data/lib/code/object/list.rb +1 -1
- data/lib/code/object/string.rb +7 -0
- data/lib/code/parser/equality.rb +5 -4
- data/lib/code/parser/name.rb +17 -4
- data/lib/code/parser/negation.rb +2 -2
- data/spec/code_spec.rb +139 -130
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44b144b44b3cff354f959404a790db624dd3c57690b9443c596c1a53e3c128ea
|
4
|
+
data.tar.gz: 3443010c854864268a599a9b0383518c560cdfa055d45a9122630b24d8b1b168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 016fa10fc17de26a7bc94ddfbc5281265d1a80f6281de93f2bb4cb7513060230399cfbfa4173526940adf20608de88904fdd9590defd1f8193bd25b720ab227f
|
7
|
+
data.tar.gz: 6469efaf79c5336ddc26c61ab4c015678425222729317fed8f74b1af8dba932ba0189dce090da88430294eec7bd7acecc834854e1ab2c5b466164eb80a2cd027
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.7
|
data/lib/code/concerns/shared.rb
CHANGED
@@ -16,7 +16,7 @@ class Code
|
|
16
16
|
code_new(*code_arguments.raw)
|
17
17
|
when "!", "not"
|
18
18
|
sig(args)
|
19
|
-
|
19
|
+
code_exclamation_mark
|
20
20
|
when "!=", "different"
|
21
21
|
sig(args) { Object }
|
22
22
|
code_different(code_value)
|
@@ -34,10 +34,13 @@ class Code
|
|
34
34
|
code_exclusive_range(code_value)
|
35
35
|
when "==", "equal"
|
36
36
|
sig(args) { Object }
|
37
|
-
|
37
|
+
code_equal(code_value)
|
38
38
|
when "===", "strict_equal"
|
39
39
|
sig(args) { Object }
|
40
|
-
|
40
|
+
code_strict_equal(code_value)
|
41
|
+
when "!==", "strict_different"
|
42
|
+
sig(args) { Object }
|
43
|
+
code_strict_different(code_value)
|
41
44
|
when "falsy?"
|
42
45
|
sig(args)
|
43
46
|
code_falsy?
|
@@ -109,6 +112,12 @@ class Code
|
|
109
112
|
when "name"
|
110
113
|
sig(args)
|
111
114
|
code_name
|
115
|
+
when "nothing?"
|
116
|
+
sig(args)
|
117
|
+
code_nothing?
|
118
|
+
when "something?"
|
119
|
+
sig(args)
|
120
|
+
code_something?
|
112
121
|
when /=$/
|
113
122
|
sig(args) { Object }
|
114
123
|
|
@@ -166,13 +175,13 @@ class Code
|
|
166
175
|
Object::Boolean.new(self != code_other)
|
167
176
|
end
|
168
177
|
|
169
|
-
def
|
178
|
+
def code_equal(other)
|
170
179
|
code_other = other.to_code
|
171
180
|
|
172
181
|
Object::Boolean.new(self == code_other)
|
173
182
|
end
|
174
183
|
|
175
|
-
def
|
184
|
+
def code_exclamation_mark
|
176
185
|
Object::Boolean.new(falsy?)
|
177
186
|
end
|
178
187
|
|
@@ -198,12 +207,18 @@ class Code
|
|
198
207
|
self
|
199
208
|
end
|
200
209
|
|
201
|
-
def
|
210
|
+
def code_strict_equal(other)
|
202
211
|
code_other = other.to_code
|
203
212
|
|
204
213
|
Object::Boolean.new(self === code_other)
|
205
214
|
end
|
206
215
|
|
216
|
+
def code_strict_different(other)
|
217
|
+
code_other = other.to_code
|
218
|
+
|
219
|
+
Object::Boolean.new(!(self === code_other))
|
220
|
+
end
|
221
|
+
|
207
222
|
def falsy?
|
208
223
|
!truthy?
|
209
224
|
end
|
@@ -302,10 +317,22 @@ class Code
|
|
302
317
|
code_inspect.raw
|
303
318
|
end
|
304
319
|
|
320
|
+
def code_nothing?
|
321
|
+
Boolean.new(nothing?)
|
322
|
+
end
|
323
|
+
|
324
|
+
def code_something?
|
325
|
+
Boolean.new(something?)
|
326
|
+
end
|
327
|
+
|
305
328
|
def nothing?
|
306
329
|
false
|
307
330
|
end
|
308
331
|
|
332
|
+
def something?
|
333
|
+
!nothing?
|
334
|
+
end
|
335
|
+
|
309
336
|
def code_falsy?
|
310
337
|
Object::Boolean.new(falsy?)
|
311
338
|
end
|
data/lib/code/object/date.rb
CHANGED
@@ -141,13 +141,15 @@ class Code
|
|
141
141
|
code_month = month.to_code
|
142
142
|
code_day = day.to_code
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
if code_year.something? || code_month.something? || code_day.something?
|
145
|
+
raw.change(
|
146
|
+
**{
|
147
|
+
year: code_year.raw,
|
148
|
+
month: code_month.raw,
|
149
|
+
day: code_day.raw
|
150
|
+
}.compact
|
151
|
+
)
|
152
|
+
end
|
151
153
|
|
152
154
|
self
|
153
155
|
end
|
@@ -210,7 +210,7 @@ class Code
|
|
210
210
|
raw.any? do |key, value|
|
211
211
|
code_argument
|
212
212
|
.call(
|
213
|
-
arguments: List.new([key, value,
|
213
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
214
214
|
**globals
|
215
215
|
)
|
216
216
|
.truthy?
|
@@ -257,7 +257,7 @@ class Code
|
|
257
257
|
Nothing.new
|
258
258
|
else
|
259
259
|
code_default.call(
|
260
|
-
arguments: List.new([code_first,
|
260
|
+
arguments: List.new([code_first, code_index, self]),
|
261
261
|
**globals
|
262
262
|
)
|
263
263
|
end
|
@@ -298,7 +298,7 @@ class Code
|
|
298
298
|
raw.delete_if.with_index do |(code_key, code_value), index|
|
299
299
|
argument.call(
|
300
300
|
arguments:
|
301
|
-
List.new([code_key, code_value,
|
301
|
+
List.new([code_key, code_value, Integer.new(index), self]),
|
302
302
|
**globals
|
303
303
|
).truthy?
|
304
304
|
end
|
@@ -315,7 +315,7 @@ class Code
|
|
315
315
|
else
|
316
316
|
raw.delete_if.with_index do |(key, value), index|
|
317
317
|
code_argument.call(
|
318
|
-
arguments: List.new([key, value,
|
318
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
319
319
|
**globals
|
320
320
|
).falsy?
|
321
321
|
end
|
@@ -343,7 +343,7 @@ class Code
|
|
343
343
|
|
344
344
|
raw.each.with_index do |(key, value), index|
|
345
345
|
code_argument.call(
|
346
|
-
arguments: List.new([key, value,
|
346
|
+
arguments: List.new([key, value, Integer.new(index), self]),
|
347
347
|
**globals
|
348
348
|
)
|
349
349
|
end
|
@@ -660,17 +660,21 @@ class Code
|
|
660
660
|
code_function = function.to_code
|
661
661
|
|
662
662
|
Dictionary.new(
|
663
|
-
raw
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
663
|
+
raw
|
664
|
+
.map
|
665
|
+
.with_index do |(key, value), index|
|
666
|
+
[
|
667
|
+
key.to_code,
|
668
|
+
code_function.call(
|
669
|
+
arguments:
|
670
|
+
List.new([key.to_code, value.to_code, index.to_code, self]),
|
671
|
+
**globals
|
672
|
+
)
|
673
|
+
]
|
674
|
+
rescue Error::Next => e
|
675
|
+
[key.to_code, e.code_value]
|
676
|
+
end
|
677
|
+
.to_h
|
674
678
|
)
|
675
679
|
end
|
676
680
|
|
data/lib/code/object/function.rb
CHANGED
@@ -41,9 +41,9 @@ class Code
|
|
41
41
|
if code_parameter.regular_splat?
|
42
42
|
code_arguments
|
43
43
|
elsif code_parameter.keyword_splat?
|
44
|
-
code_arguments
|
45
|
-
.
|
46
|
-
|
44
|
+
code_arguments.raw.detect do |code_argument|
|
45
|
+
code_argument.is_a?(Dictionary)
|
46
|
+
end || Dictionary.new
|
47
47
|
elsif code_parameter.keyword?
|
48
48
|
code_arguments
|
49
49
|
.raw
|
@@ -52,6 +52,7 @@ class Code
|
|
52
52
|
code_dictionary.code_has_value?(parameter.code_name).truthy?
|
53
53
|
end
|
54
54
|
&.code_get(parameter.code_name)
|
55
|
+
.to_code
|
55
56
|
else
|
56
57
|
code_arguments.raw[index].to_code
|
57
58
|
end
|
data/lib/code/object/list.rb
CHANGED
data/lib/code/object/string.rb
CHANGED
@@ -52,6 +52,9 @@ class Code
|
|
52
52
|
when "substitute"
|
53
53
|
sig(args) { [String, String.maybe] }
|
54
54
|
code_substitute(*code_arguments.raw)
|
55
|
+
when "upcase"
|
56
|
+
sig(args)
|
57
|
+
code_upcase
|
55
58
|
else
|
56
59
|
super
|
57
60
|
end
|
@@ -61,6 +64,10 @@ class Code
|
|
61
64
|
String.new(raw.downcase)
|
62
65
|
end
|
63
66
|
|
67
|
+
def code_upcase
|
68
|
+
String.new(raw.upcase)
|
69
|
+
end
|
70
|
+
|
64
71
|
def code_include?(value)
|
65
72
|
code_value = value.to_code
|
66
73
|
Boolean.new(raw.include?(code_value.raw))
|
data/lib/code/parser/equality.rb
CHANGED
@@ -19,7 +19,7 @@ class Code
|
|
19
19
|
str("<")
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def exclamation_mark
|
23
23
|
str("!")
|
24
24
|
end
|
25
25
|
|
@@ -32,9 +32,10 @@ class Code
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def operator
|
35
|
-
(
|
36
|
-
(
|
37
|
-
(
|
35
|
+
(exclamation_mark << equal << equal) | (equal << equal << equal) |
|
36
|
+
(equal << equal) | (lesser << equal << greater) |
|
37
|
+
(exclamation_mark << equal) | (equal << tilde) | (tilde << equal) |
|
38
|
+
(exclamation_mark << tilde)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/code/parser/name.rb
CHANGED
@@ -99,7 +99,15 @@ class Code
|
|
99
99
|
str("else")
|
100
100
|
end
|
101
101
|
|
102
|
-
def
|
102
|
+
def exclamation_mark
|
103
|
+
str("!")
|
104
|
+
end
|
105
|
+
|
106
|
+
def question_mark
|
107
|
+
str("?")
|
108
|
+
end
|
109
|
+
|
110
|
+
def reserved_character
|
103
111
|
ampersand | equal | pipe | dot | colon | comma | space | newline |
|
104
112
|
opening_curly_bracket | closing_curly_bracket | opening_parenthesis |
|
105
113
|
closing_parenthesis | opening_square_bracket |
|
@@ -108,11 +116,15 @@ class Code
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def character
|
111
|
-
|
119
|
+
reserved_character.absent << any
|
112
120
|
end
|
113
121
|
|
114
122
|
def separator
|
115
|
-
|
123
|
+
reserved_character | any.absent
|
124
|
+
end
|
125
|
+
|
126
|
+
def special_characters
|
127
|
+
exclamation_mark | question_mark
|
116
128
|
end
|
117
129
|
|
118
130
|
def root
|
@@ -120,7 +132,8 @@ class Code
|
|
120
132
|
begin_keyword << separator
|
121
133
|
).absent << (else_keyword << separator).absent <<
|
122
134
|
(elsif_keyword << separator).absent <<
|
123
|
-
(end_keyword << separator).absent <<
|
135
|
+
(end_keyword << separator).absent <<
|
136
|
+
special_characters.absent << character.repeat(1)
|
124
137
|
end
|
125
138
|
end
|
126
139
|
end
|
data/lib/code/parser/negation.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
class Code
|
4
4
|
class Parser
|
5
5
|
class Negation < Language
|
6
|
-
def
|
6
|
+
def exclamation_mark
|
7
7
|
str("!")
|
8
8
|
end
|
9
9
|
|
@@ -16,7 +16,7 @@ class Code
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def operator
|
19
|
-
|
19
|
+
exclamation_mark | tilde | plus
|
20
20
|
end
|
21
21
|
|
22
22
|
def negation
|
data/spec/code_spec.rb
CHANGED
@@ -4,136 +4,145 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
(
|
7
|
-
|
8
|
-
{}.
|
9
|
-
{}.
|
10
|
-
{}.
|
11
|
-
1.
|
12
|
-
1
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
7
|
+
[
|
8
|
+
"{ a: 1, b: 2 }.transform_values { |key| key.upcase }",
|
9
|
+
"{ a: { b: [1, 2, 3, 4] } }.dig(:a, :b, 2)",
|
10
|
+
"{ a: 1, b: 2 }.transform_values { |key, value, index| index * 2 }",
|
11
|
+
"{ a: 1, b: 2 }.transform_values { |key, value, index, dictionary| dictionary.a }",
|
12
|
+
"sum = (a, b: 2) => { a + b } sum(1)",
|
13
|
+
"Object.new !== Object.new"
|
14
|
+
] +
|
15
|
+
%w[
|
16
|
+
Date.new.change
|
17
|
+
{}.zero?
|
18
|
+
{}.any?
|
19
|
+
{}.many?
|
20
|
+
1.zero?
|
21
|
+
1.any?
|
22
|
+
1.many?
|
23
|
+
1.0.zero?
|
24
|
+
1.0.any?
|
25
|
+
1.0.many?
|
26
|
+
[].zero?
|
27
|
+
[].any?
|
28
|
+
[].many?
|
29
|
+
Base64
|
30
|
+
Base64.new
|
31
|
+
Smtp
|
32
|
+
Smtp.new
|
33
|
+
Time.monday?
|
34
|
+
Time.tuesday?
|
35
|
+
Time.wednesday?
|
36
|
+
Time.thursday?
|
37
|
+
Time.friday?
|
38
|
+
Time.saturday?
|
39
|
+
Time.sunday?
|
40
|
+
Time.now.monday?
|
41
|
+
Time.now.tuesday?
|
42
|
+
Time.now.wednesday?
|
43
|
+
Time.now.thursday?
|
44
|
+
Time.now.friday?
|
45
|
+
Time.now.saturday?
|
46
|
+
Time.now.sunday?
|
47
|
+
Time.now.second
|
48
|
+
Time.now.seconds
|
49
|
+
Time.now.minute
|
50
|
+
Time.now.minutes
|
51
|
+
Time.now.hour
|
52
|
+
Time.now.hours
|
53
|
+
Time.now.day
|
54
|
+
Time.now.days
|
55
|
+
Time.now.month
|
56
|
+
Time.now.months
|
57
|
+
Time.now.year
|
58
|
+
Time.now.years
|
59
|
+
Time.second
|
60
|
+
Time.seconds
|
61
|
+
Time.minute
|
62
|
+
Time.minutes
|
63
|
+
Time.hour
|
64
|
+
Time.hours
|
65
|
+
Time.day
|
66
|
+
Time.days
|
67
|
+
Time.month
|
68
|
+
Time.months
|
69
|
+
Time.year
|
70
|
+
Time.years
|
71
|
+
1.day.ago
|
72
|
+
1.day.from_now
|
73
|
+
1.hour.ago
|
74
|
+
1.hour.from_now
|
75
|
+
2.days.ago
|
76
|
+
2.days.from_now
|
77
|
+
2.hours.ago
|
78
|
+
2.hours.ago.hour
|
79
|
+
2.hours.from_now
|
80
|
+
2.hours.from_now.hour
|
81
|
+
Time.hour
|
82
|
+
Date.hour
|
83
|
+
Boolean.new
|
84
|
+
Boolean.new(true)
|
85
|
+
Boolean.new(false)
|
86
|
+
Class.new
|
87
|
+
Class.new(Boolean)
|
88
|
+
Class.new(Class)
|
89
|
+
Context.new
|
90
|
+
Context.new(a:1)
|
91
|
+
Date.new
|
92
|
+
Date.new.hour
|
93
|
+
Date.new("2024-03-05")
|
94
|
+
Date.new("2024-03-05").hour
|
95
|
+
Date.today
|
96
|
+
Date.yesterday
|
97
|
+
Date.tomorrow
|
98
|
+
Date.tomorrow.hour
|
99
|
+
Decimal.new
|
100
|
+
Decimal.new(0)
|
101
|
+
Decimal.new(1.2)
|
102
|
+
Dictionary.new
|
103
|
+
Dictionary.new(a:1)
|
104
|
+
Duration.new
|
105
|
+
Duration.new(1.day)
|
106
|
+
Duration.new("P1D")
|
107
|
+
Function.new
|
108
|
+
Integer.new
|
109
|
+
Integer.new(0)
|
110
|
+
Integer.new(1)
|
111
|
+
Integer.new(1.2)
|
112
|
+
List.new
|
113
|
+
List.new([])
|
114
|
+
List.new([1,2])
|
115
|
+
Nothing.new
|
116
|
+
Nothing.new(1)
|
117
|
+
Object.new
|
118
|
+
Object.new(1)
|
119
|
+
Range.new
|
120
|
+
Range.new(1,2)
|
121
|
+
Range.new(-1)
|
122
|
+
Range.new(1,2,exclude_end:false)
|
123
|
+
Range.new(1,2,exclude_end:true)
|
124
|
+
String.new
|
125
|
+
String.new(:hello)
|
126
|
+
Time.new
|
127
|
+
Time.new("2024-03-05.06:10:59.UTC")
|
128
|
+
Time.now
|
129
|
+
Time.tomorrow
|
130
|
+
Time.yesterday
|
131
|
+
Time.tomorrow
|
132
|
+
Code.new
|
133
|
+
Parameter.new
|
134
|
+
IdentifierList.new
|
135
|
+
IdentifierList.new([])
|
136
|
+
Time.new(nothing).before?
|
137
|
+
Html.link_to
|
138
|
+
Html.link_to('/')
|
139
|
+
Html.link_to('Home','/')
|
140
|
+
Json.parse('1')
|
141
|
+
Json.parse('[]')
|
142
|
+
Json.parse('{}')
|
143
|
+
Json.parse('random-string')
|
144
|
+
{}["".to_string]
|
145
|
+
] + ["Time.hour >= 6 and Time.hour <= 23"]
|
137
146
|
).each { |input| it(input) { described_class.evaluate(input) } }
|
138
147
|
|
139
148
|
[
|