Skip to content

Commit de2d723

Browse files
v3.0.2
1 parent 26f3af7 commit de2d723

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code-ruby (3.0.1)
4+
code-ruby (3.0.2)
55
activesupport
66
base64
77
bigdecimal

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.1
1+
3.0.2

lib/code/parser.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Language
6464
=>
6565
].sort_by(&:length).reverse.freeze
6666

67+
ASSIGNMENT_RHS_MIN_BP = 20
68+
6769
INFIX_PRECEDENCE = {
6870
"if" => [10, 9],
6971
"unless" => [10, 9],
@@ -293,7 +295,13 @@ def led_infix(left, operator, right_bp)
293295
when "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", "&=", "|=",
294296
"^=", "||=", "&&="
295297
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+
}
297305
when "if", "unless", "while", "until", "rescue"
298306
skip_newlines
299307
{ right_operation: { left: left, operator: operator, right: parse_expression(right_bp) } }
@@ -816,6 +824,7 @@ def next_significant_token
816824
def continuation_after_newline?(token)
817825
return false if token.type == :eof
818826
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)
819828
return true if token.type == :punctuation && token.value == "?"
820829

821830
token.type == :operator && [".", "::", "&."].include?(token.value)

spec/code_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def evaluate_with_output(input)
401401
["true ? 1", "1"],
402402
["true and false", "false"],
403403
["true or false", "true"],
404+
["weekday? = false\n or true\nweekday?", "true"],
404405
["true || false", "true"],
405406
["unless false 1", "1"],
406407
["unless true 1", "nothing"],

0 commit comments

Comments
 (0)