[rust] add Location line/column and chop methods#3890
[rust] add Location line/column and chop methods#3890
Location line/column and chop methods#3890Conversation
Location line/column and chop methods
|
Let's wait on #3860 for this. |
rust/ruby-prism-sys/src/lib.rs
Outdated
| extern "C" { | ||
| /// Return the line and column number for the given byte offset relative to | ||
| /// the beginning of the source. | ||
| pub fn pm_newline_list_line_column( |
There was a problem hiding this comment.
This doesn't exist anymore, because it was renamed. Please rebase.
b732d58 to
455afd6
Compare
rust/ruby-prism-sys/src/lib.rs
Outdated
| /// Line and column information for a given byte offset relative to the | ||
| /// beginning of the source. | ||
| #[repr(C)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct pm_line_column_t { | ||
| /// The 1-indexed line number relative to the start line configured on the | ||
| /// parser. | ||
| pub line: i32, | ||
| /// The 0-indexed column number in bytes. | ||
| pub column: u32, |
There was a problem hiding this comment.
The commit message for this explains that these are troublesome for the WASM target...but why are they troublesome, and can that be fixed instead? They really shouldn't be treated any differently than other structures, and it would be better to not maintain these declarations by hand. I trust bindgen more than manual declarations.
There was a problem hiding this comment.
Agreed, I don't want us manually maintaining parallel structures.
rust/ruby-prism-sys/src/lib.rs
Outdated
| /// Line and column information for a given byte offset relative to the | ||
| /// beginning of the source. | ||
| #[repr(C)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct pm_line_column_t { | ||
| /// The 1-indexed line number relative to the start line configured on the | ||
| /// parser. | ||
| pub line: i32, | ||
| /// The 0-indexed column number in bytes. | ||
| pub column: u32, |
There was a problem hiding this comment.
Agreed, I don't want us manually maintaining parallel structures.
8e9075c to
1f8adc0
Compare
366bdcb to
18ee95e
Compare
18ee95e to
8c1fa90
Compare
… `chop` methods for `Location` Line/column computation is implemented in Rust using binary search on the line_offsets array, matching the approach used by the Ruby and Java bindings rather than calling the C function via FFI. Co-Authored-By: Kevin Newton <kddnewton@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8c1fa90 to
814c3a6
Compare
|
Updated based on review feedback:
|
Summary
start_line()method toLocation(Rust equivalent of Ruby'sLocation#start_line)end_line()method toLocation(Rust equivalent of Ruby'sLocation#end_line)start_column()method toLocation(Rust equivalent of Ruby'sLocation#start_column)end_column()method toLocation(Rust equivalent of Ruby'sLocation#end_column)chop()method toLocation(Rust equivalent of Ruby'sLocation#chop)Line/column computation is implemented in Rust using binary search on the line offsets array, matching the approach used by the Ruby and Java bindings.
Public API Changes
Test plan
bundle exec rake cargo:testbundle exec rake cargo:lint🤖 Generated with Claude Code