Skip to content

Commit

Permalink
Fix parse result for nesting pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Dec 14, 2023
1 parent 6e32cc3 commit ee6fc9e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -12973,7 +12973,7 @@ parse_pattern_constant_path(pm_parser_t *parser, pm_node_t *node) {
case PM_ARRAY_PATTERN_NODE: {
pm_array_pattern_node_t *pattern_node = (pm_array_pattern_node_t *) inner;

if (pattern_node->constant == NULL) {
if (pattern_node->constant == NULL && pattern_node->opening_loc.start == NULL) {
pattern_node->base.location.start = node->location.start;
pattern_node->base.location.end = closing.end;

Expand All @@ -12989,7 +12989,7 @@ parse_pattern_constant_path(pm_parser_t *parser, pm_node_t *node) {
case PM_FIND_PATTERN_NODE: {
pm_find_pattern_node_t *pattern_node = (pm_find_pattern_node_t *) inner;

if (pattern_node->constant == NULL) {
if (pattern_node->constant == NULL && pattern_node->opening_loc.start == NULL) {
pattern_node->base.location.start = node->location.start;
pattern_node->base.location.end = closing.end;

Expand All @@ -13005,7 +13005,7 @@ parse_pattern_constant_path(pm_parser_t *parser, pm_node_t *node) {
case PM_HASH_PATTERN_NODE: {
pm_hash_pattern_node_t *pattern_node = (pm_hash_pattern_node_t *) inner;

if (pattern_node->constant == NULL) {
if (pattern_node->constant == NULL && pattern_node->opening_loc.start == NULL) {
pattern_node->base.location.start = node->location.start;
pattern_node->base.location.end = closing.end;

Expand Down
2 changes: 2 additions & 0 deletions test/prism/fixtures/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,5 @@ foo, bar, baz = 1, 2
foo do
[1, 2] => [foo, bar] => baz
end

foo => Object[{x:}]
144 changes: 88 additions & 56 deletions test/prism/snapshots/patterns.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee6fc9e

Please sign in to comment.