code-ruby 0.6.0 → 0.6.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 +1 -0
- data/Gemfile.lock +8 -3
- data/README.md +7 -0
- data/bin/code +94 -0
- data/code-ruby.gemspec +2 -0
- data/lib/code/object/list.rb +7 -0
- data/lib/code/version.rb +1 -1
- data/spec/code/object/list_spec.rb +14 -0
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63a5dc762c3ac1d5e2f37910c24806b092a78f0bc8ed5ad4409f2e6283f7880
|
4
|
+
data.tar.gz: 5cd2966db552e1b06a7946767af43005a670dbe76378e8680524af6abf3a2479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d364133a93859542602ac10730d4b539e2e090e7b91fa9ffacfec1602edc5701da4ab8c6d1208e6e9a1967983ea2c62d80fbf7aab6df62141da332199ed7796
|
7
|
+
data.tar.gz: ad10fe135a0391fa37d769282b13a1fa7b1423a9226daa147553d91ee0d61f03f8b49d6e7b1c0514709bbf0cb03fe6c64db9ea7a71b10b9761cdcc1cdc95f2a1
|
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.1)
|
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,14 +26,17 @@ GEM
|
|
24
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
27
|
rspec-support (~> 3.12.0)
|
26
28
|
rspec-support (3.12.1)
|
29
|
+
ruby-prof (1.7.0)
|
27
30
|
zeitwerk (2.6.12)
|
28
31
|
|
29
32
|
PLATFORMS
|
30
|
-
arm64-darwin-
|
33
|
+
arm64-darwin-23
|
34
|
+
ruby
|
31
35
|
|
32
36
|
DEPENDENCIES
|
33
37
|
code-ruby!
|
34
38
|
rspec
|
39
|
+
ruby-prof
|
35
40
|
|
36
41
|
BUNDLED WITH
|
37
|
-
2.
|
42
|
+
2.5.5
|
data/README.md
ADDED
data/bin/code
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require_relative "../lib/code-ruby"
|
5
|
+
|
6
|
+
options = { timeout: 0, profile: false, profiler: "text" }
|
7
|
+
|
8
|
+
OptionParser
|
9
|
+
.new do |opts|
|
10
|
+
opts.banner = "Usage: template [options]"
|
11
|
+
|
12
|
+
opts.on(
|
13
|
+
"-v",
|
14
|
+
"--version",
|
15
|
+
"Version of template"
|
16
|
+
) do |input|
|
17
|
+
puts Code::Version
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on(
|
22
|
+
"-i INPUT",
|
23
|
+
"--input=INPUT",
|
24
|
+
"Input in the code language (String or File)"
|
25
|
+
) do |input|
|
26
|
+
input = File.read(input) if File.exist?(input)
|
27
|
+
|
28
|
+
options[:input] = input
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on(
|
32
|
+
"-c CONTEXT",
|
33
|
+
"--context=CONTEXT",
|
34
|
+
"Context in the code language (String or File)"
|
35
|
+
) do |context|
|
36
|
+
context = File.read(context) if File.exist?(context)
|
37
|
+
|
38
|
+
options[:context] = context
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-p", "--parse", "Get parser results for input") do |parse|
|
42
|
+
options[:parse] = parse
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on(
|
46
|
+
"-t TIMEOUT",
|
47
|
+
"--timeout=TIMEOUT",
|
48
|
+
"Set timeout in seconds"
|
49
|
+
) { |timeout| options[:timeout] = timeout.to_f }
|
50
|
+
|
51
|
+
opts.on(
|
52
|
+
"--profile",
|
53
|
+
"Profile Ruby code"
|
54
|
+
) do |timeout|
|
55
|
+
require "ruby-prof"
|
56
|
+
options[:profile] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on(
|
60
|
+
"--profiler TYPE",
|
61
|
+
"Profiler output type (text (default) or html)"
|
62
|
+
) do |profiler|
|
63
|
+
require "ruby-prof"
|
64
|
+
options[:profile] = true
|
65
|
+
options[:profiler] = profiler
|
66
|
+
end
|
67
|
+
end
|
68
|
+
.parse!
|
69
|
+
|
70
|
+
input = options.fetch(:input, "")
|
71
|
+
context = options.fetch(:context, "")
|
72
|
+
|
73
|
+
if options[:profile]
|
74
|
+
RubyProf.start
|
75
|
+
end
|
76
|
+
|
77
|
+
if options[:parse]
|
78
|
+
pp Code::Parser.parse(input).to_raw
|
79
|
+
else
|
80
|
+
print Code.evaluate(input, context, io: $stdout, timeout: options[:timeout])
|
81
|
+
end
|
82
|
+
|
83
|
+
if options[:profile]
|
84
|
+
result = RubyProf.stop
|
85
|
+
if options[:profiler] == "text"
|
86
|
+
printer = RubyProf::FlatPrinter.new(result)
|
87
|
+
printer.print($stdout)
|
88
|
+
elsif options[:profiler] == "html"
|
89
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
90
|
+
printer.print($stdout)
|
91
|
+
else
|
92
|
+
abort "#{options[:profiler]} not recognized"
|
93
|
+
end
|
94
|
+
end
|
data/code-ruby.gemspec
CHANGED
@@ -12,7 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.homepage = "https://github.com/dorianmariefr/code-ruby"
|
14
14
|
s.license = "MIT"
|
15
|
+
s.executables = "code"
|
15
16
|
|
16
17
|
s.add_dependency "zeitwerk", "~> 2"
|
17
18
|
s.add_dependency "language-ruby", "~> 0"
|
19
|
+
s.add_dependency "bigdecimal", "~> 3"
|
18
20
|
end
|
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/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe Code::Object::List do
|
6
|
+
[
|
7
|
+
["[] == []", "true"],
|
8
|
+
["[1, 2, 3].sum", "6"],
|
9
|
+
].each do |input, expected|
|
10
|
+
it "#{input} == #{expected}" do
|
11
|
+
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
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.2
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -38,15 +38,32 @@ 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
|
-
executables:
|
57
|
+
executables:
|
58
|
+
- code
|
44
59
|
extensions: []
|
45
60
|
extra_rdoc_files: []
|
46
61
|
files:
|
47
62
|
- ".rspec"
|
48
63
|
- Gemfile
|
49
64
|
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- bin/code
|
50
67
|
- code-ruby.gemspec
|
51
68
|
- lib/code-ruby.rb
|
52
69
|
- lib/code.rb
|
@@ -151,6 +168,7 @@ files:
|
|
151
168
|
- spec/code/object/dictionary_spec.rb
|
152
169
|
- spec/code/object/function_spec.rb
|
153
170
|
- spec/code/object/integer_spec.rb
|
171
|
+
- spec/code/object/list_spec.rb
|
154
172
|
- spec/code/object/nothing_spec.rb
|
155
173
|
- spec/code/object/range_spec.rb
|
156
174
|
- spec/code/parser/boolean_spec.rb
|
@@ -185,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
203
|
- !ruby/object:Gem::Version
|
186
204
|
version: '0'
|
187
205
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.5.5
|
189
207
|
signing_key:
|
190
208
|
specification_version: 4
|
191
209
|
summary: A programming language
|
@@ -196,6 +214,7 @@ test_files:
|
|
196
214
|
- spec/code/object/dictionary_spec.rb
|
197
215
|
- spec/code/object/function_spec.rb
|
198
216
|
- spec/code/object/integer_spec.rb
|
217
|
+
- spec/code/object/list_spec.rb
|
199
218
|
- spec/code/object/nothing_spec.rb
|
200
219
|
- spec/code/object/range_spec.rb
|
201
220
|
- spec/code/parser/boolean_spec.rb
|