Skip to content

ast.rb: Fix bug for source of multibyte characters #8844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2023

Conversation

alpaca-tc
Copy link
Contributor

RubyVM::AbstractSyntaxTree::Node's #first_column and #last_column return byte positions, but existing implementations did not consider multi-byte.

ast = RubyVM::AbstractSyntaxTree.parse(%{a("§");b("©")}, keep_script_lines: true)
a_fcall, b_fcall = ast.children[2].children

puts a_fcall.source
puts b_fcall.source
# before
a("§");
("©")

# after
a("§")
b("©")

first_column and last_column return byte positions, but existing implementations
did not consider multibyte.
@nobu nobu merged commit 8ed733f into ruby:master Nov 4, 2023
@alpaca-tc alpaca-tc deleted the fix-ast-node-source branch November 4, 2023 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants