code-ruby 3.0.0 → 3.0.2

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: c4aec10b766ce32c39c533055ec8a17e8463551a11e83c995028dbf43b67d42e
4
- data.tar.gz: 8f88527a8964da7c61fef7990f29582c56c542d59d33e11700c2ea0801be6749
3
+ metadata.gz: b61a40e84c1815a9437f6127c4db28d7327982671aa1a602e11ccc85e467861f
4
+ data.tar.gz: 796e46b1fbd2443799bd4cba9fcd7513c462bc9b605d31d17a2d1197ee7d6fd1
5
5
  SHA512:
6
- metadata.gz: da6c39843bfc479cfd66f965f9eacb6c80b002beda34c30128f2e5db4ac7bc787b0c002406385089ebeb3fd640896005cb2f54ba4e87c232600ed7275a7b43f6
7
- data.tar.gz: 457cba3cadc88d3a4a1520ec4b7dfbdb0c2088e16be3b6097be26d9cf6aab4f83cc33ad178baaea42895143c0867bc3e70dc9424e60f0dfeb8f807c72c5d7ff1
6
+ metadata.gz: 4d131863a968fa7e02711182c37840bd7743770d32da91f031bdc8e6ccd42aedea8312c1521c1095205eca46ed87f2b663a0622cc97706beb6383b5998bba097
7
+ data.tar.gz: 9b17fa0e159d1472929fd284020e538937ed1465cfeb0e36dce1f079044e657920edfd2d000aedee61a2e2a9f5eaabdf3ac3503833d162d3693efcccc594ffbd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (3.0.0)
4
+ code-ruby (3.0.2)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.2
@@ -22,7 +22,12 @@ class Code
22
22
  def resolve(**args)
23
23
  left = @left&.resolve(**args) || Object::Nothing.new
24
24
 
25
- list = Object::IdentifierList.new([left])
25
+ list =
26
+ if left.is_an?(Object::IdentifierList)
27
+ Object::IdentifierList.new(left.raw.dup)
28
+ else
29
+ Object::IdentifierList.new([left])
30
+ end
26
31
 
27
32
  (@statements || []).each do |statement|
28
33
  list.code_append(statement.evaluate(**args))
data/lib/code/parser.rb CHANGED
@@ -64,6 +64,8 @@ class Code
64
64
  =>
65
65
  ].sort_by(&:length).reverse.freeze
66
66
 
67
+ ASSIGNMENT_RHS_MIN_BP = 20
68
+
67
69
  INFIX_PRECEDENCE = {
68
70
  "if" => [10, 9],
69
71
  "unless" => [10, 9],
@@ -293,7 +295,13 @@ class Code
293
295
  when "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", "&=", "|=",
294
296
  "^=", "||=", "&&="
295
297
  skip_newlines
296
- { right_operation: { left: left, operator: operator, right: parse_expression(right_bp) } }
298
+ {
299
+ right_operation: {
300
+ left: left,
301
+ operator: operator,
302
+ right: parse_expression(ASSIGNMENT_RHS_MIN_BP)
303
+ }
304
+ }
297
305
  when "if", "unless", "while", "until", "rescue"
298
306
  skip_newlines
299
307
  { right_operation: { left: left, operator: operator, right: parse_expression(right_bp) } }
@@ -816,6 +824,7 @@ class Code
816
824
  def continuation_after_newline?(token)
817
825
  return false if token.type == :eof
818
826
  return true if token.type == :operator && INFIX_PRECEDENCE.key?(token.value)
827
+ return true if token.type == :keyword && %w[or and rescue].include?(token.value)
819
828
  return true if token.type == :punctuation && token.value == "?"
820
829
 
821
830
  token.type == :operator && [".", "::", "&."].include?(token.value)
data/spec/code_spec.rb CHANGED
@@ -401,6 +401,7 @@ RSpec.describe Code do
401
401
  ["true ? 1", "1"],
402
402
  ["true and false", "false"],
403
403
  ["true or false", "true"],
404
+ ["weekday? = false\n or true\nweekday?", "true"],
404
405
  ["true || false", "true"],
405
406
  ["unless false 1", "1"],
406
407
  ["unless true 1", "nothing"],
@@ -412,6 +413,7 @@ RSpec.describe Code do
412
413
  ['"Hello {1}"', '"Hello 1"'],
413
414
  ['user = {} user.name = "Dorian" user.name', ":Dorian"],
414
415
  ['user = {} user[:name] = "Dorian" user[:name]', ":Dorian"],
416
+ ['value = {} email = "a" calendar_id = "c" value[email] ||= {} value[email][calendar_id] ||= {} value[email][calendar_id]', "{}"],
415
417
  ['{ "first_name": "Dorian" }', '{"first_name" => "Dorian"}'],
416
418
  ['{ "first_name": "Dorian" }.as_json', '{"first_name" => "Dorian"}'],
417
419
  %w[nothing.to_json :null],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -306,7 +306,6 @@ files:
306
306
  - spec/code/object/decimal_spec.rb
307
307
  - spec/code/object/dictionary_spec.rb
308
308
  - spec/code/object/function_spec.rb
309
- - spec/code/object/identifier_list_spec.rb
310
309
  - spec/code/object/integer_spec.rb
311
310
  - spec/code/object/list_spec.rb
312
311
  - spec/code/object/nothing_spec.rb
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Code::Object::IdentifierList do
6
- it "assigns square bracket keys in parent context from nested scopes" do
7
- parent_context = Code::Object::Context.new
8
- child_context = Code::Object::Context.new({}, parent_context)
9
- code_identifier = Code::Object::String.new("github")
10
- code_index = Code::Object::Integer.new(1)
11
-
12
- parent_context.code_set(code_identifier, Code::Object::Dictionary.new(a: 1))
13
-
14
- identifier_list = described_class.new([code_identifier, code_index])
15
-
16
- identifier_list.call(
17
- operator: "=",
18
- arguments: Code::Object::List.new([Code::Object::Integer.new(2)]),
19
- context: child_context,
20
- error: StringIO.new,
21
- input: StringIO.new,
22
- object: Code::Object::Global.new,
23
- output: StringIO.new,
24
- source: ""
25
- )
26
-
27
- expect(parent_context.code_fetch(code_identifier).code_fetch(code_index)).to eq(
28
- Code::Object::Integer.new(2)
29
- )
30
- end
31
-
32
- it "keeps context for ||= assignments in nested context receivers" do
33
- code_context = Code::Object::Context.new
34
- code_identifier = Code::Object::String.new("value")
35
- code_key = Code::Object::String.new("key")
36
-
37
- code_context.code_set(
38
- code_identifier,
39
- Code::Object::Dictionary.new(code_key => Code::Object::Dictionary.new(a: 1))
40
- )
41
-
42
- identifier_list = described_class.new([code_identifier, code_key])
43
-
44
- expect do
45
- identifier_list.send(
46
- :assign_in_context,
47
- context: code_context,
48
- assignment_operator: "||=",
49
- code_value: Code::Object::Dictionary.new(b: 2),
50
- arguments: Code::Object::List.new([Code::Object::Dictionary.new(b: 2)]),
51
- operator: "||=",
52
- error: StringIO.new,
53
- input: StringIO.new,
54
- object: Code::Object::Global.new,
55
- output: StringIO.new,
56
- source: ""
57
- )
58
- end.not_to raise_error
59
- end
60
- end