code-ruby 0.13.1 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +15 -0
  3. data/.github/workflows/ci.yml +31 -0
  4. data/.rubocop.yml +8 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +52 -4
  7. data/bin/bundle-audit +31 -0
  8. data/bin/bundler-audit +31 -0
  9. data/bin/console +1 -0
  10. data/bin/rspec +31 -0
  11. data/bin/rubocop +31 -0
  12. data/lib/code/error.rb +0 -3
  13. data/lib/code/node/base_10.rb +4 -3
  14. data/lib/code/node/base_16.rb +1 -0
  15. data/lib/code/node/base_2.rb +1 -0
  16. data/lib/code/node/base_8.rb +1 -0
  17. data/lib/code/node/boolean.rb +1 -0
  18. data/lib/code/node/call.rb +14 -15
  19. data/lib/code/node/call_argument.rb +4 -4
  20. data/lib/code/node/code.rb +1 -0
  21. data/lib/code/node/decimal.rb +4 -3
  22. data/lib/code/node/dictionary.rb +5 -3
  23. data/lib/code/node/function.rb +1 -0
  24. data/lib/code/node/function_parameter.rb +14 -0
  25. data/lib/code/node/if.rb +6 -4
  26. data/lib/code/node/left_operation.rb +3 -3
  27. data/lib/code/node/list.rb +1 -0
  28. data/lib/code/node/negation.rb +1 -0
  29. data/lib/code/node/not.rb +1 -0
  30. data/lib/code/node/nothing.rb +1 -0
  31. data/lib/code/node/right_operation.rb +3 -2
  32. data/lib/code/node/splat.rb +1 -0
  33. data/lib/code/node/square_bracket.rb +1 -0
  34. data/lib/code/node/string.rb +3 -0
  35. data/lib/code/node/ternary.rb +4 -3
  36. data/lib/code/node/unary_minus.rb +1 -0
  37. data/lib/code/node/while.rb +4 -3
  38. data/lib/code/object/boolean.rb +2 -2
  39. data/lib/code/object/context.rb +1 -1
  40. data/lib/code/object/decimal.rb +9 -21
  41. data/lib/code/object/dictionary.rb +80 -113
  42. data/lib/code/object/function.rb +25 -35
  43. data/lib/code/object/global.rb +33 -32
  44. data/lib/code/object/identifier_list.rb +4 -4
  45. data/lib/code/object/integer.rb +14 -23
  46. data/lib/code/object/json.rb +10 -2
  47. data/lib/code/object/list.rb +50 -23
  48. data/lib/code/object/parameter.rb +18 -10
  49. data/lib/code/object/range.rb +33 -10
  50. data/lib/code/object/string.rb +2 -2
  51. data/lib/code/object/time.rb +4 -4
  52. data/lib/code/object.rb +31 -50
  53. data/lib/code/parser/string.rb +1 -1
  54. data/lib/code/type/repeat.rb +1 -1
  55. data/lib/code/type/sig.rb +1 -3
  56. data/lib/code/version.rb +1 -1
  57. data/lib/code-ruby.rb +2 -7
  58. data/lib/code.rb +1 -3
  59. data/spec/code/object/dictionary_spec.rb +6 -6
  60. data/spec/code_spec.rb +7 -8
  61. data/yarn.lock +4 -0
  62. metadata +10 -3
  63. data/lib/code/object/argument.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47fad657becca52443b5080a065fcad9e9faa2b1094e324d839eab8fdcb01e94
4
- data.tar.gz: 852bdb9f9114eceba8da2fc63b7c0f5514a1ffaf44999bc9de73c8b97a2852de
3
+ metadata.gz: 4457f2b10410f6514df4f0eebb52d52931724e2b448bd8e179650942f78aba9f
4
+ data.tar.gz: c9a3214b391d5a39aa185dd48ad6bde35bbd537616b93d626ff6686fc341ed9a
5
5
  SHA512:
6
- metadata.gz: 8a4e6d2c9252e22da770116fc739915bba7ec4e1b8f3896699fb5b34762a0d646994dd906bd614f1134251449dd82bbbd8d69b22318f9e9cf61c97f75f2b8fa2
7
- data.tar.gz: 82d89c16c8e982946b246573a5e59b2ae1a64b98027307b6b2a73395a4a8697f50f81a6994303a73cb2dad3f989bf6ad7e4e1cee8e5e47758acaae3c3ce79b99
6
+ metadata.gz: 6ba9119d592685a669c174ead2554725ec5586f25bcf41b3c9c418fb95965327cf0e84f1797e3dd83abc7c4cfe4bb9be4ed2f2fbd7fb9e98de94571b83c53647
7
+ data.tar.gz: e1c928ad8bbeab9b0101af715cea94ebefa8540465ae4482e7a8afa8d5e88436a800b8097e51a44b624bb8171c0940397f1eb4b871269d130eb2453e74fa3da3
@@ -0,0 +1,15 @@
1
+ ---
2
+ version: 2
3
+ updates:
4
+ - directory: "/"
5
+ package-ecosystem: github-actions
6
+ schedule:
7
+ interval: daily
8
+ - directory: "/"
9
+ package-ecosystem: npm
10
+ schedule:
11
+ interval: daily
12
+ - directory: "/"
13
+ package-ecosystem: bundler
14
+ schedule:
15
+ interval: daily
@@ -0,0 +1,31 @@
1
+ name: CI
2
+ on: push
3
+ jobs:
4
+ bundler-audit:
5
+ name: Bundler Audit
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v4
9
+ - uses: ruby/setup-ruby@v1
10
+ with:
11
+ bundler-cache: true
12
+ - run: bin/bundler-audit check --update
13
+ rspec:
14
+ name: RSpec
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3.3.0
21
+ bundler-cache: true
22
+ - run: bin/rspec
23
+ rubocop:
24
+ name: Rubocop
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ bundler-cache: true
31
+ - run: bin/rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_gem:
2
+ rubocop-rails-omakase: rubocop.yml
3
+
4
+ Layout/SpaceInsideArrayLiteralBrackets:
5
+ Enabled: false
6
+
7
+ Performance/UnfreezeString:
8
+ Enabled: false
data/Gemfile CHANGED
@@ -6,6 +6,8 @@ gemspec
6
6
 
7
7
  ruby "3.3.0"
8
8
 
9
+ gem "bundler-audit"
9
10
  gem "rake"
10
11
  gem "rspec"
12
+ gem "rubocop-rails-omakase"
11
13
  gem "ruby-prof"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (0.13.1)
4
+ code-ruby (0.14.0)
5
5
  activesupport (~> 7)
6
6
  bigdecimal (~> 3)
7
7
  json (~> 2)
@@ -21,8 +21,12 @@ GEM
21
21
  minitest (>= 5.1)
22
22
  mutex_m
23
23
  tzinfo (~> 2.0)
24
+ ast (2.4.2)
24
25
  base64 (0.2.0)
25
- bigdecimal (3.1.6)
26
+ bigdecimal (3.1.7)
27
+ bundler-audit (0.9.1)
28
+ bundler (>= 1.2.0, < 3)
29
+ thor (~> 1.0)
26
30
  concurrent-ruby (1.2.3)
27
31
  connection_pool (2.4.1)
28
32
  diff-lcs (1.5.1)
@@ -30,11 +34,21 @@ GEM
30
34
  i18n (1.14.4)
31
35
  concurrent-ruby (~> 1.0)
32
36
  json (2.7.1)
33
- language-ruby (0.8.0)
37
+ language-ruby (0.8.1)
34
38
  zeitwerk (~> 2)
35
- minitest (5.22.2)
39
+ language_server-protocol (3.17.0.3)
40
+ minitest (5.22.3)
36
41
  mutex_m (0.2.0)
42
+ parallel (1.24.0)
43
+ parser (3.3.0.5)
44
+ ast (~> 2.4.1)
45
+ racc
46
+ racc (1.7.3)
47
+ rack (3.0.9.1)
48
+ rainbow (3.1.1)
37
49
  rake (13.1.0)
50
+ regexp_parser (2.9.0)
51
+ rexml (3.2.6)
38
52
  rspec (3.13.0)
39
53
  rspec-core (~> 3.13.0)
40
54
  rspec-expectations (~> 3.13.0)
@@ -48,9 +62,41 @@ GEM
48
62
  diff-lcs (>= 1.2.0, < 2.0)
49
63
  rspec-support (~> 3.13.0)
50
64
  rspec-support (3.13.1)
65
+ rubocop (1.62.1)
66
+ json (~> 2.3)
67
+ language_server-protocol (>= 3.17.0)
68
+ parallel (~> 1.10)
69
+ parser (>= 3.3.0.2)
70
+ rainbow (>= 2.2.2, < 4.0)
71
+ regexp_parser (>= 1.8, < 3.0)
72
+ rexml (>= 3.2.5, < 4.0)
73
+ rubocop-ast (>= 1.31.1, < 2.0)
74
+ ruby-progressbar (~> 1.7)
75
+ unicode-display_width (>= 2.4.0, < 3.0)
76
+ rubocop-ast (1.31.2)
77
+ parser (>= 3.3.0.4)
78
+ rubocop-minitest (0.35.0)
79
+ rubocop (>= 1.61, < 2.0)
80
+ rubocop-ast (>= 1.31.1, < 2.0)
81
+ rubocop-performance (1.20.2)
82
+ rubocop (>= 1.48.1, < 2.0)
83
+ rubocop-ast (>= 1.30.0, < 2.0)
84
+ rubocop-rails (2.24.0)
85
+ activesupport (>= 4.2.0)
86
+ rack (>= 1.1)
87
+ rubocop (>= 1.33.0, < 2.0)
88
+ rubocop-ast (>= 1.31.1, < 2.0)
89
+ rubocop-rails-omakase (1.0.0)
90
+ rubocop
91
+ rubocop-minitest
92
+ rubocop-performance
93
+ rubocop-rails
51
94
  ruby-prof (1.7.0)
95
+ ruby-progressbar (1.13.0)
96
+ thor (1.3.1)
52
97
  tzinfo (2.0.6)
53
98
  concurrent-ruby (~> 1.0)
99
+ unicode-display_width (2.5.0)
54
100
  zeitwerk (2.6.13)
55
101
 
56
102
  PLATFORMS
@@ -58,9 +104,11 @@ PLATFORMS
58
104
  ruby
59
105
 
60
106
  DEPENDENCIES
107
+ bundler-audit
61
108
  code-ruby!
62
109
  rake
63
110
  rspec
111
+ rubocop-rails-omakase
64
112
  ruby-prof
65
113
 
66
114
  RUBY VERSION
data/bin/bundle-audit ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle-audit' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?(
17
+ "This file was generated by Bundler"
18
+ )
19
+ load(bundle_binstub)
20
+ else
21
+ abort(
22
+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
23
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again."
24
+ )
25
+ end
26
+ end
27
+
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+
31
+ load Gem.bin_path("bundler-audit", "bundle-audit")
data/bin/bundler-audit ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundler-audit' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?(
17
+ "This file was generated by Bundler"
18
+ )
19
+ load(bundle_binstub)
20
+ else
21
+ abort(
22
+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
23
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again."
24
+ )
25
+ end
26
+ end
27
+
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+
31
+ load Gem.bin_path("bundler-audit", "bundler-audit")
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative "../lib/code-ruby"
4
5
 
data/bin/rspec ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?(
17
+ "This file was generated by Bundler"
18
+ )
19
+ load(bundle_binstub)
20
+ else
21
+ abort(
22
+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
23
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again."
24
+ )
25
+ end
26
+ end
27
+
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+
31
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?(
17
+ "This file was generated by Bundler"
18
+ )
19
+ load(bundle_binstub)
20
+ else
21
+ abort(
22
+ "Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
23
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again."
24
+ )
25
+ end
26
+ end
27
+
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+
31
+ load Gem.bin_path("rubocop", "rubocop")
data/lib/code/error.rb CHANGED
@@ -17,9 +17,6 @@ class Code
17
17
  class UndefinedVariable < Error
18
18
  end
19
19
 
20
- class ArgumentError < Error
21
- end
22
-
23
20
  class IncompatibleContext < Error
24
21
  end
25
22
 
@@ -5,11 +5,12 @@ class Code
5
5
  class Base10 < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @whole = parsed.delete(:whole).presence
9
10
 
10
- if parsed.key?(:exponent)
11
- @exponent = Node::Statement.new(parsed.delete(:exponent).presence)
12
- end
11
+ return unless parsed.key?(:exponent)
12
+
13
+ @exponent = Node::Statement.new(parsed.delete(:exponent).presence)
13
14
  end
14
15
 
15
16
  def evaluate(**args)
@@ -5,6 +5,7 @@ class Code
5
5
  class Base16 < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @base_16 = parsed.presence
9
10
  end
10
11
 
@@ -5,6 +5,7 @@ class Code
5
5
  class Base2 < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @base_2 = parsed.presence
9
10
  end
10
11
 
@@ -5,6 +5,7 @@ class Code
5
5
  class Base8 < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @base_8 = parsed.presence
9
10
  end
10
11
 
@@ -8,6 +8,7 @@ class Code
8
8
 
9
9
  def initialize(parsed)
10
10
  return if parsed.blank?
11
+
11
12
  @boolean = parsed.presence
12
13
  end
13
14
 
@@ -6,6 +6,7 @@ class Code
6
6
  class Block < Node
7
7
  def initialize(parsed)
8
8
  return if parsed.blank?
9
+
9
10
  @parameters = parsed.delete(:parameters) { [] }.presence || []
10
11
  @parameters.map! { |parameter| FunctionParameter.new(parameter) }
11
12
 
@@ -13,19 +14,20 @@ class Code
13
14
  end
14
15
 
15
16
  def evaluate(**_args)
16
- Object::Argument.new(Object::Function.new(@parameters, @body))
17
+ Object::Function.new(@parameters, @body)
17
18
  end
18
19
  end
19
20
 
20
21
  def initialize(parsed)
21
22
  return if parsed.blank?
23
+
22
24
  @name = parsed.delete(:name).presence
23
25
  @arguments = parsed.delete(:arguments).presence || []
24
26
  @arguments.map! { |argument| CallArgument.new(argument) }
25
27
 
26
- if parsed.key?(:block)
27
- @block = Call::Block.new(parsed.delete(:block).presence)
28
- end
28
+ return unless parsed.key?(:block)
29
+
30
+ @block = Call::Block.new(parsed.delete(:block).presence)
29
31
  end
30
32
 
31
33
  def evaluate(**args)
@@ -33,17 +35,10 @@ class Code
33
35
 
34
36
  (@arguments || []).each do |argument|
35
37
  if argument.keyword?
36
- if arguments.last&.value.is_a?(Object::Dictionary)
37
- arguments.last.value.code_set(
38
- argument.name,
39
- argument.evaluate(**args).value
40
- )
38
+ if arguments.last.is_a?(Object::Dictionary)
39
+ arguments.last.code_merge!(argument.evaluate(**args))
41
40
  else
42
- arguments << Object::Argument.new(
43
- Object::Dictionary.new(
44
- { argument.name => argument.evaluate(**args).value }
45
- )
46
- )
41
+ arguments << argument.evaluate(**args)
47
42
  end
48
43
  else
49
44
  arguments << argument.evaluate(**args)
@@ -54,7 +49,11 @@ class Code
54
49
 
55
50
  name = Object::String.new(@name)
56
51
 
57
- args.fetch(:object).call(operator: name, arguments:, **args)
52
+ args.fetch(:object).call(
53
+ operator: name,
54
+ arguments: Object::List.new(arguments),
55
+ **args
56
+ )
58
57
  end
59
58
 
60
59
  def resolve(**_args)
@@ -5,18 +5,18 @@ class Code
5
5
  class CallArgument < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @value = Node::Code.new(parsed.delete(:value).presence)
9
10
  @name = parsed.delete(:name).presence
10
11
  end
11
12
 
12
13
  def evaluate(**args)
13
14
  if @name
14
- Object::Argument.new(
15
- @value&.evaluate(**args) || Object::Nothing.new,
16
- name:
15
+ Object::Dictionary.new(
16
+ name => @value&.evaluate(**args) || Object::Nothing.new
17
17
  )
18
18
  else
19
- Object::Argument.new(@value&.evaluate(**args) || Object::Nothing.new)
19
+ @value&.evaluate(**args) || Object::Nothing.new
20
20
  end
21
21
  end
22
22
 
@@ -5,6 +5,7 @@ class Code
5
5
  class Code < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @statements =
9
10
  (parsed.presence || []).map { |statement| Statement.new(statement) }
10
11
  end
@@ -5,11 +5,12 @@ class Code
5
5
  class Decimal < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @decimal = parsed.delete(:decimal).presence
9
10
 
10
- if parsed.key?(:exponent)
11
- @exponent = Statement.new(parsed.delete(:exponent).presence)
12
- end
11
+ return unless parsed.key?(:exponent)
12
+
13
+ @exponent = Statement.new(parsed.delete(:exponent).presence)
13
14
  end
14
15
 
15
16
  def evaluate(**args)
@@ -6,15 +6,16 @@ class Code
6
6
  class KeyValue < Node
7
7
  def initialize(parsed)
8
8
  return if parsed.blank?
9
+
9
10
  if parsed.key?(:statement)
10
11
  @key = Node::Statement.new(parsed.delete(:statement).presence)
11
12
  elsif parsed.key?(:name)
12
13
  @key = Node::String.new([{ text: parsed.delete(:name).presence }])
13
14
  end
14
15
 
15
- if parsed[:value].presence
16
- @value = Node::Code.new(parsed.delete(:value).presence)
17
- end
16
+ return unless parsed[:value].presence
17
+
18
+ @value = Node::Code.new(parsed.delete(:value).presence)
18
19
  end
19
20
 
20
21
  def evaluate(**args)
@@ -31,6 +32,7 @@ class Code
31
32
 
32
33
  def initialize(parsed)
33
34
  return if parsed.blank?
35
+
34
36
  @key_values = parsed.presence || []
35
37
  @key_values.map! do |key_value|
36
38
  Node::Dictionary::KeyValue.new(key_value)
@@ -5,6 +5,7 @@ class Code
5
5
  class Function < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @parameters = parsed.delete(:parameters).presence || []
9
10
  @parameters.map! { |parameter| FunctionParameter.new(parameter) }
10
11
 
@@ -5,6 +5,7 @@ class Code
5
5
  class FunctionParameter < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @name = parsed.delete(:name).presence
9
10
  @keyword = parsed.delete(:keyword).present?
10
11
  end
@@ -32,6 +33,19 @@ class Code
32
33
  def default
33
34
  nil
34
35
  end
36
+
37
+ def to_h
38
+ {
39
+ Object::String.new(:name) => Object::String.new(name),
40
+ Object::String.new(:regular?) => Object::Boolean.new(regular?),
41
+ Object::String.new(:keyword?) => Object::Boolean.new(keyword?),
42
+ Object::String.new(:regular_splat?) =>
43
+ Object::Boolean.new(regular_splat?),
44
+ Object::String.new(:keyword_splat?) =>
45
+ Object::Boolean.new(keyword_splat?),
46
+ Object::String.new(:default) => Object::Code.new(default)
47
+ }
48
+ end
35
49
  end
36
50
  end
37
51
  end
data/lib/code/node/if.rb CHANGED
@@ -13,22 +13,24 @@ class Code
13
13
 
14
14
  def initialize(parsed)
15
15
  return if parsed.blank?
16
+
16
17
  @operator = parsed.delete(:operator).presence
17
18
  @body = Node::Code.new(parsed.delete(:body).presence)
18
19
 
19
- if parsed.key?(:statement)
20
- @statement = Node::Statement.new(parsed.delete(:statement).presence)
21
- end
20
+ return unless parsed.key?(:statement)
21
+
22
+ @statement = Node::Statement.new(parsed.delete(:statement).presence)
22
23
  end
23
24
  end
24
25
 
25
26
  def initialize(parsed)
26
27
  return if parsed.blank?
28
+
27
29
  @first_operator = parsed.delete(:first_operator).presence
28
30
  @first_statement =
29
31
  Node::Statement.new(parsed.delete(:first_statement).presence)
30
32
  @first_body = Node::Code.new(parsed.delete(:first_body).presence)
31
- @elses = (parsed.delete(:elses).presence || [])
33
+ @elses = parsed.delete(:elses).presence || []
32
34
  @elses.map! { |elses| Node::If::Else.new(elses) }
33
35
  end
34
36
 
@@ -11,6 +11,7 @@ class Code
11
11
 
12
12
  def initialize(parsed)
13
13
  return if parsed.blank?
14
+
14
15
  @operator = parsed.delete(:operator).presence
15
16
  @statement = Statement.new(parsed.delete(:statement).presence)
16
17
  end
@@ -22,6 +23,7 @@ class Code
22
23
 
23
24
  def initialize(parsed)
24
25
  return if parsed.blank?
26
+
25
27
  @first = Statement.new(parsed.delete(:first).presence)
26
28
  @others = parsed.delete(:others).presence || []
27
29
  @others.map! { |operator| Operator.new(operator) }
@@ -34,12 +36,10 @@ class Code
34
36
  if right.call?
35
37
  right.statement.evaluate(**args, object: left)
36
38
  else
37
- statement = right.statement.evaluate(**args)
38
-
39
39
  left.call(
40
40
  **args,
41
41
  operator: right.operator,
42
- arguments: [::Code::Object::Argument.new(statement)]
42
+ arguments: Object::List.new([right.statement.evaluate(**args)])
43
43
  )
44
44
  end
45
45
  end
@@ -5,6 +5,7 @@ class Code
5
5
  class List < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @elements =
9
10
  (parsed.presence || []).map { |element| Node::Code.new(element) }
10
11
  end
@@ -5,6 +5,7 @@ class Code
5
5
  class Negation < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @operator = parsed.delete(:operator).presence
9
10
  @right = Node::Statement.new(parsed.delete(:right).presence)
10
11
  end
data/lib/code/node/not.rb CHANGED
@@ -5,6 +5,7 @@ class Code
5
5
  class Not < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @operator = parsed.delete(:operator).presence
9
10
  @right = Node::Statement.new(parsed.delete(:right).presence)
10
11
  end
@@ -5,6 +5,7 @@ class Code
5
5
  class Nothing < Node
6
6
  def initialize(parsed)
7
7
  return if parsed.blank?
8
+
8
9
  @nothing = parsed.presence
9
10
  end
10
11