code-ruby 0.13.1 → 0.14.0
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/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +31 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +51 -3
- data/bin/bundle-audit +31 -0
- data/bin/bundler-audit +31 -0
- data/bin/console +1 -0
- data/bin/rspec +31 -0
- data/bin/rubocop +31 -0
- data/lib/code/error.rb +0 -3
- data/lib/code/node/base_10.rb +4 -3
- data/lib/code/node/base_16.rb +1 -0
- data/lib/code/node/base_2.rb +1 -0
- data/lib/code/node/base_8.rb +1 -0
- data/lib/code/node/boolean.rb +1 -0
- data/lib/code/node/call.rb +14 -15
- data/lib/code/node/call_argument.rb +4 -4
- data/lib/code/node/code.rb +1 -0
- data/lib/code/node/decimal.rb +4 -3
- data/lib/code/node/dictionary.rb +5 -3
- data/lib/code/node/function.rb +1 -0
- data/lib/code/node/function_parameter.rb +14 -0
- data/lib/code/node/if.rb +6 -4
- data/lib/code/node/left_operation.rb +3 -3
- data/lib/code/node/list.rb +1 -0
- data/lib/code/node/negation.rb +1 -0
- data/lib/code/node/not.rb +1 -0
- data/lib/code/node/nothing.rb +1 -0
- data/lib/code/node/right_operation.rb +3 -2
- data/lib/code/node/splat.rb +1 -0
- data/lib/code/node/square_bracket.rb +1 -0
- data/lib/code/node/string.rb +3 -0
- data/lib/code/node/ternary.rb +4 -3
- data/lib/code/node/unary_minus.rb +1 -0
- data/lib/code/node/while.rb +4 -3
- data/lib/code/object/boolean.rb +2 -2
- data/lib/code/object/context.rb +1 -1
- data/lib/code/object/decimal.rb +9 -21
- data/lib/code/object/dictionary.rb +43 -113
- data/lib/code/object/function.rb +25 -35
- data/lib/code/object/global.rb +33 -32
- data/lib/code/object/identifier_list.rb +4 -4
- data/lib/code/object/integer.rb +14 -23
- data/lib/code/object/json.rb +10 -2
- data/lib/code/object/list.rb +50 -23
- data/lib/code/object/parameter.rb +18 -10
- data/lib/code/object/range.rb +33 -10
- data/lib/code/object/string.rb +2 -2
- data/lib/code/object/time.rb +4 -4
- data/lib/code/object.rb +31 -50
- data/lib/code/parser/string.rb +1 -1
- data/lib/code/type/repeat.rb +1 -1
- data/lib/code/type/sig.rb +1 -3
- data/lib/code/version.rb +1 -1
- data/lib/code-ruby.rb +2 -7
- data/lib/code.rb +1 -3
- data/spec/code/object/dictionary_spec.rb +6 -6
- data/spec/code_spec.rb +5 -8
- data/yarn.lock +4 -0
- metadata +10 -3
- data/lib/code/object/argument.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c99f4f0ee7e0d6ac477e266434a927ae59acc6cbf0ae50237397801acbd790a9
|
4
|
+
data.tar.gz: a6b1fb15a82837f17482a64d0e03f371b88d9f6fc1a7cd0ce10f37473ed71174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac6a450e1cdc87c22ce13b834158c50ff3688152f524560c5fa35a3c86fa11f607859208e1fb1cad5333147bbbb5674e862e92c393e70382c4a42dc5e86bd153
|
7
|
+
data.tar.gz: 5cdaa736e54913b5de049fb580ddbef07e5240d9f5de7cb7aa183b5c7abd70601839a74378b779bdcb313de1cf2398d651a34f596afbcb4f3299c885e7ba28ff
|
@@ -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
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -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.
|
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.
|
37
|
+
language-ruby (0.8.1)
|
34
38
|
zeitwerk (~> 2)
|
35
|
-
|
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
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
data/lib/code/node/base_10.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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)
|
data/lib/code/node/base_16.rb
CHANGED
data/lib/code/node/base_2.rb
CHANGED
data/lib/code/node/base_8.rb
CHANGED
data/lib/code/node/boolean.rb
CHANGED
data/lib/code/node/call.rb
CHANGED
@@ -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::
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
37
|
-
arguments.last.
|
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 <<
|
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(
|
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::
|
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
|
-
|
19
|
+
@value&.evaluate(**args) || Object::Nothing.new
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/code/node/code.rb
CHANGED
data/lib/code/node/decimal.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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)
|
data/lib/code/node/dictionary.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
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)
|
data/lib/code/node/function.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
21
|
-
|
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 =
|
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:
|
42
|
+
arguments: Object::List.new([right.statement.evaluate(**args)])
|
43
43
|
)
|
44
44
|
end
|
45
45
|
end
|
data/lib/code/node/list.rb
CHANGED
data/lib/code/node/negation.rb
CHANGED
data/lib/code/node/not.rb
CHANGED
data/lib/code/node/nothing.rb
CHANGED
@@ -7,6 +7,7 @@ class Code
|
|
7
7
|
|
8
8
|
def initialize(parsed)
|
9
9
|
return if parsed.blank?
|
10
|
+
|
10
11
|
@left = Statement.new(parsed.delete(:left).presence)
|
11
12
|
@operator = parsed.delete(:operator).presence
|
12
13
|
@right = Statement.new(parsed.delete(:right).presence)
|
@@ -54,7 +55,7 @@ class Code
|
|
54
55
|
|
55
56
|
left.call(
|
56
57
|
operator: @operator,
|
57
|
-
arguments:
|
58
|
+
arguments: Object::List.new([right]),
|
58
59
|
**args
|
59
60
|
)
|
60
61
|
else
|
@@ -63,7 +64,7 @@ class Code
|
|
63
64
|
|
64
65
|
left.call(
|
65
66
|
operator: @operator,
|
66
|
-
arguments:
|
67
|
+
arguments: Object::List.new([right]),
|
67
68
|
**args
|
68
69
|
)
|
69
70
|
end
|