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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f013740cc5bbbf2e3d0d364dc987ed62d34d85d38b4af848d4c74a7110e6ad16
4
- data.tar.gz: adf22e7e5b35c2cda0e112797768af9f2840edd9425a2a4ea87d510698d27754
3
+ metadata.gz: bf105ec027258dabb4bca7a9b2246a1babc47f5557a47bc885fe9ddf1fea3bc7
4
+ data.tar.gz: 1976ef6aee479a4adfc402c58cbba49fbf175561a28d69784ccd7818ad13664d
5
5
  SHA512:
6
- metadata.gz: fc543960e9c707f39753e9931c85f35508cc97196ddee418165bf632ceea29a2f48c076e080ad3dba0ea4080a92ce17c262f24e5686083b6051d57da157b7f96
7
- data.tar.gz: 965a1ecebb0486ab5bca33b9c35d0303b2a9204d079675516d10a52ccd10c6104003336dedd0f5d82f8e35ef805dd749ea805a5b4890c43b76f99903e3aa9d1f
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.6.7)
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.0)
14
- language-ruby (0.6.1)
13
+ diff-lcs (1.5.1)
14
+ language-ruby (0.6.2)
15
15
  zeitwerk (~> 2)
16
- rspec (3.12.0)
17
- rspec-core (~> 3.12.0)
18
- rspec-expectations (~> 3.12.0)
19
- rspec-mocks (~> 3.12.0)
20
- rspec-core (3.12.2)
21
- rspec-support (~> 3.12.0)
22
- rspec-expectations (3.12.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.12.0)
25
- rspec-mocks (3.12.6)
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.12.0)
28
- rspec-support (3.12.1)
27
+ rspec-support (~> 3.13.0)
28
+ rspec-support (3.13.0)
29
29
  ruby-prof (1.7.0)
30
- zeitwerk (2.6.12)
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 = { timeout: 0, profile: false, profiler: 'text' }
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: template [options]'
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=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=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=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(input, context, io: $stdout, timeout: options[:timeout])
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)
@@ -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
- code
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
- (whitespace? << element << (whitespace? << comma).maybe).repeat <<
42
+ element.repeat <<
38
43
  (whitespace? << closing_square_bracket.ignore).maybe
39
44
  ).aka(:list) | String
40
45
  end
@@ -108,7 +108,7 @@ class Code
108
108
  end
109
109
 
110
110
  def separator
111
- special_character
111
+ special_character | any.absent
112
112
  end
113
113
 
114
114
  def root
@@ -8,7 +8,7 @@ class Code
8
8
  end
9
9
 
10
10
  def newline
11
- str("\n")
11
+ str("\n") | str("\r")
12
12
  end
13
13
 
14
14
  def hashtag
data/lib/code/version.rb CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../code"
4
4
 
5
- Code::Version = Gem::Version.new("0.7.1")
5
+ Code::Version = Gem::Version.new("0.7.3")
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.1
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 00:00:00.000000000 Z
11
+ date: 2024-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal