code-ruby 0.15.16 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.prettierignore +2 -0
- data/.rubocop.yml +121 -5
- data/Gemfile +9 -1
- data/Gemfile.lock +30 -22
- data/VERSION +1 -1
- data/bin/bundle +123 -0
- data/bin/code +8 -10
- data/code-ruby.gemspec +3 -1
- data/lib/code/node/dictionary.rb +1 -3
- data/lib/code/node/if.rb +20 -15
- data/lib/code/node/left_operation.rb +1 -3
- data/lib/code/node/right_operation.rb +6 -6
- data/lib/code/node/while.rb +6 -6
- data/lib/code/object/boolean.rb +1 -1
- data/lib/code/object/class.rb +1 -1
- data/lib/code/object/code.rb +1 -1
- data/lib/code/object/context.rb +1 -1
- data/lib/code/object/date.rb +1 -1
- data/lib/code/object/decimal.rb +2 -2
- data/lib/code/object/dictionary.rb +12 -34
- data/lib/code/object/duration.rb +1 -1
- data/lib/code/object/function.rb +1 -1
- data/lib/code/object/global.rb +1 -1
- data/lib/code/object/html.rb +1 -1
- data/lib/code/object/integer.rb +2 -2
- data/lib/code/object/json.rb +2 -4
- data/lib/code/object/list.rb +3 -5
- data/lib/code/object/nothing.rb +1 -1
- data/lib/code/object/parameter.rb +1 -5
- data/lib/code/object/range.rb +1 -1
- data/lib/code/object/string.rb +1 -1
- data/lib/code/object/time.rb +1 -1
- data/lib/code/object.rb +7 -13
- data/lib/code/parser/string.rb +7 -7
- data/lib/code/type/repeat.rb +1 -1
- data/lib/code/version.rb +1 -1
- data/lib/code-ruby.rb +1 -1
- data/package-lock.json +14 -0
- data/package.json +0 -1
- data/spec/code/node/call_spec.rb +0 -34
- data/spec/code/parser_spec.rb +2 -2
- data/spec/code/type_spec.rb +1 -1
- data/spec/code_spec.rb +78 -79
- metadata +14 -12
- data/bin/console +0 -6
- data/yarn.lock +0 -4
- /data/spec/code/parser/{chained_call.rb → chained_call_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d8e0526c2c649cf532eb5247172d32f52800a1006a4381de261faddfe654f04
|
4
|
+
data.tar.gz: 0d2397eb058541a4240162524b6896ece6978affc5aa3536928986f20be263b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a933f5a095a685a765ecfaa301295193de9cb619247841d0d50e3db0e076666ef3ebd2b0ef1e836de7fe7a71cbe9cb8a7866cb42bc6d78a87f8309e25b32dc43
|
7
|
+
data.tar.gz: 0341d3df4cc73b743017744999de3f3a12c9f0ec8b58d99ea425c3e60fa41bae2aab6827228a1c54ba0aa00f12fb470cc500af810f8afdacdbe2634b8a5dda69
|
data/.github/workflows/ci.yml
CHANGED
@@ -28,10 +28,10 @@ jobs:
|
|
28
28
|
with:
|
29
29
|
bundler-cache: true
|
30
30
|
- run: bin/rubocop
|
31
|
-
|
32
|
-
name:
|
31
|
+
npm-audit:
|
32
|
+
name: npm Audit
|
33
33
|
runs-on: ubuntu-latest
|
34
34
|
steps:
|
35
35
|
- uses: actions/checkout@v4
|
36
36
|
- uses: actions/setup-node@v4
|
37
|
-
- run:
|
37
|
+
- run: npm audit
|
data/.prettierignore
ADDED
data/.rubocop.yml
CHANGED
@@ -1,8 +1,124 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- "*/node_modules/**/*"
|
5
|
+
- "*/vendor/**/*"
|
6
|
+
- node_modules/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
NewCops: enable
|
9
|
+
Layout/ClosingHeredocIndentation:
|
10
|
+
Enabled: false
|
11
|
+
Layout/FirstArgumentIndentation:
|
12
|
+
Enabled: false
|
13
|
+
Layout/HashAlignment:
|
14
|
+
Enabled: false
|
15
|
+
Layout/HeredocIndentation:
|
16
|
+
Enabled: false
|
17
|
+
Layout/LineEndStringConcatenationIndentation:
|
18
|
+
Enabled: false
|
19
|
+
Layout/LineLength:
|
20
|
+
Enabled: false
|
21
|
+
Layout/MultilineMethodCallIndentation:
|
22
|
+
Enabled: false
|
23
|
+
Layout/MultilineOperationIndentation:
|
24
|
+
Enabled: false
|
25
|
+
Lint/EmptyClass:
|
26
|
+
Enabled: false
|
27
|
+
Lint/MissingSuper:
|
28
|
+
Enabled: false
|
29
|
+
Lint/PercentStringArray:
|
30
|
+
Enabled: false
|
31
|
+
Lint/ShadowingOuterLocalVariable:
|
32
|
+
Enabled: false
|
33
|
+
Lint/SuppressedException:
|
34
|
+
Enabled: false
|
35
|
+
Lint/UnusedBlockArgument:
|
36
|
+
Enabled: false
|
37
|
+
Lint/UselessAssignment:
|
38
|
+
Enabled: false
|
39
|
+
Metrics/AbcSize:
|
40
|
+
Enabled: false
|
41
|
+
Metrics/BlockLength:
|
42
|
+
Enabled: false
|
43
|
+
Metrics/ClassLength:
|
44
|
+
Enabled: false
|
45
|
+
Metrics/CyclomaticComplexity:
|
46
|
+
Enabled: false
|
47
|
+
Metrics/MethodLength:
|
48
|
+
Enabled: false
|
49
|
+
Metrics/ModuleLength:
|
50
|
+
Enabled: false
|
51
|
+
Metrics/ParameterLists:
|
52
|
+
Enabled: false
|
53
|
+
Metrics/PerceivedComplexity:
|
54
|
+
Enabled: false
|
55
|
+
Naming/FileName:
|
56
|
+
Enabled: false
|
57
|
+
Naming/MethodParameterName:
|
58
|
+
Enabled: false
|
59
|
+
Naming/VariableNumber:
|
5
60
|
Enabled: false
|
6
|
-
|
7
61
|
Performance/UnfreezeString:
|
8
62
|
Enabled: false
|
63
|
+
RSpec/AnyInstance:
|
64
|
+
Enabled: false
|
65
|
+
RSpec/ContextWording:
|
66
|
+
Enabled: false
|
67
|
+
RSpec/DescribeClass:
|
68
|
+
Enabled: false
|
69
|
+
RSpec/ExampleLength:
|
70
|
+
Enabled: false
|
71
|
+
RSpec/ExampleWording:
|
72
|
+
Enabled: false
|
73
|
+
RSpec/MultipleExpectations:
|
74
|
+
Enabled: false
|
75
|
+
RSpec/NoExpectationExample:
|
76
|
+
Enabled: false
|
77
|
+
RSpec/PendingWithoutReason:
|
78
|
+
Enabled: false
|
79
|
+
Rails/Delegate:
|
80
|
+
Enabled: false
|
81
|
+
Rails/DynamicFindBy:
|
82
|
+
Enabled: false
|
83
|
+
Rails/HelperInstanceVariable:
|
84
|
+
Enabled: false
|
85
|
+
Rails/NegateInclude:
|
86
|
+
Enabled: false
|
87
|
+
Rails/Output:
|
88
|
+
Enabled: false
|
89
|
+
Rails/Presence:
|
90
|
+
Enabled: false
|
91
|
+
Rails/Present:
|
92
|
+
Enabled: false
|
93
|
+
Rails/ThreeStateBooleanColumn:
|
94
|
+
Enabled: false
|
95
|
+
Rails/TimeZone:
|
96
|
+
Enabled: false
|
97
|
+
Security/Eval:
|
98
|
+
Enabled: false
|
99
|
+
Style/CaseEquality:
|
100
|
+
Enabled: false
|
101
|
+
Style/Documentation:
|
102
|
+
Enabled: false
|
103
|
+
Style/DoubleNegation:
|
104
|
+
Enabled: false
|
105
|
+
Style/EmptyMethod:
|
106
|
+
Enabled: false
|
107
|
+
Style/IfUnlessModifier:
|
108
|
+
Enabled: false
|
109
|
+
Style/MultilineBlockChain:
|
110
|
+
Enabled: false
|
111
|
+
Style/QuotedSymbols:
|
112
|
+
Enabled: false
|
113
|
+
Style/StringLiterals:
|
114
|
+
Enabled: false
|
115
|
+
Style/StringLiteralsInInterpolation:
|
116
|
+
Enabled: false
|
117
|
+
require:
|
118
|
+
- rubocop-factory_bot
|
119
|
+
- rubocop-performance
|
120
|
+
- rubocop-rails
|
121
|
+
- rubocop-rake
|
122
|
+
- rubocop-rspec
|
123
|
+
- rubocop-rspec_rails
|
124
|
+
- rubocop-capybara
|
data/Gemfile
CHANGED
@@ -9,5 +9,13 @@ ruby "3.3.4"
|
|
9
9
|
gem "bundler-audit"
|
10
10
|
gem "rake"
|
11
11
|
gem "rspec"
|
12
|
-
gem "rubocop-rails-omakase"
|
13
12
|
gem "ruby-prof"
|
13
|
+
|
14
|
+
gem "rubocop-factory_bot"
|
15
|
+
gem "rubocop-performance"
|
16
|
+
gem "rubocop-rails"
|
17
|
+
gem "rubocop-rake"
|
18
|
+
gem "rubocop-rspec"
|
19
|
+
gem "rubocop-rspec_rails"
|
20
|
+
|
21
|
+
gem "rubocop-capybara"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (
|
4
|
+
code-ruby (1.1.0)
|
5
5
|
activesupport
|
6
6
|
bigdecimal
|
7
7
|
did-you-mean
|
@@ -13,7 +13,7 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activesupport (7.2.
|
16
|
+
activesupport (7.2.1)
|
17
17
|
base64
|
18
18
|
bigdecimal
|
19
19
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
@@ -27,7 +27,7 @@ GEM
|
|
27
27
|
ast (2.4.2)
|
28
28
|
base64 (0.2.0)
|
29
29
|
bigdecimal (3.1.8)
|
30
|
-
bundler-audit (0.9.
|
30
|
+
bundler-audit (0.9.2)
|
31
31
|
bundler (>= 1.2.0, < 3)
|
32
32
|
thor (~> 1.0)
|
33
33
|
concurrent-ruby (1.3.4)
|
@@ -35,16 +35,14 @@ GEM
|
|
35
35
|
did-you-mean (0.1.1)
|
36
36
|
levenshtein (>= 0.2.0)
|
37
37
|
diff-lcs (1.5.1)
|
38
|
-
dorian-arguments (
|
39
|
-
activesupport
|
38
|
+
dorian-arguments (1.1.1)
|
40
39
|
bigdecimal
|
41
|
-
dorian-to_struct
|
42
|
-
dorian-to_struct (0.5.0)
|
43
40
|
drb (2.2.1)
|
44
41
|
i18n (1.14.5)
|
45
42
|
concurrent-ruby (~> 1.0)
|
46
43
|
json (2.7.2)
|
47
|
-
language-ruby (0.
|
44
|
+
language-ruby (1.0.1)
|
45
|
+
dorian-arguments
|
48
46
|
zeitwerk
|
49
47
|
language_server-protocol (3.17.0.3)
|
50
48
|
levenshtein (0.2.2)
|
@@ -59,7 +57,7 @@ GEM
|
|
59
57
|
rainbow (3.1.1)
|
60
58
|
rake (13.2.1)
|
61
59
|
regexp_parser (2.9.2)
|
62
|
-
rexml (3.3.
|
60
|
+
rexml (3.3.6)
|
63
61
|
strscan
|
64
62
|
rspec (3.13.0)
|
65
63
|
rspec-core (~> 3.13.0)
|
@@ -87,27 +85,30 @@ GEM
|
|
87
85
|
unicode-display_width (>= 2.4.0, < 3.0)
|
88
86
|
rubocop-ast (1.32.1)
|
89
87
|
parser (>= 3.3.1.0)
|
90
|
-
rubocop-
|
91
|
-
rubocop (
|
92
|
-
|
88
|
+
rubocop-capybara (2.21.0)
|
89
|
+
rubocop (~> 1.41)
|
90
|
+
rubocop-factory_bot (2.26.1)
|
91
|
+
rubocop (~> 1.61)
|
93
92
|
rubocop-performance (1.21.1)
|
94
93
|
rubocop (>= 1.48.1, < 2.0)
|
95
94
|
rubocop-ast (>= 1.31.1, < 2.0)
|
96
|
-
rubocop-rails (2.
|
95
|
+
rubocop-rails (2.26.0)
|
97
96
|
activesupport (>= 4.2.0)
|
98
97
|
rack (>= 1.1)
|
99
|
-
rubocop (>= 1.
|
98
|
+
rubocop (>= 1.52.0, < 2.0)
|
100
99
|
rubocop-ast (>= 1.31.1, < 2.0)
|
101
|
-
rubocop-
|
102
|
-
rubocop
|
103
|
-
|
104
|
-
rubocop
|
105
|
-
|
100
|
+
rubocop-rake (0.6.0)
|
101
|
+
rubocop (~> 1.0)
|
102
|
+
rubocop-rspec (3.0.4)
|
103
|
+
rubocop (~> 1.61)
|
104
|
+
rubocop-rspec_rails (2.30.0)
|
105
|
+
rubocop (~> 1.61)
|
106
|
+
rubocop-rspec (~> 3, >= 3.0.1)
|
106
107
|
ruby-prof (1.7.0)
|
107
108
|
ruby-progressbar (1.13.0)
|
108
109
|
securerandom (0.3.1)
|
109
110
|
strscan (3.1.0)
|
110
|
-
thor (1.3.
|
111
|
+
thor (1.3.2)
|
111
112
|
tzinfo (2.0.6)
|
112
113
|
concurrent-ruby (~> 1.0)
|
113
114
|
unicode-display_width (2.5.0)
|
@@ -116,17 +117,24 @@ GEM
|
|
116
117
|
PLATFORMS
|
117
118
|
arm64-darwin-23
|
118
119
|
ruby
|
120
|
+
x86_64-linux
|
119
121
|
|
120
122
|
DEPENDENCIES
|
121
123
|
bundler-audit
|
122
124
|
code-ruby!
|
123
125
|
rake
|
124
126
|
rspec
|
125
|
-
rubocop-
|
127
|
+
rubocop-capybara
|
128
|
+
rubocop-factory_bot
|
129
|
+
rubocop-performance
|
130
|
+
rubocop-rails
|
131
|
+
rubocop-rake
|
132
|
+
rubocop-rspec
|
133
|
+
rubocop-rspec_rails
|
126
134
|
ruby-prof
|
127
135
|
|
128
136
|
RUBY VERSION
|
129
137
|
ruby 3.3.4p94
|
130
138
|
|
131
139
|
BUNDLED WITH
|
132
|
-
2.5.
|
140
|
+
2.5.18
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.1.0
|
data/bin/bundle
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m =
|
14
|
+
Module.new do
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def invoked_as_script?
|
18
|
+
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
|
19
|
+
end
|
20
|
+
|
21
|
+
def env_var_version
|
22
|
+
ENV.fetch("BUNDLER_VERSION", nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cli_arg_version
|
26
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
27
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
28
|
+
|
29
|
+
bundler_version = nil
|
30
|
+
update_index = nil
|
31
|
+
ARGV.each_with_index do |a, i|
|
32
|
+
if update_index && update_index.succ == i &&
|
33
|
+
a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
|
34
|
+
bundler_version = a
|
35
|
+
end
|
36
|
+
unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o
|
37
|
+
next
|
38
|
+
end
|
39
|
+
|
40
|
+
bundler_version = Regexp.last_match(1)
|
41
|
+
update_index = i
|
42
|
+
end
|
43
|
+
bundler_version
|
44
|
+
end
|
45
|
+
|
46
|
+
def gemfile
|
47
|
+
gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
|
48
|
+
return gemfile if gemfile && !gemfile.empty?
|
49
|
+
|
50
|
+
File.expand_path("../Gemfile", __dir__)
|
51
|
+
end
|
52
|
+
|
53
|
+
def lockfile
|
54
|
+
lockfile =
|
55
|
+
case File.basename(gemfile)
|
56
|
+
when "gems.rb"
|
57
|
+
gemfile.sub(/\.rb$/, ".locked")
|
58
|
+
else
|
59
|
+
"#{gemfile}.lock"
|
60
|
+
end
|
61
|
+
File.expand_path(lockfile)
|
62
|
+
end
|
63
|
+
|
64
|
+
def lockfile_version
|
65
|
+
return unless File.file?(lockfile)
|
66
|
+
|
67
|
+
lockfile_contents = File.read(lockfile)
|
68
|
+
unless lockfile_contents =~
|
69
|
+
/\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
Regexp.last_match(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
def bundler_requirement
|
77
|
+
@bundler_requirement ||=
|
78
|
+
env_var_version || cli_arg_version ||
|
79
|
+
bundler_requirement_for(lockfile_version)
|
80
|
+
end
|
81
|
+
|
82
|
+
def bundler_requirement_for(version)
|
83
|
+
return "#{Gem::Requirement.default}.a" unless version
|
84
|
+
|
85
|
+
bundler_gem_version = Gem::Version.new(version)
|
86
|
+
|
87
|
+
bundler_gem_version.approximate_recommendation
|
88
|
+
end
|
89
|
+
|
90
|
+
def load_bundler!
|
91
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
92
|
+
|
93
|
+
activate_bundler
|
94
|
+
end
|
95
|
+
|
96
|
+
def activate_bundler
|
97
|
+
gem_error =
|
98
|
+
activation_error_handling { gem "bundler", bundler_requirement }
|
99
|
+
return if gem_error.nil?
|
100
|
+
|
101
|
+
require_error = activation_error_handling { require "bundler/version" }
|
102
|
+
if require_error.nil? &&
|
103
|
+
Gem::Requirement.new(bundler_requirement).satisfied_by?(
|
104
|
+
Gem::Version.new(Bundler::VERSION)
|
105
|
+
)
|
106
|
+
return
|
107
|
+
end
|
108
|
+
|
109
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
110
|
+
exit 42
|
111
|
+
end
|
112
|
+
|
113
|
+
def activation_error_handling
|
114
|
+
yield
|
115
|
+
nil
|
116
|
+
rescue StandardError, LoadError => e
|
117
|
+
e
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
m.load_bundler!
|
122
|
+
|
123
|
+
load Gem.bin_path("bundler", "bundle") if m.invoked_as_script?
|
data/bin/code
CHANGED
@@ -34,12 +34,10 @@ abort Code::Version.to_s if parsed.options.version
|
|
34
34
|
abort parsed.help if parsed.options.help
|
35
35
|
|
36
36
|
input = parsed.options.input.to_s
|
37
|
-
input
|
37
|
+
input += File.read(input) if File.exist?(input)
|
38
38
|
input += parsed.arguments.join(" ")
|
39
39
|
input += parsed.files.map { |file| File.read(file) }.join
|
40
40
|
|
41
|
-
abort parsed.help if input.empty?
|
42
|
-
|
43
41
|
profile = parsed.options.profile || parsed.options.profiler
|
44
42
|
require "ruby-prof" if profile
|
45
43
|
|
@@ -61,11 +59,11 @@ end
|
|
61
59
|
if profile
|
62
60
|
result = RubyProf.stop
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
printer =
|
63
|
+
if parsed.options.profiler == "html"
|
64
|
+
RubyProf::GraphHtmlPrinter.new(result)
|
65
|
+
else
|
66
|
+
RubyProf::FlatPrinter.new(result)
|
67
|
+
end
|
68
|
+
printer.print($stdout)
|
71
69
|
end
|
data/code-ruby.gemspec
CHANGED
@@ -16,8 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency "activesupport"
|
17
17
|
s.add_dependency "bigdecimal"
|
18
18
|
s.add_dependency "did-you-mean"
|
19
|
+
s.add_dependency "dorian-arguments"
|
19
20
|
s.add_dependency "json"
|
20
21
|
s.add_dependency "language-ruby"
|
21
22
|
s.add_dependency "zeitwerk"
|
22
|
-
s.
|
23
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
24
|
+
s.required_ruby_version = "3.3.4"
|
23
25
|
end
|
data/lib/code/node/dictionary.rb
CHANGED
data/lib/code/node/if.rb
CHANGED
@@ -35,24 +35,29 @@ class Code
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def evaluate(**args)
|
38
|
-
if
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
if (
|
39
|
+
@first_operator == IF_KEYWORD &&
|
40
|
+
@first_statement.evaluate(**args).truthy?
|
41
|
+
) ||
|
42
|
+
(
|
43
|
+
@first_operator == UNLESS_KEYWORD &&
|
44
|
+
@first_statement.evaluate(**args).falsy?
|
45
|
+
)
|
43
46
|
@first_body.evaluate(**args)
|
44
47
|
else
|
45
48
|
(@elses || []).each do |elses|
|
46
|
-
if
|
47
|
-
elses.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
if (
|
50
|
+
elses.operator == ELSIF_KEYWORD &&
|
51
|
+
elses.statement.evaluate(**args).truthy?
|
52
|
+
) ||
|
53
|
+
(
|
54
|
+
elses.operator == IF_KEYWORD &&
|
55
|
+
elses.statement.evaluate(**args).truthy?
|
56
|
+
) ||
|
57
|
+
(
|
58
|
+
elses.operator == UNLESS_KEYWORD &&
|
59
|
+
elses.statement.evaluate(**args).falsy?
|
60
|
+
) || (elses.operator == ELSE_KEYWORD)
|
56
61
|
return elses.body.evaluate(**args)
|
57
62
|
end
|
58
63
|
end
|
@@ -30,17 +30,17 @@ class Code
|
|
30
30
|
when "while"
|
31
31
|
left = Object::Nothing.new
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
left = @left&.evaluate(**args) || Object::Nothing.new while (
|
34
|
+
@right&.evaluate(**args) || Object::Nothing.new
|
35
|
+
).truthy?
|
36
36
|
|
37
37
|
left
|
38
38
|
when "until"
|
39
39
|
left = Object::Nothing.new
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
left = @left&.evaluate(**args) || Object::Nothing.new while (
|
42
|
+
@right&.evaluate(**args) || Object::Nothing.new
|
43
|
+
).falsy?
|
44
44
|
|
45
45
|
left
|
46
46
|
when "rescue"
|
data/lib/code/node/while.rb
CHANGED
@@ -22,17 +22,17 @@ class Code
|
|
22
22
|
when WHILE_KEYWORD
|
23
23
|
last = Object::Nothing.new
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
last = @body&.evaluate(**args) || Object::Nothing.new while (
|
26
|
+
@statement&.evaluate(**args) || Object::Nothing.new
|
27
|
+
).truthy?
|
28
28
|
|
29
29
|
last
|
30
30
|
when UNTIL_KEYWORD
|
31
31
|
last = Object::Nothing.new
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
last = @body&.evaluate(**args) || Object::Nothing.new while (
|
34
|
+
@statement&.evaluate(**args) || Object::Nothing.new
|
35
|
+
).falsy?
|
36
36
|
|
37
37
|
last
|
38
38
|
when LOOP_KEYWORD
|
data/lib/code/object/boolean.rb
CHANGED
data/lib/code/object/class.rb
CHANGED
data/lib/code/object/code.rb
CHANGED
data/lib/code/object/context.rb
CHANGED
data/lib/code/object/date.rb
CHANGED
data/lib/code/object/decimal.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
class Code
|
4
4
|
class Object
|
5
5
|
class Decimal < Object
|
6
|
-
def initialize(*args, **_kargs, &
|
6
|
+
def initialize(*args, **_kargs, &)
|
7
7
|
decimal = args.first || "0"
|
8
8
|
exponent = args.second || "0"
|
9
9
|
decimal = decimal.raw if decimal.is_an?(Object)
|
10
10
|
exponent = exponent.raw if exponent.is_an?(Object)
|
11
|
-
@raw = decimal.to_d * 10**exponent.to_d
|
11
|
+
@raw = decimal.to_d * (10**exponent.to_d)
|
12
12
|
rescue FloatDomainError
|
13
13
|
raise Error, "#{decimal.inspect} * 10**#{exponent.inspect} is invalid"
|
14
14
|
end
|