Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Handle multibyte strings
  • Loading branch information
vinistock committed Apr 12, 2022
commit 48ce3753499f3ad510c0234539c6c23f4ecfc784
3 changes: 2 additions & 1 deletion lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def char_pos
# This represents the current column we're in relative to the beginning of
# the current line.
def current_column
column - line_counts[lineno - 1].start
line = line_counts[lineno - 1]
line[column].to_i - line.start
end

# As we build up a list of tokens, we'll periodically need to go backwards
Expand Down
10 changes: 10 additions & 0 deletions test/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,16 @@ def test_column_positions
assert_node(Command, "command", source, at: at)
end

def test_multibyte_column_positions
source = <<~SOURCE
puts "Congrats"
puts "🎉 🎉"
SOURCE

at = location(lines: 2..2, chars: 16..26, columns: 0..10)
assert_node(Command, "command", source, at: at)
end

private

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