Skip to content

Commit 8d01058

Browse files
committed
Handle deeply nested capture variables syntax err
When there are nested capture variables inside of a pattern match that has an alternation pattern, it is a syntax error. Currently it only adds a syntax error when it is at the top level of the pattern.
1 parent 4870fbd commit 8d01058

File tree

11 files changed

+102
-52
lines changed

11 files changed

+102
-52
lines changed

prism/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ errors:
217217
- PARAMETER_UNEXPECTED_FWD
218218
- PARAMETER_UNEXPECTED_NO_KW
219219
- PARAMETER_WILD_LOOSE_COMMA
220-
- PATTERN_ALTERNATIVE_AFTER_CAPTURE
221220
- PATTERN_ARRAY_MULTIPLE_RESTS
222221
- PATTERN_CAPTURE_DUPLICATE
223222
- PATTERN_CAPTURE_IN_ALTERNATIVE

prism/prism.c

Lines changed: 60 additions & 48 deletions
Large diffs are not rendered by default.

prism/templates/src/diagnostic.c.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
299299
[PM_ERR_PARAMETER_UNEXPECTED_FWD] = { "unexpected `...` in parameters", PM_ERROR_LEVEL_SYNTAX },
300300
[PM_ERR_PARAMETER_WILD_LOOSE_COMMA] = { "unexpected `,` in parameters", PM_ERROR_LEVEL_SYNTAX },
301301
[PM_ERR_PARAMETER_UNEXPECTED_NO_KW] = { "unexpected **nil; no keywords marker disallowed after keywords", PM_ERROR_LEVEL_SYNTAX },
302-
[PM_ERR_PATTERN_ALTERNATIVE_AFTER_CAPTURE] = { "alternative pattern after variable capture", PM_ERROR_LEVEL_SYNTAX },
303302
[PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS] = { "unexpected multiple '*' rest patterns in an array pattern", PM_ERROR_LEVEL_SYNTAX },
304303
[PM_ERR_PATTERN_CAPTURE_DUPLICATE] = { "duplicated variable name", PM_ERROR_LEVEL_SYNTAX },
305304
[PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE] = { "variable capture in alternative pattern", PM_ERROR_LEVEL_SYNTAX },
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude(:test_alternative_pattern_nested, "Changes here for syntax errors")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude(:test_alternative_pattern_nested, "Deeply nested captures variables are missing a syntax error")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude(:test_alternative_pattern_nested, "Changes here for syntax errors") if RUBY_DESCRIPTION.include?("+GC")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 => [a, b] | 2
2+
^ variable capture in alternative pattern
3+
^ variable capture in alternative pattern
4+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 => { a: b } | 2
2+
^ variable capture in alternative pattern
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 => (2 => b) | 2
2+
^ variable capture in alternative pattern
3+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 => a | b
2+
^ variable capture in alternative pattern
3+
^ variable capture in alternative pattern
4+

0 commit comments

Comments
 (0)