Skip to content

Commit 42356fd

Browse files
committed
Treat loop do as a pattern terminator
Prism rejected pattern-matching loop conditions with a trailing comma before the `do` delimiter, while parse.y accepts them. Treat `PM_TOKEN_KEYWORD_DO_LOOP` as a terminator after a trailing comma, so the loop `do` delimiter is not parsed as another pattern.
1 parent 880833d commit 42356fd

7 files changed

Lines changed: 225 additions & 84 deletions

File tree

snapshots/for.txt

Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@ ProgramNode (location: (1,0)-(19,22))
1+
@ ProgramNode (location: (1,0)-(21,25))
22
├── flags: ∅
3-
├── locals: [:i, :j, :k]
3+
├── locals: [:i, :j, :k, :x, :b]
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(19,22))
5+
@ StatementsNode (location: (1,0)-(21,25))
66
├── flags: ∅
7-
└── body: (length: 6)
7+
└── body: (length: 7)
88
├── @ ForNode (location: (1,0)-(3,3))
99
│ ├── flags: newline
1010
│ ├── index:
@@ -186,34 +186,83 @@
186186
│ ├── in_keyword_loc: (15,6)-(15,8) = "in"
187187
│ ├── do_keyword_loc: (15,15)-(15,17) = "do"
188188
│ └── end_keyword_loc: (17,0)-(17,3) = "end"
189-
└── @ ForNode (location: (19,0)-(19,22))
189+
├── @ ForNode (location: (19,0)-(19,22))
190+
│ ├── flags: newline
191+
│ ├── index:
192+
│ │ @ LocalVariableTargetNode (location: (19,4)-(19,5))
193+
│ │ ├── flags: ∅
194+
│ │ ├── name: :i
195+
│ │ └── depth: 0
196+
│ ├── collection:
197+
│ │ @ RangeNode (location: (19,9)-(19,14))
198+
│ │ ├── flags: static_literal
199+
│ │ ├── left:
200+
│ │ │ @ IntegerNode (location: (19,9)-(19,10))
201+
│ │ │ ├── flags: static_literal, decimal
202+
│ │ │ └── value: 1
203+
│ │ ├── right:
204+
│ │ │ @ IntegerNode (location: (19,12)-(19,14))
205+
│ │ │ ├── flags: static_literal, decimal
206+
│ │ │ └── value: 10
207+
│ │ └── operator_loc: (19,10)-(19,12) = ".."
208+
│ ├── statements:
209+
│ │ @ StatementsNode (location: (19,16)-(19,17))
210+
│ │ ├── flags: ∅
211+
│ │ └── body: (length: 1)
212+
│ │ └── @ LocalVariableReadNode (location: (19,16)-(19,17))
213+
│ │ ├── flags: newline
214+
│ │ ├── name: :i
215+
│ │ └── depth: 0
216+
│ ├── for_keyword_loc: (19,0)-(19,3) = "for"
217+
│ ├── in_keyword_loc: (19,6)-(19,8) = "in"
218+
│ ├── do_keyword_loc: ∅
219+
│ └── end_keyword_loc: (19,19)-(19,22) = "end"
220+
└── @ ForNode (location: (21,0)-(21,25))
190221
├── flags: newline
191222
├── index:
192-
│ @ LocalVariableTargetNode (location: (19,4)-(19,5))
223+
│ @ LocalVariableTargetNode (location: (21,4)-(21,5))
193224
│ ├── flags: ∅
194-
│ ├── name: :i
225+
│ ├── name: :x
195226
│ └── depth: 0
196227
├── collection:
197-
│ @ RangeNode (location: (19,9)-(19,14))
198-
│ ├── flags: static_literal
199-
│ ├── left:
200-
│ │ @ IntegerNode (location: (19,9)-(19,10))
201-
│ │ ├── flags: static_literal, decimal
202-
│ │ └── value: 1
203-
│ ├── right:
204-
│ │ @ IntegerNode (location: (19,12)-(19,14))
205-
│ │ ├── flags: static_literal, decimal
206-
│ │ └── value: 10
207-
│ └── operator_loc: (19,10)-(19,12) = ".."
228+
│ @ MatchPredicateNode (location: (21,9)-(21,16))
229+
│ ├── flags: ∅
230+
│ ├── value:
231+
│ │ @ CallNode (location: (21,9)-(21,10))
232+
│ │ ├── flags: variable_call, ignore_visibility
233+
│ │ ├── receiver: ∅
234+
│ │ ├── call_operator_loc: ∅
235+
│ │ ├── name: :a
236+
│ │ ├── message_loc: (21,9)-(21,10) = "a"
237+
│ │ ├── opening_loc: ∅
238+
│ │ ├── arguments: ∅
239+
│ │ ├── closing_loc: ∅
240+
│ │ ├── equal_loc: ∅
241+
│ │ └── block: ∅
242+
│ ├── pattern:
243+
│ │ @ ArrayPatternNode (location: (21,14)-(21,16))
244+
│ │ ├── flags: ∅
245+
│ │ ├── constant: ∅
246+
│ │ ├── requireds: (length: 1)
247+
│ │ │ └── @ LocalVariableTargetNode (location: (21,14)-(21,15))
248+
│ │ │ ├── flags: ∅
249+
│ │ │ ├── name: :b
250+
│ │ │ └── depth: 0
251+
│ │ ├── rest:
252+
│ │ │ @ ImplicitRestNode (location: (21,15)-(21,16))
253+
│ │ │ └── flags: ∅
254+
│ │ ├── posts: (length: 0)
255+
│ │ ├── opening_loc: ∅
256+
│ │ └── closing_loc: ∅
257+
│ └── operator_loc: (21,11)-(21,13) = "in"
208258
├── statements:
209-
│ @ StatementsNode (location: (19,16)-(19,17))
259+
│ @ StatementsNode (location: (21,20)-(21,21))
210260
│ ├── flags: ∅
211261
│ └── body: (length: 1)
212-
│ └── @ LocalVariableReadNode (location: (19,16)-(19,17))
213-
│ ├── flags: newline
214-
│ ├── name: :i
215-
│ └── depth: 0
216-
├── for_keyword_loc: (19,0)-(19,3) = "for"
217-
├── in_keyword_loc: (19,6)-(19,8) = "in"
218-
├── do_keyword_loc: ∅
219-
└── end_keyword_loc: (19,19)-(19,22) = "end"
262+
│ └── @ IntegerNode (location: (21,20)-(21,21))
263+
│ ├── flags: newline, static_literal, decimal
264+
│ └── value: 1
265+
├── for_keyword_loc: (21,0)-(21,3) = "for"
266+
├── in_keyword_loc: (21,6)-(21,8) = "in"
267+
├── do_keyword_loc: (21,17)-(21,19) = "do"
268+
└── end_keyword_loc: (21,22)-(21,25) = "end"

snapshots/until.txt

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@ ProgramNode (location: (1,0)-(13,20))
1+
@ ProgramNode (location: (1,0)-(15,22))
22
├── flags: ∅
3-
├── locals: [:baz]
3+
├── locals: [:baz, :b]
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(13,20))
5+
@ StatementsNode (location: (1,0)-(15,22))
66
├── flags: ∅
7-
└── body: (length: 7)
7+
└── body: (length: 8)
88
├── @ UntilNode (location: (1,0)-(1,18))
99
│ ├── flags: newline
1010
│ ├── keyword_loc: (1,0)-(1,5) = "until"
@@ -172,44 +172,87 @@
172172
│ ├── closing_loc: ∅
173173
│ ├── equal_loc: ∅
174174
│ └── block: ∅
175-
└── @ WhileNode (location: (13,0)-(13,20))
175+
├── @ WhileNode (location: (13,0)-(13,20))
176+
│ ├── flags: newline
177+
│ ├── keyword_loc: (13,4)-(13,9) = "while"
178+
│ ├── do_keyword_loc: ∅
179+
│ ├── closing_loc: ∅
180+
│ ├── predicate:
181+
│ │ @ MatchPredicateNode (location: (13,10)-(13,20))
182+
│ │ ├── flags: ∅
183+
│ │ ├── value:
184+
│ │ │ @ CallNode (location: (13,10)-(13,13))
185+
│ │ │ ├── flags: variable_call, ignore_visibility
186+
│ │ │ ├── receiver: ∅
187+
│ │ │ ├── call_operator_loc: ∅
188+
│ │ │ ├── name: :bar
189+
│ │ │ ├── message_loc: (13,10)-(13,13) = "bar"
190+
│ │ │ ├── opening_loc: ∅
191+
│ │ │ ├── arguments: ∅
192+
│ │ │ ├── closing_loc: ∅
193+
│ │ │ ├── equal_loc: ∅
194+
│ │ │ └── block: ∅
195+
│ │ ├── pattern:
196+
│ │ │ @ LocalVariableTargetNode (location: (13,17)-(13,20))
197+
│ │ │ ├── flags: ∅
198+
│ │ │ ├── name: :baz
199+
│ │ │ └── depth: 0
200+
│ │ └── operator_loc: (13,14)-(13,16) = "in"
201+
│ └── statements:
202+
│ @ StatementsNode (location: (13,0)-(13,3))
203+
│ ├── flags: ∅
204+
│ └── body: (length: 1)
205+
│ └── @ CallNode (location: (13,0)-(13,3))
206+
│ ├── flags: newline, variable_call, ignore_visibility
207+
│ ├── receiver: ∅
208+
│ ├── call_operator_loc: ∅
209+
│ ├── name: :foo
210+
│ ├── message_loc: (13,0)-(13,3) = "foo"
211+
│ ├── opening_loc: ∅
212+
│ ├── arguments: ∅
213+
│ ├── closing_loc: ∅
214+
│ ├── equal_loc: ∅
215+
│ └── block: ∅
216+
└── @ UntilNode (location: (15,0)-(15,22))
176217
├── flags: newline
177-
├── keyword_loc: (13,4)-(13,9) = "while"
178-
├── do_keyword_loc:
179-
├── closing_loc:
218+
├── keyword_loc: (15,0)-(15,5) = "until"
219+
├── do_keyword_loc: (15,14)-(15,16) = "do"
220+
├── closing_loc: (15,19)-(15,22) = "end"
180221
├── predicate:
181-
│ @ MatchPredicateNode (location: (13,10)-(13,20))
222+
│ @ MatchPredicateNode (location: (15,6)-(15,13))
182223
│ ├── flags: ∅
183224
│ ├── value:
184-
│ │ @ CallNode (location: (13,10)-(13,13))
225+
│ │ @ CallNode (location: (15,6)-(15,7))
185226
│ │ ├── flags: variable_call, ignore_visibility
186227
│ │ ├── receiver: ∅
187228
│ │ ├── call_operator_loc: ∅
188-
│ │ ├── name: :bar
189-
│ │ ├── message_loc: (13,10)-(13,13) = "bar"
229+
│ │ ├── name: :a
230+
│ │ ├── message_loc: (15,6)-(15,7) = "a"
190231
│ │ ├── opening_loc: ∅
191232
│ │ ├── arguments: ∅
192233
│ │ ├── closing_loc: ∅
193234
│ │ ├── equal_loc: ∅
194235
│ │ └── block: ∅
195236
│ ├── pattern:
196-
│ │ @ LocalVariableTargetNode (location: (13,17)-(13,20))
237+
│ │ @ ArrayPatternNode (location: (15,11)-(15,13))
197238
│ │ ├── flags: ∅
198-
│ │ ├── name: :baz
199-
│ │ └── depth: 0
200-
│ └── operator_loc: (13,14)-(13,16) = "in"
239+
│ │ ├── constant: ∅
240+
│ │ ├── requireds: (length: 1)
241+
│ │ │ └── @ LocalVariableTargetNode (location: (15,11)-(15,12))
242+
│ │ │ ├── flags: ∅
243+
│ │ │ ├── name: :b
244+
│ │ │ └── depth: 0
245+
│ │ ├── rest:
246+
│ │ │ @ ImplicitRestNode (location: (15,12)-(15,13))
247+
│ │ │ └── flags: ∅
248+
│ │ ├── posts: (length: 0)
249+
│ │ ├── opening_loc: ∅
250+
│ │ └── closing_loc: ∅
251+
│ └── operator_loc: (15,8)-(15,10) = "in"
201252
└── statements:
202-
@ StatementsNode (location: (13,0)-(13,3))
253+
@ StatementsNode (location: (15,17)-(15,18))
203254
├── flags: ∅
204255
└── body: (length: 1)
205-
└── @ CallNode (location: (13,0)-(13,3))
206-
├── flags: newline, variable_call, ignore_visibility
207-
├── receiver: ∅
208-
├── call_operator_loc: ∅
209-
├── name: :foo
210-
├── message_loc: (13,0)-(13,3) = "foo"
211-
├── opening_loc: ∅
212-
├── arguments: ∅
213-
├── closing_loc: ∅
214-
├── equal_loc: ∅
215-
└── block: ∅
256+
└── @ IntegerNode (location: (15,17)-(15,18))
257+
├── flags: newline, static_literal, decimal
258+
└── value: 1

snapshots/while.txt

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@ ProgramNode (location: (1,0)-(23,20))
1+
@ ProgramNode (location: (1,0)-(25,22))
22
├── flags: ∅
3-
├── locals: [:baz]
3+
├── locals: [:baz, :b]
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(23,20))
5+
@ StatementsNode (location: (1,0)-(25,22))
66
├── flags: ∅
7-
└── body: (length: 12)
7+
└── body: (length: 13)
88
├── @ WhileNode (location: (1,0)-(1,18))
99
│ ├── flags: newline
1010
│ ├── keyword_loc: (1,0)-(1,5) = "while"
@@ -513,44 +513,87 @@
513513
│ │ ├── equal_loc: (21,14)-(21,15) = "="
514514
│ │ └── end_keyword_loc: ∅
515515
│ └── statements: ∅
516-
└── @ WhileNode (location: (23,0)-(23,20))
516+
├── @ WhileNode (location: (23,0)-(23,20))
517+
│ ├── flags: newline
518+
│ ├── keyword_loc: (23,4)-(23,9) = "while"
519+
│ ├── do_keyword_loc: ∅
520+
│ ├── closing_loc: ∅
521+
│ ├── predicate:
522+
│ │ @ MatchPredicateNode (location: (23,10)-(23,20))
523+
│ │ ├── flags: ∅
524+
│ │ ├── value:
525+
│ │ │ @ CallNode (location: (23,10)-(23,13))
526+
│ │ │ ├── flags: variable_call, ignore_visibility
527+
│ │ │ ├── receiver: ∅
528+
│ │ │ ├── call_operator_loc: ∅
529+
│ │ │ ├── name: :bar
530+
│ │ │ ├── message_loc: (23,10)-(23,13) = "bar"
531+
│ │ │ ├── opening_loc: ∅
532+
│ │ │ ├── arguments: ∅
533+
│ │ │ ├── closing_loc: ∅
534+
│ │ │ ├── equal_loc: ∅
535+
│ │ │ └── block: ∅
536+
│ │ ├── pattern:
537+
│ │ │ @ LocalVariableTargetNode (location: (23,17)-(23,20))
538+
│ │ │ ├── flags: ∅
539+
│ │ │ ├── name: :baz
540+
│ │ │ └── depth: 0
541+
│ │ └── operator_loc: (23,14)-(23,16) = "in"
542+
│ └── statements:
543+
│ @ StatementsNode (location: (23,0)-(23,3))
544+
│ ├── flags: ∅
545+
│ └── body: (length: 1)
546+
│ └── @ CallNode (location: (23,0)-(23,3))
547+
│ ├── flags: newline, variable_call, ignore_visibility
548+
│ ├── receiver: ∅
549+
│ ├── call_operator_loc: ∅
550+
│ ├── name: :foo
551+
│ ├── message_loc: (23,0)-(23,3) = "foo"
552+
│ ├── opening_loc: ∅
553+
│ ├── arguments: ∅
554+
│ ├── closing_loc: ∅
555+
│ ├── equal_loc: ∅
556+
│ └── block: ∅
557+
└── @ WhileNode (location: (25,0)-(25,22))
517558
├── flags: newline
518-
├── keyword_loc: (23,4)-(23,9) = "while"
519-
├── do_keyword_loc:
520-
├── closing_loc:
559+
├── keyword_loc: (25,0)-(25,5) = "while"
560+
├── do_keyword_loc: (25,14)-(25,16) = "do"
561+
├── closing_loc: (25,19)-(25,22) = "end"
521562
├── predicate:
522-
│ @ MatchPredicateNode (location: (23,10)-(23,20))
563+
│ @ MatchPredicateNode (location: (25,6)-(25,13))
523564
│ ├── flags: ∅
524565
│ ├── value:
525-
│ │ @ CallNode (location: (23,10)-(23,13))
566+
│ │ @ CallNode (location: (25,6)-(25,7))
526567
│ │ ├── flags: variable_call, ignore_visibility
527568
│ │ ├── receiver: ∅
528569
│ │ ├── call_operator_loc: ∅
529-
│ │ ├── name: :bar
530-
│ │ ├── message_loc: (23,10)-(23,13) = "bar"
570+
│ │ ├── name: :a
571+
│ │ ├── message_loc: (25,6)-(25,7) = "a"
531572
│ │ ├── opening_loc: ∅
532573
│ │ ├── arguments: ∅
533574
│ │ ├── closing_loc: ∅
534575
│ │ ├── equal_loc: ∅
535576
│ │ └── block: ∅
536577
│ ├── pattern:
537-
│ │ @ LocalVariableTargetNode (location: (23,17)-(23,20))
578+
│ │ @ ArrayPatternNode (location: (25,11)-(25,13))
538579
│ │ ├── flags: ∅
539-
│ │ ├── name: :baz
540-
│ │ └── depth: 0
541-
│ └── operator_loc: (23,14)-(23,16) = "in"
580+
│ │ ├── constant: ∅
581+
│ │ ├── requireds: (length: 1)
582+
│ │ │ └── @ LocalVariableTargetNode (location: (25,11)-(25,12))
583+
│ │ │ ├── flags: ∅
584+
│ │ │ ├── name: :b
585+
│ │ │ └── depth: 0
586+
│ │ ├── rest:
587+
│ │ │ @ ImplicitRestNode (location: (25,12)-(25,13))
588+
│ │ │ └── flags: ∅
589+
│ │ ├── posts: (length: 0)
590+
│ │ ├── opening_loc: ∅
591+
│ │ └── closing_loc: ∅
592+
│ └── operator_loc: (25,8)-(25,10) = "in"
542593
└── statements:
543-
@ StatementsNode (location: (23,0)-(23,3))
594+
@ StatementsNode (location: (25,17)-(25,18))
544595
├── flags: ∅
545596
└── body: (length: 1)
546-
└── @ CallNode (location: (23,0)-(23,3))
547-
├── flags: newline, variable_call, ignore_visibility
548-
├── receiver: ∅
549-
├── call_operator_loc: ∅
550-
├── name: :foo
551-
├── message_loc: (23,0)-(23,3) = "foo"
552-
├── opening_loc: ∅
553-
├── arguments: ∅
554-
├── closing_loc: ∅
555-
├── equal_loc: ∅
556-
└── block: ∅
597+
└── @ IntegerNode (location: (25,17)-(25,18))
598+
├── flags: newline, static_literal, decimal
599+
└── value: 1

0 commit comments

Comments
 (0)