From 6a65136a8875339f1514ba1310c78bbb8ed6d1ce Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 28 Dec 2022 13:48:19 -0500 Subject: [PATCH] Fix for #235 --- lib/syntax_tree/parser.rb | 30 ++++++++++++++---------------- test/fixtures/rassign.rb | 6 ++++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/syntax_tree/parser.rb b/lib/syntax_tree/parser.rb index 85f6661e..fcefed30 100644 --- a/lib/syntax_tree/parser.rb +++ b/lib/syntax_tree/parser.rb @@ -995,22 +995,11 @@ def on_call(receiver, operator, message) # :call-seq: # on_case: (untyped value, untyped consequent) -> Case | RAssign def on_case(value, consequent) - if (keyword = find_keyword(:case)) - tokens.delete(keyword) - - Case.new( - keyword: keyword, - value: value, - consequent: consequent, - location: keyword.location.to(consequent.location) - ) - else - operator = - if (keyword = find_keyword(:in)) - tokens.delete(keyword) - else - consume_operator(:"=>") - end + if value && (operator = find_keyword(:in) || find_operator(:"=>")) && + (value.location.end_char...consequent.location.start_char).cover?( + operator.location.start_char + ) + tokens.delete(operator) node = RAssign.new( @@ -1022,6 +1011,15 @@ def on_case(value, consequent) PinVisitor.visit(node, tokens) node + else + keyword = consume_keyword(:case) + + Case.new( + keyword: keyword, + value: value, + consequent: consequent, + location: keyword.location.to(consequent.location) + ) end end diff --git a/test/fixtures/rassign.rb b/test/fixtures/rassign.rb index 3db52b18..3d357351 100644 --- a/test/fixtures/rassign.rb +++ b/test/fixtures/rassign.rb @@ -23,3 +23,9 @@ % a in Integer b => [Integer => c] +% +case [0] +when 0 + { a: 0 } => { a: } + puts a +end