diff options
-rw-r--r-- | lib/prism/translation/parser/compiler.rb | 28 | ||||
-rw-r--r-- | lib/prism/translation/parser/lexer.rb | 2 | ||||
-rw-r--r-- | test/prism/fixtures/patterns.txt | 1 | ||||
-rw-r--r-- | test/prism/ruby/parser_test.rb | 1 |
4 files changed, 14 insertions, 18 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index c5356555d0..acf4e77ee4 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -133,8 +133,8 @@ module Prism def visit_assoc_node(node) key = node.key - if in_pattern - if node.value.is_a?(ImplicitNode) + if node.value.is_a?(ImplicitNode) + if in_pattern if key.is_a?(SymbolNode) if key.opening.nil? builder.match_hash_var([key.unescaped, srange(key.location)]) @@ -144,23 +144,19 @@ module Prism else builder.match_hash_var_from_str(token(key.opening_loc), visit_all(key.parts), token(key.closing_loc)) end - elsif key.opening.nil? - builder.pair_keyword([key.unescaped, srange(key.location)], visit(node.value)) else - builder.pair_quoted(token(key.opening_loc), [builder.string_internal([key.unescaped, srange(key.value_loc)])], token(key.closing_loc), visit(node.value)) - end - elsif node.value.is_a?(ImplicitNode) - value = node.value.value + value = node.value.value - implicit_value = if value.is_a?(CallNode) - builder.call_method(nil, nil, [value.name, srange(value.message_loc)]) - elsif value.is_a?(ConstantReadNode) - builder.const([value.name, srange(key.value_loc)]) - else - builder.ident([value.name, srange(key.value_loc)]).updated(:lvar) - end + implicit_value = if value.is_a?(CallNode) + builder.call_method(nil, nil, [value.name, srange(value.message_loc)]) + elsif value.is_a?(ConstantReadNode) + builder.const([value.name, srange(key.value_loc)]) + else + builder.ident([value.name, srange(key.value_loc)]).updated(:lvar) + end - builder.pair_keyword([key.unescaped, srange(key)], implicit_value) + builder.pair_keyword([key.unescaped, srange(key)], implicit_value) + end elsif node.operator_loc builder.pair(visit(key), token(node.operator_loc), visit(node.value)) elsif key.is_a?(SymbolNode) && key.opening_loc.nil? diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 7db519499f..8f2d065b73 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -200,7 +200,7 @@ module Prism # The `PARENTHESIS_LEFT` token in Prism is classified as either `tLPAREN` or `tLPAREN2` in the Parser gem. # The following token types are listed as those classified as `tLPAREN`. LPAREN_CONVERSION_TOKEN_TYPES = Set.new([ - :kBREAK, :kCASE, :tDIVIDE, :kFOR, :kIF, :kNEXT, :kRETURN, :kUNTIL, :kWHILE, :tAMPER, :tANDOP, :tBANG, :tCOMMA, :tDOT2, :tDOT3, + :kBREAK, :tCARET, :kCASE, :tDIVIDE, :kFOR, :kIF, :kNEXT, :kRETURN, :kUNTIL, :kWHILE, :tAMPER, :tANDOP, :tBANG, :tCOMMA, :tDOT2, :tDOT3, :tEQL, :tLPAREN, :tLPAREN2, :tLPAREN_ARG, :tLSHFT, :tNL, :tOP_ASGN, :tOROP, :tPIPE, :tSEMI, :tSTRING_DBEG, :tUMINUS, :tUPLUS ]) diff --git a/test/prism/fixtures/patterns.txt b/test/prism/fixtures/patterns.txt index f4f3489e4d..09584e43eb 100644 --- a/test/prism/fixtures/patterns.txt +++ b/test/prism/fixtures/patterns.txt @@ -212,6 +212,7 @@ foo => Object[{x:}] case (); in [_a, _a]; end case (); in [{a:1}, {a:2}]; end +a => ^({'a' => 'b'}) a in b, and c a in b, or c diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 1324ac45e4..e94f9f860d 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -127,7 +127,6 @@ module Prism "whitequark/newline_in_hash_argument.txt", "whitequark/pattern_matching_expr_in_paren.txt", "whitequark/pattern_matching_hash.txt", - "whitequark/pin_expr.txt", "whitequark/ruby_bug_14690.txt", "whitequark/ruby_bug_9669.txt", "whitequark/space_args_arg_block.txt", |