Skip to content

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

Merged
nobu merged 1 commit into
ruby:masterfrom
alpaca-tc:fix-ast-node-source
Nov 4, 2023
Merged

ast.rb: Fix bug for source of multibyte characters#8844
nobu merged 1 commit into
ruby:masterfrom
alpaca-tc:fix-ast-node-source

Conversation

@alpaca-tc

Copy link
Copy Markdown
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