@@ -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
0 commit comments