Skip to content

Commit 915f6b3

Browse files
committed
Ensure context terminators terminate expressions
1 parent 483aa89 commit 915f6b3

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

snapshots/case_in_hash_key.txt

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
@ ProgramNode (location: (1,0)-(6,3))
2+
├── flags: ∅
3+
├── locals: []
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(6,3))
6+
├── flags: ∅
7+
└── body: (length: 1)
8+
└── @ CaseMatchNode (location: (1,0)-(6,3))
9+
├── flags: newline
10+
├── predicate:
11+
│ @ IntegerNode (location: (1,5)-(1,6))
12+
│ ├── flags: static_literal, decimal
13+
│ └── value: 1
14+
├── conditions: (length: 2)
15+
│ ├── @ InNode (location: (2,0)-(3,18))
16+
│ │ ├── flags: ∅
17+
│ │ ├── pattern:
18+
│ │ │ @ IntegerNode (location: (2,3)-(2,4))
19+
│ │ │ ├── flags: static_literal, decimal
20+
│ │ │ └── value: 2
21+
│ │ ├── statements:
22+
│ │ │ @ StatementsNode (location: (3,2)-(3,18))
23+
│ │ │ ├── flags: ∅
24+
│ │ │ └── body: (length: 1)
25+
│ │ │ └── @ CallNode (location: (3,2)-(3,18))
26+
│ │ │ ├── flags: newline
27+
│ │ │ ├── receiver:
28+
│ │ │ │ @ ConstantReadNode (location: (3,2)-(3,3))
29+
│ │ │ │ ├── flags: ∅
30+
│ │ │ │ └── name: :A
31+
│ │ │ ├── call_operator_loc: (3,3)-(3,4) = "."
32+
│ │ │ ├── name: :print
33+
│ │ │ ├── message_loc: (3,4)-(3,9) = "print"
34+
│ │ │ ├── opening_loc: ∅
35+
│ │ │ ├── arguments:
36+
│ │ │ │ @ ArgumentsNode (location: (3,10)-(3,18))
37+
│ │ │ │ ├── flags: contains_keywords
38+
│ │ │ │ └── arguments: (length: 1)
39+
│ │ │ │ └── @ KeywordHashNode (location: (3,10)-(3,18))
40+
│ │ │ │ ├── flags: symbol_keys
41+
│ │ │ │ └── elements: (length: 1)
42+
│ │ │ │ └── @ AssocNode (location: (3,10)-(3,18))
43+
│ │ │ │ ├── flags: ∅
44+
│ │ │ │ ├── key:
45+
│ │ │ │ │ @ SymbolNode (location: (3,10)-(3,18))
46+
│ │ │ │ │ ├── flags: static_literal, forced_us_ascii_encoding
47+
│ │ │ │ │ ├── opening_loc: ∅
48+
│ │ │ │ │ ├── value_loc: (3,10)-(3,17) = "message"
49+
│ │ │ │ │ ├── closing_loc: (3,17)-(3,18) = ":"
50+
│ │ │ │ │ └── unescaped: "message"
51+
│ │ │ │ ├── value:
52+
│ │ │ │ │ @ ImplicitNode (location: (3,10)-(3,18))
53+
│ │ │ │ │ ├── flags: ∅
54+
│ │ │ │ │ └── value:
55+
│ │ │ │ │ @ CallNode (location: (3,10)-(3,18))
56+
│ │ │ │ │ ├── flags: ignore_visibility
57+
│ │ │ │ │ ├── receiver: ∅
58+
│ │ │ │ │ ├── call_operator_loc: ∅
59+
│ │ │ │ │ ├── name: :message
60+
│ │ │ │ │ ├── message_loc: (3,10)-(3,17) = "message"
61+
│ │ │ │ │ ├── opening_loc: ∅
62+
│ │ │ │ │ ├── arguments: ∅
63+
│ │ │ │ │ ├── closing_loc: ∅
64+
│ │ │ │ │ └── block: ∅
65+
│ │ │ │ └── operator_loc: ∅
66+
│ │ │ ├── closing_loc: ∅
67+
│ │ │ └── block: ∅
68+
│ │ ├── in_loc: (2,0)-(2,2) = "in"
69+
│ │ └── then_loc: ∅
70+
│ └── @ InNode (location: (4,0)-(5,18))
71+
│ ├── flags: ∅
72+
│ ├── pattern:
73+
│ │ @ IntegerNode (location: (4,3)-(4,4))
74+
│ │ ├── flags: static_literal, decimal
75+
│ │ └── value: 3
76+
│ ├── statements:
77+
│ │ @ StatementsNode (location: (5,2)-(5,18))
78+
│ │ ├── flags: ∅
79+
│ │ └── body: (length: 1)
80+
│ │ └── @ CallNode (location: (5,2)-(5,18))
81+
│ │ ├── flags: newline
82+
│ │ ├── receiver:
83+
│ │ │ @ ConstantReadNode (location: (5,2)-(5,3))
84+
│ │ │ ├── flags: ∅
85+
│ │ │ └── name: :A
86+
│ │ ├── call_operator_loc: (5,3)-(5,4) = "."
87+
│ │ ├── name: :print
88+
│ │ ├── message_loc: (5,4)-(5,9) = "print"
89+
│ │ ├── opening_loc: ∅
90+
│ │ ├── arguments:
91+
│ │ │ @ ArgumentsNode (location: (5,10)-(5,18))
92+
│ │ │ ├── flags: contains_keywords
93+
│ │ │ └── arguments: (length: 1)
94+
│ │ │ └── @ KeywordHashNode (location: (5,10)-(5,18))
95+
│ │ │ ├── flags: symbol_keys
96+
│ │ │ └── elements: (length: 1)
97+
│ │ │ └── @ AssocNode (location: (5,10)-(5,18))
98+
│ │ │ ├── flags: ∅
99+
│ │ │ ├── key:
100+
│ │ │ │ @ SymbolNode (location: (5,10)-(5,18))
101+
│ │ │ │ ├── flags: static_literal, forced_us_ascii_encoding
102+
│ │ │ │ ├── opening_loc: ∅
103+
│ │ │ │ ├── value_loc: (5,10)-(5,17) = "message"
104+
│ │ │ │ ├── closing_loc: (5,17)-(5,18) = ":"
105+
│ │ │ │ └── unescaped: "message"
106+
│ │ │ ├── value:
107+
│ │ │ │ @ ImplicitNode (location: (5,10)-(5,18))
108+
│ │ │ │ ├── flags: ∅
109+
│ │ │ │ └── value:
110+
│ │ │ │ @ CallNode (location: (5,10)-(5,18))
111+
│ │ │ │ ├── flags: ignore_visibility
112+
│ │ │ │ ├── receiver: ∅
113+
│ │ │ │ ├── call_operator_loc: ∅
114+
│ │ │ │ ├── name: :message
115+
│ │ │ │ ├── message_loc: (5,10)-(5,17) = "message"
116+
│ │ │ │ ├── opening_loc: ∅
117+
│ │ │ │ ├── arguments: ∅
118+
│ │ │ │ ├── closing_loc: ∅
119+
│ │ │ │ └── block: ∅
120+
│ │ │ └── operator_loc: ∅
121+
│ │ ├── closing_loc: ∅
122+
│ │ └── block: ∅
123+
│ ├── in_loc: (4,0)-(4,2) = "in"
124+
│ └── then_loc: ∅
125+
├── else_clause: ∅
126+
├── case_keyword_loc: (1,0)-(1,4) = "case"
127+
└── end_keyword_loc: (6,0)-(6,3) = "end"

src/prism.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22150,6 +22150,12 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
2215022150
) {
2215122151
node = parse_expression_infix(parser, node, binding_power, current_binding_powers.right, accepts_command_call, (uint16_t) (depth + 1));
2215222152

22153+
if (context_terminator(parser->current_context->context, &parser->current)) {
22154+
// If this token terminates the current context, then we need to
22155+
// stop parsing the expression, as it has become a statement.
22156+
return node;
22157+
}
22158+
2215322159
switch (PM_NODE_TYPE(node)) {
2215422160
case PM_MULTI_WRITE_NODE:
2215522161
// Multi-write nodes are statements, and cannot be followed by
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
case 1
2+
in 2
3+
A.print message:
4+
in 3
5+
A.print message:
6+
end

0 commit comments

Comments
 (0)