Skip to content

Commit

Permalink
fix: some pattern matching edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Dec 5, 2023
1 parent 4d9fc00 commit a394b64
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/parser/prism/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def visit_assoc_node(node)
elsif in_pattern && node.value.nil?
if node.key.is_a?(::Prism::SymbolNode)
builder.match_hash_var([node.key.unescaped, srange(node.key.location)])
elsif node.key.is_a?(::Prism::MissingNode)
visit_missing_node(node)
else
builder.match_hash_var_from_str(token(node.key.opening_loc), visit_all(node.key.parts), token(node.key.closing_loc))
end
Expand All @@ -82,8 +84,10 @@ def visit_assoc_node(node)
parts =
if node.key.is_a?(::Prism::SymbolNode)
[builder.string_internal([node.key.unescaped, srange(node.key.value_loc)])]
else
elsif node.key.respond_to?(:parts)
visit_all(node.key.parts)
else
visit_missing_node(node)
end

builder.pair_quoted(token(node.key.opening_loc), parts, token(node.key.closing_loc), visit(node.value))
Expand Down Expand Up @@ -1014,7 +1018,7 @@ def visit_match_write_node(node)
# case of a syntax error. The parser gem doesn't have such a concept, so
# we invent our own here.
def visit_missing_node(node)
raise "Cannot compile missing nodes"
raise ::SyntaxError, "unexpected node"
end

# module Foo; end
Expand Down

0 comments on commit a394b64

Please sign in to comment.