Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 48ce375

Browse files
committed
Handle multibyte strings
1 parent c212530 commit 48ce375

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/syntax_tree/parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def char_pos
166166
# This represents the current column we're in relative to the beginning of
167167
# the current line.
168168
def current_column
169-
column - line_counts[lineno - 1].start
169+
line = line_counts[lineno - 1]
170+
line[column].to_i - line.start
170171
end
171172

172173
# As we build up a list of tokens, we'll periodically need to go backwards

test/node_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,16 @@ def test_column_positions
10091009
assert_node(Command, "command", source, at: at)
10101010
end
10111011

1012+
def test_multibyte_column_positions
1013+
source = <<~SOURCE
1014+
puts "Congrats"
1015+
puts "🎉 🎉"
1016+
SOURCE
1017+
1018+
at = location(lines: 2..2, chars: 16..26, columns: 0..10)
1019+
assert_node(Command, "command", source, at: at)
1020+
end
1021+
10121022
private
10131023

10141024
def location(lines: 1..1, chars: 0..0, columns: 0..0)

0 commit comments

Comments
 (0)