code-ruby 0.6.1 → 0.6.3
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/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -4
- data/README.md +4 -0
- data/bin/code +3 -12
- data/code-ruby.gemspec +1 -0
- data/lib/code/object/dictionary.rb +15 -3
- data/lib/code/object/function.rb +5 -4
- data/lib/code/object/list.rb +7 -0
- data/lib/code/object/string.rb +1 -1
- data/lib/code/type/hash.rb +3 -7
- data/lib/code/type/sig.rb +10 -4
- data/lib/code/version.rb +1 -1
- data/spec/code/object/function_spec.rb +2 -2
- data/spec/code/object/list_spec.rb +11 -0
- data/spec/code_spec.rb +1 -1
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ab3a0f0749357d4065315d58b613f8d44cba5f567b6ae33444cff90c1dedde0
|
4
|
+
data.tar.gz: b48a0d5c713c0eb33c53bd30fafaaa7bc03f657a7ac7a5c70ae257eedf677cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e137c317b1d87a1a61d30ce70d4bccdd75417ab002c6ad57249081f2e8b8189e4194efaad6e277f68448fa8f55b1402e337d5387d34449b69fce4425b17d72e7
|
7
|
+
data.tar.gz: 2bdfced46d44b0ef4787a998fb17ce073b38a939d044a9f48f39c74dc42adbec3962622792f9852579203f090a66db78dc45aa118d25ff325089cde03cb00c93
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.3.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (0.6.
|
4
|
+
code-ruby (0.6.2)
|
5
|
+
bigdecimal (~> 3)
|
5
6
|
language-ruby (~> 0)
|
6
7
|
zeitwerk (~> 2)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
bigdecimal (3.1.6)
|
11
13
|
diff-lcs (1.5.0)
|
12
14
|
language-ruby (0.6.0)
|
13
15
|
zeitwerk (~> 2)
|
@@ -24,16 +26,20 @@ GEM
|
|
24
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
27
|
rspec-support (~> 3.12.0)
|
26
28
|
rspec-support (3.12.1)
|
27
|
-
ruby-prof (1.
|
29
|
+
ruby-prof (1.7.0)
|
28
30
|
zeitwerk (2.6.12)
|
29
31
|
|
30
32
|
PLATFORMS
|
31
|
-
arm64-darwin-
|
33
|
+
arm64-darwin-23
|
34
|
+
ruby
|
32
35
|
|
33
36
|
DEPENDENCIES
|
34
37
|
code-ruby!
|
35
38
|
rspec
|
36
39
|
ruby-prof
|
37
40
|
|
41
|
+
RUBY VERSION
|
42
|
+
ruby 3.3.0p0
|
43
|
+
|
38
44
|
BUNDLED WITH
|
39
|
-
2.
|
45
|
+
2.5.5
|
data/README.md
CHANGED
data/bin/code
CHANGED
@@ -9,11 +9,7 @@ OptionParser
|
|
9
9
|
.new do |opts|
|
10
10
|
opts.banner = "Usage: template [options]"
|
11
11
|
|
12
|
-
opts.on(
|
13
|
-
"-v",
|
14
|
-
"--version",
|
15
|
-
"Version of template"
|
16
|
-
) do |input|
|
12
|
+
opts.on("-v", "--version", "Version of template") do |input|
|
17
13
|
puts Code::Version
|
18
14
|
exit
|
19
15
|
end
|
@@ -48,10 +44,7 @@ OptionParser
|
|
48
44
|
"Set timeout in seconds"
|
49
45
|
) { |timeout| options[:timeout] = timeout.to_f }
|
50
46
|
|
51
|
-
opts.on(
|
52
|
-
"--profile",
|
53
|
-
"Profile Ruby code"
|
54
|
-
) do |timeout|
|
47
|
+
opts.on("--profile", "Profile Ruby code") do |timeout|
|
55
48
|
require "ruby-prof"
|
56
49
|
options[:profile] = true
|
57
50
|
end
|
@@ -70,9 +63,7 @@ OptionParser
|
|
70
63
|
input = options.fetch(:input, "")
|
71
64
|
context = options.fetch(:context, "")
|
72
65
|
|
73
|
-
if options[:profile]
|
74
|
-
RubyProf.start
|
75
|
-
end
|
66
|
+
RubyProf.start if options[:profile]
|
76
67
|
|
77
68
|
if options[:parse]
|
78
69
|
pp Code::Parser.parse(input).to_raw
|
data/code-ruby.gemspec
CHANGED
@@ -214,7 +214,11 @@ class Code
|
|
214
214
|
|
215
215
|
def code_delete(*arguments, index: Integer.new(0), **globals)
|
216
216
|
default =
|
217
|
-
(
|
217
|
+
(
|
218
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
219
|
+
arguments.last
|
220
|
+
end
|
221
|
+
)
|
218
222
|
|
219
223
|
arguments = arguments[..-2] if default
|
220
224
|
|
@@ -337,7 +341,11 @@ class Code
|
|
337
341
|
|
338
342
|
def code_fetch(*arguments, index: Integer.new(0), **globals)
|
339
343
|
default =
|
340
|
-
(
|
344
|
+
(
|
345
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
346
|
+
arguments.last
|
347
|
+
end
|
348
|
+
)
|
341
349
|
|
342
350
|
arguments = arguments[..-2] if default
|
343
351
|
|
@@ -485,7 +493,11 @@ class Code
|
|
485
493
|
|
486
494
|
def code_merge(*arguments, **globals)
|
487
495
|
conflict =
|
488
|
-
(
|
496
|
+
(
|
497
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
498
|
+
arguments.last
|
499
|
+
end
|
500
|
+
)
|
489
501
|
|
490
502
|
arguments = arguments[..-2] if conflict
|
491
503
|
|
data/lib/code/object/function.rb
CHANGED
@@ -36,9 +36,7 @@ class Code
|
|
36
36
|
if parameter.regular_splat?
|
37
37
|
context.code_set(
|
38
38
|
parameter.name,
|
39
|
-
List.new(
|
40
|
-
arguments.select(&:regular?).map(&:value)
|
41
|
-
)
|
39
|
+
List.new(arguments.select(&:regular?).map(&:value))
|
42
40
|
)
|
43
41
|
elsif parameter.keyword_splat?
|
44
42
|
context.code_set(
|
@@ -53,7 +51,10 @@ class Code
|
|
53
51
|
context.code_set(parameter.name, argument)
|
54
52
|
end
|
55
53
|
elsif parameter.keyword?
|
56
|
-
argument =
|
54
|
+
argument =
|
55
|
+
arguments
|
56
|
+
.detect { |argument| argument.name == parameter.name }
|
57
|
+
&.value
|
57
58
|
argument = parameter.evaluate(**globals) if argument.nil?
|
58
59
|
context.code_set(parameter.name, argument)
|
59
60
|
else
|
data/lib/code/object/list.rb
CHANGED
@@ -71,6 +71,9 @@ class Code
|
|
71
71
|
when "size"
|
72
72
|
sig(args)
|
73
73
|
code_size
|
74
|
+
when "sum"
|
75
|
+
sig(args)
|
76
|
+
code_sum
|
74
77
|
when "uniq"
|
75
78
|
sig(args)
|
76
79
|
code_uniq
|
@@ -197,6 +200,10 @@ class Code
|
|
197
200
|
List.new(raw.uniq)
|
198
201
|
end
|
199
202
|
|
203
|
+
def code_sum
|
204
|
+
raw.inject(&:code_plus) || Nothing.new
|
205
|
+
end
|
206
|
+
|
200
207
|
def inspect
|
201
208
|
to_s
|
202
209
|
end
|
data/lib/code/object/string.rb
CHANGED
data/lib/code/type/hash.rb
CHANGED
@@ -6,7 +6,7 @@ class Code
|
|
6
6
|
attr_reader :hash
|
7
7
|
|
8
8
|
def initialize(hash)
|
9
|
-
@hash = hash
|
9
|
+
@hash = hash.transform_keys { |key| Object::String.new(key) }
|
10
10
|
end
|
11
11
|
|
12
12
|
def valid?(argument)
|
@@ -19,15 +19,11 @@ class Code
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def min_arguments
|
22
|
-
hash.sum
|
23
|
-
min_arguments_of(value)
|
24
|
-
end
|
22
|
+
hash.sum { |_, value| min_arguments_of(value) }
|
25
23
|
end
|
26
24
|
|
27
25
|
def max_arguments
|
28
|
-
hash.sum
|
29
|
-
max_arguments_of(value)
|
30
|
-
end
|
26
|
+
hash.sum { |_, value| max_arguments_of(value) }
|
31
27
|
end
|
32
28
|
|
33
29
|
def name
|
data/lib/code/type/sig.rb
CHANGED
@@ -23,9 +23,10 @@ class Code
|
|
23
23
|
attr_reader :args, :block, :object
|
24
24
|
|
25
25
|
def expected_arguments
|
26
|
-
@expected_arguments ||=
|
27
|
-
|
28
|
-
|
26
|
+
@expected_arguments ||=
|
27
|
+
wrap(block&.call || []).map do |clazz|
|
28
|
+
clazz.is_a?(::Hash) ? Hash.new(clazz) : clazz
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
def min_arguments_of(clazz)
|
@@ -53,7 +54,8 @@ class Code
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def max_arguments
|
56
|
-
max_arguments =
|
57
|
+
max_arguments =
|
58
|
+
expected_arguments.map { |clazz| max_arguments_of(clazz) }
|
57
59
|
max_arguments.include?(nil) ? nil : max_arguments.sum
|
58
60
|
end
|
59
61
|
|
@@ -96,6 +98,10 @@ class Code
|
|
96
98
|
expected.is_a?(Type) ? expected.valid?(actual) : actual.is_a?(expected)
|
97
99
|
end
|
98
100
|
|
101
|
+
def wrap(object)
|
102
|
+
object.is_a?(Array) ? object : [object]
|
103
|
+
end
|
104
|
+
|
99
105
|
def check_types_of_arguments!
|
100
106
|
expected_index = 0
|
101
107
|
repeat_index = 0
|
data/lib/code/version.rb
CHANGED
@@ -19,8 +19,8 @@ RSpec.describe Code::Object::Function do
|
|
19
19
|
context "valid" do
|
20
20
|
[
|
21
21
|
"f = () => {} f",
|
22
|
-
"f = (x) => {} f(1)"
|
23
|
-
# "f = (x:) => {} f(x: 1)"
|
22
|
+
"f = (x) => {} f(1)"
|
23
|
+
# "f = (x:) => {} f(x: 1)"
|
24
24
|
].each do |input|
|
25
25
|
it "#{input} is valid" do
|
26
26
|
Code.evaluate(input)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe Code::Object::List do
|
6
|
+
[["[] == []", "true"], ["[1, 2, 3].sum", "6"]].each do |input, expected|
|
7
|
+
it "#{input} == #{expected}" do
|
8
|
+
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/code_spec.rb
CHANGED
@@ -109,7 +109,7 @@ RSpec.describe Code do
|
|
109
109
|
['"Hello \\{name}"', '"Hello \\{" + "name}"'],
|
110
110
|
["'Hello {1}'", '"Hello 1"'],
|
111
111
|
['"Hello {1}"', '"Hello 1"'],
|
112
|
-
|
112
|
+
[":Hello.include?(a: :H)", true],
|
113
113
|
%w["Hello".downcase :hello],
|
114
114
|
["true ? 1", "1"],
|
115
115
|
["false ? 1", ""],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bigdecimal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
41
55
|
description: 'A programming language, like Code.evaluate("1 + 1") # => 2'
|
42
56
|
email: dorian@dorianmarie.fr
|
43
57
|
executables:
|
@@ -45,7 +59,10 @@ executables:
|
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
62
|
+
- ".gitignore"
|
48
63
|
- ".rspec"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".tool-versions"
|
49
66
|
- Gemfile
|
50
67
|
- Gemfile.lock
|
51
68
|
- README.md
|
@@ -154,6 +171,7 @@ files:
|
|
154
171
|
- spec/code/object/dictionary_spec.rb
|
155
172
|
- spec/code/object/function_spec.rb
|
156
173
|
- spec/code/object/integer_spec.rb
|
174
|
+
- spec/code/object/list_spec.rb
|
157
175
|
- spec/code/object/nothing_spec.rb
|
158
176
|
- spec/code/object/range_spec.rb
|
159
177
|
- spec/code/parser/boolean_spec.rb
|
@@ -188,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
206
|
- !ruby/object:Gem::Version
|
189
207
|
version: '0'
|
190
208
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
209
|
+
rubygems_version: 3.5.5
|
192
210
|
signing_key:
|
193
211
|
specification_version: 4
|
194
212
|
summary: A programming language
|
@@ -199,6 +217,7 @@ test_files:
|
|
199
217
|
- spec/code/object/dictionary_spec.rb
|
200
218
|
- spec/code/object/function_spec.rb
|
201
219
|
- spec/code/object/integer_spec.rb
|
220
|
+
- spec/code/object/list_spec.rb
|
202
221
|
- spec/code/object/nothing_spec.rb
|
203
222
|
- spec/code/object/range_spec.rb
|
204
223
|
- spec/code/parser/boolean_spec.rb
|