Skip to content

Commit d3c3ca4

Browse files
authored
Merge pull request #3692 from ruby/equal-loc
Add equal_loc to call nodes
2 parents a192db5 + bfc798a commit d3c3ca4

File tree

626 files changed

+3114
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

626 files changed

+3114
-16
lines changed

config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,16 @@ nodes:
15151515
15161516
foo(bar)
15171517
^
1518+
- name: equal_loc
1519+
type: location?
1520+
comment: |
1521+
Represents the location of the equal sign, in the case that this is an attribute write.
1522+
1523+
foo.bar = value
1524+
^
1525+
1526+
foo[bar] = value
1527+
^
15181528
- name: block
15191529
type: node?
15201530
kind:

lib/prism/translation/parser/compiler.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def visit_begin_node(node)
217217
rescue_clause.exceptions.any? ? builder.array(nil, visit_all(rescue_clause.exceptions), nil) : nil,
218218
token(rescue_clause.operator_loc),
219219
visit(rescue_clause.reference),
220-
srange_find(find_start_offset, find_end_offset, ";"),
220+
srange_semicolon(find_start_offset, find_end_offset),
221221
visit(rescue_clause.statements)
222222
)
223223
end until (rescue_clause = rescue_clause.subsequent).nil?
@@ -323,7 +323,7 @@ def visit_call_node(node)
323323
visit_all(arguments),
324324
token(node.closing_loc),
325325
),
326-
srange_find(node.message_loc.end_offset, node.arguments.arguments.last.location.start_offset, "="),
326+
token(node.equal_loc),
327327
visit(node.arguments.arguments.last)
328328
),
329329
block
@@ -340,7 +340,7 @@ def visit_call_node(node)
340340
if name.end_with?("=") && !message_loc.slice.end_with?("=") && node.arguments && block.nil?
341341
builder.assign(
342342
builder.attr_asgn(visit(node.receiver), call_operator, token(message_loc)),
343-
srange_find(message_loc.end_offset, node.arguments.location.start_offset, "="),
343+
token(node.equal_loc),
344344
visit(node.arguments.arguments.last)
345345
)
346346
else
@@ -789,7 +789,7 @@ def visit_for_node(node)
789789
if (do_keyword_loc = node.do_keyword_loc)
790790
token(do_keyword_loc)
791791
else
792-
srange_find(node.collection.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset, ";")
792+
srange_semicolon(node.collection.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset)
793793
end,
794794
visit(node.statements),
795795
token(node.end_keyword_loc)
@@ -921,7 +921,7 @@ def visit_if_node(node)
921921
if (then_keyword_loc = node.then_keyword_loc)
922922
token(then_keyword_loc)
923923
else
924-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset, ";")
924+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset)
925925
end,
926926
visit(node.statements),
927927
case node.subsequent
@@ -987,7 +987,7 @@ def visit_in_node(node)
987987
if (then_loc = node.then_loc)
988988
token(then_loc)
989989
else
990-
srange_find(node.pattern.location.end_offset, node.statements&.location&.start_offset, ";")
990+
srange_semicolon(node.pattern.location.end_offset, node.statements&.location&.start_offset)
991991
end,
992992
visit(node.statements)
993993
)
@@ -1808,7 +1808,7 @@ def visit_unless_node(node)
18081808
if (then_keyword_loc = node.then_keyword_loc)
18091809
token(then_keyword_loc)
18101810
else
1811-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset, ";")
1811+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset)
18121812
end,
18131813
visit(node.else_clause),
18141814
token(node.else_clause&.else_keyword_loc),
@@ -1839,7 +1839,7 @@ def visit_until_node(node)
18391839
if (do_keyword_loc = node.do_keyword_loc)
18401840
token(do_keyword_loc)
18411841
else
1842-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, ";")
1842+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset)
18431843
end,
18441844
visit(node.statements),
18451845
token(node.closing_loc)
@@ -1863,7 +1863,7 @@ def visit_when_node(node)
18631863
if (then_keyword_loc = node.then_keyword_loc)
18641864
token(then_keyword_loc)
18651865
else
1866-
srange_find(node.conditions.last.location.end_offset, node.statements&.location&.start_offset, ";")
1866+
srange_semicolon(node.conditions.last.location.end_offset, node.statements&.location&.start_offset)
18671867
end,
18681868
visit(node.statements)
18691869
)
@@ -1883,7 +1883,7 @@ def visit_while_node(node)
18831883
if (do_keyword_loc = node.do_keyword_loc)
18841884
token(do_keyword_loc)
18851885
else
1886-
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, ";")
1886+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset)
18871887
end,
18881888
visit(node.statements),
18891889
token(node.closing_loc)
@@ -2012,16 +2012,16 @@ def srange_offsets(start_offset, end_offset)
20122012
Range.new(source_buffer, offset_cache[start_offset], offset_cache[end_offset])
20132013
end
20142014

2015-
# Constructs a new source range by finding the given character between
2016-
# the given start offset and end offset. If the needle is not found, it
2017-
# returns nil. Importantly it does not search past newlines or comments.
2015+
# Constructs a new source range by finding a semicolon between the given
2016+
# start offset and end offset. If the semicolon is not found, it returns
2017+
# nil. Importantly it does not search past newlines or comments.
20182018
#
20192019
# Note that end_offset is allowed to be nil, in which case this will
20202020
# search until the end of the string.
2021-
def srange_find(start_offset, end_offset, character)
2022-
if (match = source_buffer.source.byteslice(start_offset...end_offset)[/\A\s*#{character}/])
2021+
def srange_semicolon(start_offset, end_offset)
2022+
if (match = source_buffer.source.byteslice(start_offset...end_offset)[/\A\s*;/])
20232023
final_offset = start_offset + match.bytesize
2024-
[character, Range.new(source_buffer, offset_cache[final_offset - character.bytesize], offset_cache[final_offset])]
2024+
[";", Range.new(source_buffer, offset_cache[final_offset - 1], offset_cache[final_offset])]
20252025
end
20262026
end
20272027

snapshots/3.3-3.3/block_args_in_array_assignment.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
│ ├── opening_loc: ∅
1818
│ ├── arguments: ∅
1919
│ ├── closing_loc: ∅
20+
│ ├── equal_loc: ∅
2021
│ └── block: ∅
2122
├── call_operator_loc: ∅
2223
├── name: :[]=
@@ -33,6 +34,7 @@
3334
│ ├── flags: static_literal, decimal
3435
│ └── value: 8
3536
├── closing_loc: (1,16)-(1,17) = "]"
37+
├── equal_loc: (1,18)-(1,19) = "="
3638
└── block:
3739
@ BlockArgumentNode (location: (1,10)-(1,16))
3840
├── flags: ∅
@@ -46,5 +48,6 @@
4648
│ ├── opening_loc: ∅
4749
│ ├── arguments: ∅
4850
│ ├── closing_loc: ∅
51+
│ ├── equal_loc: ∅
4952
│ └── block: ∅
5053
└── operator_loc: (1,10)-(1,11) = "&"

snapshots/3.3-3.3/it.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
│ ├── opening_loc: ∅
1515
│ ├── arguments: ∅
1616
│ ├── closing_loc: ∅
17+
│ ├── equal_loc: ∅
1718
│ └── block:
1819
│ @ BlockNode (location: (1,2)-(3,3))
1920
│ ├── flags: ∅
@@ -32,6 +33,7 @@
3233
│ │ ├── opening_loc: ∅
3334
│ │ ├── arguments: ∅
3435
│ │ ├── closing_loc: ∅
36+
│ │ ├── equal_loc: ∅
3537
│ │ └── block: ∅
3638
│ ├── opening_loc: (1,2)-(1,4) = "do"
3739
│ └── closing_loc: (3,0)-(3,3) = "end"
@@ -55,4 +57,5 @@
5557
├── opening_loc: ∅
5658
├── arguments: ∅
5759
├── closing_loc: ∅
60+
├── equal_loc: ∅
5861
└── block: ∅

snapshots/3.3-3.3/it_indirect_writes.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
│ ├── opening_loc: ∅
1515
│ ├── arguments: ∅
1616
│ ├── closing_loc: ∅
17+
│ ├── equal_loc: ∅
1718
│ └── block:
1819
│ @ BlockNode (location: (1,4)-(1,15))
1920
│ ├── flags: ∅
@@ -45,6 +46,7 @@
4546
│ ├── opening_loc: ∅
4647
│ ├── arguments: ∅
4748
│ ├── closing_loc: ∅
49+
│ ├── equal_loc: ∅
4850
│ └── block:
4951
│ @ BlockNode (location: (3,4)-(3,16))
5052
│ ├── flags: ∅
@@ -75,6 +77,7 @@
7577
│ ├── opening_loc: ∅
7678
│ ├── arguments: ∅
7779
│ ├── closing_loc: ∅
80+
│ ├── equal_loc: ∅
7881
│ └── block:
7982
│ @ BlockNode (location: (5,4)-(5,16))
8083
│ ├── flags: ∅
@@ -105,6 +108,7 @@
105108
│ ├── opening_loc: ∅
106109
│ ├── arguments: ∅
107110
│ ├── closing_loc: ∅
111+
│ ├── equal_loc: ∅
108112
│ └── block:
109113
│ @ BlockNode (location: (7,4)-(7,19))
110114
│ ├── flags: ∅
@@ -123,6 +127,7 @@
123127
│ │ │ ├── opening_loc: ∅
124128
│ │ │ ├── arguments: ∅
125129
│ │ │ ├── closing_loc: ∅
130+
│ │ │ ├── equal_loc: ∅
126131
│ │ │ └── block: ∅
127132
│ │ └── @ LocalVariableOperatorWriteNode (location: (7,10)-(7,17))
128133
│ │ ├── flags: newline
@@ -146,6 +151,7 @@
146151
│ ├── opening_loc: ∅
147152
│ ├── arguments: ∅
148153
│ ├── closing_loc: ∅
154+
│ ├── equal_loc: ∅
149155
│ └── block:
150156
│ @ BlockNode (location: (9,4)-(9,20))
151157
│ ├── flags: ∅
@@ -164,6 +170,7 @@
164170
│ │ │ ├── opening_loc: ∅
165171
│ │ │ ├── arguments: ∅
166172
│ │ │ ├── closing_loc: ∅
173+
│ │ │ ├── equal_loc: ∅
167174
│ │ │ └── block: ∅
168175
│ │ └── @ LocalVariableOrWriteNode (location: (9,10)-(9,18))
169176
│ │ ├── flags: newline
@@ -186,6 +193,7 @@
186193
│ ├── opening_loc: ∅
187194
│ ├── arguments: ∅
188195
│ ├── closing_loc: ∅
196+
│ ├── equal_loc: ∅
189197
│ └── block:
190198
│ @ BlockNode (location: (11,4)-(11,20))
191199
│ ├── flags: ∅
@@ -204,6 +212,7 @@
204212
│ │ │ ├── opening_loc: ∅
205213
│ │ │ ├── arguments: ∅
206214
│ │ │ ├── closing_loc: ∅
215+
│ │ │ ├── equal_loc: ∅
207216
│ │ │ └── block: ∅
208217
│ │ └── @ LocalVariableAndWriteNode (location: (11,10)-(11,18))
209218
│ │ ├── flags: newline
@@ -226,6 +235,7 @@
226235
│ ├── opening_loc: ∅
227236
│ ├── arguments: ∅
228237
│ ├── closing_loc: ∅
238+
│ ├── equal_loc: ∅
229239
│ └── block:
230240
│ @ BlockNode (location: (13,4)-(13,19))
231241
│ ├── flags: ∅
@@ -261,6 +271,7 @@
261271
│ ├── opening_loc: ∅
262272
│ ├── arguments: ∅
263273
│ ├── closing_loc: ∅
274+
│ ├── equal_loc: ∅
264275
│ └── block:
265276
│ @ BlockNode (location: (15,4)-(15,20))
266277
│ ├── flags: ∅
@@ -295,6 +306,7 @@
295306
│ ├── opening_loc: ∅
296307
│ ├── arguments: ∅
297308
│ ├── closing_loc: ∅
309+
│ ├── equal_loc: ∅
298310
│ └── block:
299311
│ @ BlockNode (location: (17,4)-(17,20))
300312
│ ├── flags: ∅
@@ -329,6 +341,7 @@
329341
│ ├── opening_loc: ∅
330342
│ ├── arguments: ∅
331343
│ ├── closing_loc: ∅
344+
│ ├── equal_loc: ∅
332345
│ └── block:
333346
│ @ BlockNode (location: (19,4)-(19,23))
334347
│ ├── flags: ∅
@@ -347,6 +360,7 @@
347360
│ │ │ ├── opening_loc: ∅
348361
│ │ │ ├── arguments: ∅
349362
│ │ │ ├── closing_loc: ∅
363+
│ │ │ ├── equal_loc: ∅
350364
│ │ │ └── block: ∅
351365
│ │ ├── @ LocalVariableOperatorWriteNode (location: (19,10)-(19,17))
352366
│ │ │ ├── flags: newline
@@ -374,6 +388,7 @@
374388
│ ├── opening_loc: ∅
375389
│ ├── arguments: ∅
376390
│ ├── closing_loc: ∅
391+
│ ├── equal_loc: ∅
377392
│ └── block:
378393
│ @ BlockNode (location: (21,4)-(21,24))
379394
│ ├── flags: ∅
@@ -392,6 +407,7 @@
392407
│ │ │ ├── opening_loc: ∅
393408
│ │ │ ├── arguments: ∅
394409
│ │ │ ├── closing_loc: ∅
410+
│ │ │ ├── equal_loc: ∅
395411
│ │ │ └── block: ∅
396412
│ │ ├── @ LocalVariableOrWriteNode (location: (21,10)-(21,18))
397413
│ │ │ ├── flags: newline
@@ -418,6 +434,7 @@
418434
├── opening_loc: ∅
419435
├── arguments: ∅
420436
├── closing_loc: ∅
437+
├── equal_loc: ∅
421438
└── block:
422439
@ BlockNode (location: (23,4)-(23,24))
423440
├── flags: ∅
@@ -436,6 +453,7 @@
436453
│ │ ├── opening_loc: ∅
437454
│ │ ├── arguments: ∅
438455
│ │ ├── closing_loc: ∅
456+
│ │ ├── equal_loc: ∅
439457
│ │ └── block: ∅
440458
│ ├── @ LocalVariableAndWriteNode (location: (23,10)-(23,18))
441459
│ │ ├── flags: newline

snapshots/3.3-3.3/it_read_and_assignment.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
├── opening_loc: ∅
1818
├── arguments: ∅
1919
├── closing_loc: ∅
20+
├── equal_loc: ∅
2021
└── block:
2122
@ BlockNode (location: (1,7)-(1,30))
2223
├── flags: ∅
@@ -46,8 +47,10 @@
4647
│ │ │ ├── opening_loc: ∅
4748
│ │ │ ├── arguments: ∅
4849
│ │ │ ├── closing_loc: ∅
50+
│ │ │ ├── equal_loc: ∅
4951
│ │ │ └── block: ∅
5052
│ │ ├── closing_loc: ∅
53+
│ │ ├── equal_loc: ∅
5154
│ │ └── block: ∅
5255
│ ├── @ LocalVariableWriteNode (location: (1,15)-(1,22))
5356
│ │ ├── flags: newline
@@ -76,6 +79,7 @@
7679
│ │ ├── name: :it
7780
│ │ └── depth: 0
7881
│ ├── closing_loc: ∅
82+
│ ├── equal_loc: ∅
7983
│ └── block: ∅
8084
├── opening_loc: (1,7)-(1,8) = "{"
8185
└── closing_loc: (1,29)-(1,30) = "}"

snapshots/3.3-3.3/it_with_ordinary_parameter.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
├── opening_loc: ∅
1515
├── arguments: ∅
1616
├── closing_loc: ∅
17+
├── equal_loc: ∅
1718
└── block:
1819
@ BlockNode (location: (1,5)-(1,14))
1920
├── flags: ∅
@@ -38,6 +39,7 @@
3839
│ ├── opening_loc: ∅
3940
│ ├── arguments: ∅
4041
│ ├── closing_loc: ∅
42+
│ ├── equal_loc: ∅
4143
│ └── block: ∅
4244
├── opening_loc: (1,5)-(1,6) = "{"
4345
└── closing_loc: (1,13)-(1,14) = "}"

snapshots/3.3-3.3/keyword_args_in_array_assignment.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
│ ├── opening_loc: ∅
1818
│ ├── arguments: ∅
1919
│ ├── closing_loc: ∅
20+
│ ├── equal_loc: ∅
2021
│ └── block: ∅
2122
├── call_operator_loc: ∅
2223
├── name: :[]=
@@ -53,4 +54,5 @@
5354
│ ├── flags: static_literal, decimal
5455
│ └── value: 8
5556
├── closing_loc: (1,18)-(1,19) = "]"
57+
├── equal_loc: (1,20)-(1,21) = "="
5658
└── block: ∅

snapshots/3.4/circular_parameters.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
│ ├── opening_loc: ∅
9292
│ ├── arguments: ∅
9393
│ ├── closing_loc: ∅
94+
│ ├── equal_loc: ∅
9495
│ └── block:
9596
│ @ BlockNode (location: (3,5)-(3,20))
9697
│ ├── flags: ∅
@@ -133,6 +134,7 @@
133134
├── opening_loc: ∅
134135
├── arguments: ∅
135136
├── closing_loc: ∅
137+
├── equal_loc: ∅
136138
└── block:
137139
@ BlockNode (location: (4,5)-(4,19))
138140
├── flags: ∅

snapshots/3.4/it.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
│ ├── opening_loc: ∅
1515
│ ├── arguments: ∅
1616
│ ├── closing_loc: ∅
17+
│ ├── equal_loc: ∅
1718
│ └── block:
1819
│ @ BlockNode (location: (1,2)-(3,3))
1920
│ ├── flags: ∅

0 commit comments

Comments
 (0)