code-ruby 0.7.1 → 0.7.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/Gemfile.lock +15 -15
- data/bin/code +21 -10
- data/lib/code/parser/list.rb +7 -2
- data/lib/code/parser/name.rb +1 -1
- data/lib/code/parser/whitespace.rb +1 -1
- data/lib/code/version.rb +1 -1
- data/spec/code_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf105ec027258dabb4bca7a9b2246a1babc47f5557a47bc885fe9ddf1fea3bc7
|
4
|
+
data.tar.gz: 1976ef6aee479a4adfc402c58cbba49fbf175561a28d69784ccd7818ad13664d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68677a0f868274367d97fa0692b6f289a3ed90533b7fa5c104be5c84275e241791111ad5191004ac7fa88de3faf4a0331a064fa6e403ad1b1d18e8283847f030
|
7
|
+
data.tar.gz: 17615b062f51e946d979b84da8e05d9c48d711a909c29bae426576a973336b8b3b7858b2d484692e33caf58be5d931dfde69a61b763cf39c5616141d60b6f71e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (0.
|
4
|
+
code-ruby (0.7.1)
|
5
5
|
bigdecimal (~> 3)
|
6
6
|
language-ruby (~> 0)
|
7
7
|
zeitwerk (~> 2)
|
@@ -10,24 +10,24 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
bigdecimal (3.1.6)
|
13
|
-
diff-lcs (1.5.
|
14
|
-
language-ruby (0.6.
|
13
|
+
diff-lcs (1.5.1)
|
14
|
+
language-ruby (0.6.2)
|
15
15
|
zeitwerk (~> 2)
|
16
|
-
rspec (3.
|
17
|
-
rspec-core (~> 3.
|
18
|
-
rspec-expectations (~> 3.
|
19
|
-
rspec-mocks (~> 3.
|
20
|
-
rspec-core (3.
|
21
|
-
rspec-support (~> 3.
|
22
|
-
rspec-expectations (3.
|
16
|
+
rspec (3.13.0)
|
17
|
+
rspec-core (~> 3.13.0)
|
18
|
+
rspec-expectations (~> 3.13.0)
|
19
|
+
rspec-mocks (~> 3.13.0)
|
20
|
+
rspec-core (3.13.0)
|
21
|
+
rspec-support (~> 3.13.0)
|
22
|
+
rspec-expectations (3.13.0)
|
23
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-mocks (3.
|
24
|
+
rspec-support (~> 3.13.0)
|
25
|
+
rspec-mocks (3.13.0)
|
26
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-support (3.
|
27
|
+
rspec-support (~> 3.13.0)
|
28
|
+
rspec-support (3.13.0)
|
29
29
|
ruby-prof (1.7.0)
|
30
|
-
zeitwerk (2.6.
|
30
|
+
zeitwerk (2.6.13)
|
31
31
|
|
32
32
|
PLATFORMS
|
33
33
|
arm64-darwin-23
|
data/bin/code
CHANGED
@@ -4,11 +4,18 @@
|
|
4
4
|
require 'optparse'
|
5
5
|
require_relative '../lib/code-ruby'
|
6
6
|
|
7
|
-
options = {
|
7
|
+
options = {
|
8
|
+
timeout: 0,
|
9
|
+
profile: false,
|
10
|
+
profiler: 'text',
|
11
|
+
input: "",
|
12
|
+
context: "",
|
13
|
+
parse: false
|
14
|
+
}
|
8
15
|
|
9
16
|
OptionParser
|
10
17
|
.new do |opts|
|
11
|
-
opts.banner = 'Usage:
|
18
|
+
opts.banner = 'Usage: code [options]'
|
12
19
|
|
13
20
|
opts.on('-v', '--version', 'Version of template') do |_input|
|
14
21
|
puts Code::Version
|
@@ -17,7 +24,7 @@ OptionParser
|
|
17
24
|
|
18
25
|
opts.on(
|
19
26
|
'-i INPUT',
|
20
|
-
'--input
|
27
|
+
'--input INPUT',
|
21
28
|
'Input in the code language (String or File)'
|
22
29
|
) do |input|
|
23
30
|
input = File.read(input) if File.exist?(input)
|
@@ -27,7 +34,7 @@ OptionParser
|
|
27
34
|
|
28
35
|
opts.on(
|
29
36
|
'-c CONTEXT',
|
30
|
-
'--context
|
37
|
+
'--context CONTEXT',
|
31
38
|
'Context in the code language (String or File)'
|
32
39
|
) do |context|
|
33
40
|
context = File.read(context) if File.exist?(context)
|
@@ -41,7 +48,7 @@ OptionParser
|
|
41
48
|
|
42
49
|
opts.on(
|
43
50
|
'-t TIMEOUT',
|
44
|
-
'--timeout
|
51
|
+
'--timeout TIMEOUT',
|
45
52
|
'Set timeout in seconds'
|
46
53
|
) { |timeout| options[:timeout] = timeout.to_f }
|
47
54
|
|
@@ -61,19 +68,23 @@ OptionParser
|
|
61
68
|
end
|
62
69
|
.parse!
|
63
70
|
|
64
|
-
input = options.fetch(:input, '')
|
65
|
-
context = options.fetch(:context, '')
|
66
|
-
|
67
71
|
RubyProf.start if options[:profile]
|
68
72
|
|
69
73
|
if options[:parse]
|
70
|
-
pp Code::Parser.parse(input).to_raw
|
74
|
+
pp Code::Parser.parse(options[:input]).to_raw
|
71
75
|
else
|
72
|
-
print Code.evaluate(
|
76
|
+
print Code.evaluate(
|
77
|
+
options[:input],
|
78
|
+
options[:context],
|
79
|
+
output: $stdout,
|
80
|
+
error: $stderr,
|
81
|
+
timeout: options[:timeout]
|
82
|
+
)
|
73
83
|
end
|
74
84
|
|
75
85
|
if options[:profile]
|
76
86
|
result = RubyProf.stop
|
87
|
+
|
77
88
|
if options[:profiler] == 'text'
|
78
89
|
printer = RubyProf::FlatPrinter.new(result)
|
79
90
|
printer.print($stdout)
|
data/lib/code/parser/list.rb
CHANGED
@@ -4,6 +4,10 @@ class Code
|
|
4
4
|
class Parser
|
5
5
|
class List < Language
|
6
6
|
def code
|
7
|
+
Code
|
8
|
+
end
|
9
|
+
|
10
|
+
def code_present
|
7
11
|
Code.new.present
|
8
12
|
end
|
9
13
|
|
@@ -28,13 +32,14 @@ class Code
|
|
28
32
|
end
|
29
33
|
|
30
34
|
def element
|
31
|
-
|
35
|
+
(whitespace? << code_present << (whitespace? << comma).maybe) |
|
36
|
+
(whitespace? << code << whitespace? << comma)
|
32
37
|
end
|
33
38
|
|
34
39
|
def root
|
35
40
|
(
|
36
41
|
opening_square_bracket.ignore << whitespace? <<
|
37
|
-
|
42
|
+
element.repeat <<
|
38
43
|
(whitespace? << closing_square_bracket.ignore).maybe
|
39
44
|
).aka(:list) | String
|
40
45
|
end
|
data/lib/code/parser/name.rb
CHANGED
data/lib/code/version.rb
CHANGED
data/spec/code_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
[
|
7
|
+
["\r\n", "nothing"],
|
7
8
|
["1 + 1", "2"],
|
8
9
|
["a = 1", "1"],
|
9
10
|
["a = 1 b = 2 c = a + b c", "3"],
|
@@ -67,6 +68,11 @@ RSpec.describe Code do
|
|
67
68
|
["[1, 2, 3]", "[1, 2, 3]"],
|
68
69
|
["[1, 2, 3].include?(2)", "true"],
|
69
70
|
["[1, 2, 3].include?(4)", "false"],
|
71
|
+
["[1, 2, 3,].include?(4)", "false"],
|
72
|
+
["[1, 2, 3, \n ].include?(4)", "false"],
|
73
|
+
["[1].each do end", "[1]"],
|
74
|
+
["[,].include?(4)", "false"],
|
75
|
+
["[,,].include?(4)", "false"],
|
70
76
|
["[[true]]", "[[true]]"],
|
71
77
|
["2 * 3", "6"],
|
72
78
|
["2 * 3 + 2", "8"],
|
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.7.
|
4
|
+
version: 0.7.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: 2024-02-
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|