Skip to content

Commit 43ffaad

Browse files
committed
Handle EOF in hash pattern key
1 parent 6b4f0ad commit 43ffaad

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@ ProgramNode (location: (1,0)-(1,15))
2+
├── flags: ∅
3+
├── locals: [:b]
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(1,15))
6+
├── flags: ∅
7+
└── body: (length: 1)
8+
└── @ MatchRequiredNode (location: (1,0)-(1,15))
9+
├── flags: newline
10+
├── value:
11+
│ @ CallNode (location: (1,0)-(1,3))
12+
│ ├── flags: variable_call, ignore_visibility
13+
│ ├── receiver: ∅
14+
│ ├── call_operator_loc: ∅
15+
│ ├── name: :foo
16+
│ ├── message_loc: (1,0)-(1,3) = "foo"
17+
│ ├── opening_loc: ∅
18+
│ ├── arguments: ∅
19+
│ ├── closing_loc: ∅
20+
│ ├── equal_loc: ∅
21+
│ └── block: ∅
22+
├── pattern:
23+
│ @ HashPatternNode (location: (1,7)-(1,15))
24+
│ ├── flags: ∅
25+
│ ├── constant: ∅
26+
│ ├── elements: (length: 2)
27+
│ │ ├── @ AssocNode (location: (1,7)-(1,11))
28+
│ │ │ ├── flags: static_literal
29+
│ │ │ ├── key:
30+
│ │ │ │ @ SymbolNode (location: (1,7)-(1,9))
31+
│ │ │ │ ├── flags: static_literal, forced_us_ascii_encoding
32+
│ │ │ │ ├── opening_loc: ∅
33+
│ │ │ │ ├── value_loc: (1,7)-(1,8) = "a"
34+
│ │ │ │ ├── closing_loc: (1,8)-(1,9) = ":"
35+
│ │ │ │ └── unescaped: "a"
36+
│ │ │ ├── value:
37+
│ │ │ │ @ IntegerNode (location: (1,10)-(1,11))
38+
│ │ │ │ ├── flags: static_literal, decimal
39+
│ │ │ │ └── value: 1
40+
│ │ │ └── operator_loc: ∅
41+
│ │ └── @ AssocNode (location: (1,13)-(1,15))
42+
│ │ ├── flags: ∅
43+
│ │ ├── key:
44+
│ │ │ @ SymbolNode (location: (1,13)-(1,15))
45+
│ │ │ ├── flags: static_literal, forced_us_ascii_encoding
46+
│ │ │ ├── opening_loc: ∅
47+
│ │ │ ├── value_loc: (1,13)-(1,14) = "b"
48+
│ │ │ ├── closing_loc: (1,14)-(1,15) = ":"
49+
│ │ │ └── unescaped: "b"
50+
│ │ ├── value:
51+
│ │ │ @ ImplicitNode (location: (1,13)-(1,14))
52+
│ │ │ ├── flags: ∅
53+
│ │ │ └── value:
54+
│ │ │ @ LocalVariableTargetNode (location: (1,13)-(1,14))
55+
│ │ │ ├── flags: ∅
56+
│ │ │ ├── name: :b
57+
│ │ │ └── depth: 0
58+
│ │ └── operator_loc: ∅
59+
│ ├── rest: ∅
60+
│ ├── opening_loc: ∅
61+
│ └── closing_loc: ∅
62+
└── operator_loc: (1,4)-(1,6) = "=>"

src/prism.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17060,7 +17060,7 @@ parse_pattern_hash(pm_parser_t *parser, pm_constant_id_list_t *captures, pm_node
1706017060
parse_pattern_hash_key(parser, &keys, key);
1706117061
pm_node_t *value = NULL;
1706217062

17063-
if (match7(parser, PM_TOKEN_COMMA, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON)) {
17063+
if (match8(parser, PM_TOKEN_COMMA, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_TOKEN_EOF)) {
1706417064
if (PM_NODE_TYPE_P(key, PM_SYMBOL_NODE)) {
1706517065
value = parse_pattern_hash_implicit_value(parser, captures, (pm_symbol_node_t *) key);
1706617066
} else {

test/prism/errors/pattern_string_key.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ case:a
22
^~~~ expected an `end` to close the `case` statement
33
in b:"","#{}"
44
^~~~~ expected a label after the `,` in the hash pattern
5-
^ expected a pattern expression after the key
65
^ expected a delimiter after the patterns of an `in` clause
76
^ unexpected end-of-input, assuming it is closing the parent top level context
87

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo => a: 1, b:

0 commit comments

Comments
 (0)