code-ruby 3.0.1 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/parser.rb +10 -1
- data/spec/code_spec.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b61a40e84c1815a9437f6127c4db28d7327982671aa1a602e11ccc85e467861f
|
|
4
|
+
data.tar.gz: 796e46b1fbd2443799bd4cba9fcd7513c462bc9b605d31d17a2d1197ee7d6fd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d131863a968fa7e02711182c37840bd7743770d32da91f031bdc8e6ccd42aedea8312c1521c1095205eca46ed87f2b663a0622cc97706beb6383b5998bba097
|
|
7
|
+
data.tar.gz: 9b17fa0e159d1472929fd284020e538937ed1465cfeb0e36dce1f079044e657920edfd2d000aedee61a2e2a9f5eaabdf3ac3503833d162d3693efcccc594ffbd
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.2
|
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
|
-
{
|
|
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"],
|