Skip to content

[rust] add Location line/column and chop methods#3890

Open
sei40kr wants to merge 1 commit intoruby:mainfrom
sei40kr:feat/rust-location-methods
Open

[rust] add Location line/column and chop methods#3890
sei40kr wants to merge 1 commit intoruby:mainfrom
sei40kr:feat/rust-location-methods

Conversation

@sei40kr
Copy link
Contributor

@sei40kr sei40kr commented Jan 29, 2026

Summary

  • Add start_line() method to Location (Rust equivalent of Ruby's Location#start_line)
  • Add end_line() method to Location (Rust equivalent of Ruby's Location#end_line)
  • Add start_column() method to Location (Rust equivalent of Ruby's Location#start_column)
  • Add end_column() method to Location (Rust equivalent of Ruby's Location#end_column)
  • Add chop() method to Location (Rust equivalent of Ruby's Location#chop)

These methods use the C API pm_newline_list_line_column function to compute line and column numbers.

Public API Changes

Removed items from the public API
=================================
(none)

Changed items in the public API
===============================
(none)

Added items to the public API
=============================
+pub const fn ruby_prism::Location<'pr>::chop(&self) -> Self
+pub fn ruby_prism::Location<'pr>::end_column(&self) -> u32
+pub fn ruby_prism::Location<'pr>::end_line(&self) -> i32
+pub fn ruby_prism::Location<'pr>::start_column(&self) -> u32
+pub fn ruby_prism::Location<'pr>::start_line(&self) -> i32

Test plan

  • bundle exec rake cargo:test
  • bundle exec rake cargo:lint

🤖 Generated with Claude Code

@sei40kr sei40kr changed the title [rust] Add Location line/column and chop methods [rust] add Location line/column and chop methods Jan 29, 2026
@sei40kr sei40kr changed the title [rust] add Location line/column and chop methods [rust] add Location line/column and chop methods Jan 29, 2026
@sei40kr sei40kr marked this pull request as draft January 29, 2026 09:20
@kddnewton
Copy link
Collaborator

Let's wait on #3860 for this.

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist anymore, because it was renamed. Please rebase.

@sei40kr sei40kr force-pushed the feat/rust-location-methods branch from b732d58 to 455afd6 Compare February 18, 2026 18:07
Comment on lines +39 to +48
/// 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I don't want us manually maintaining parallel structures.

Comment on lines +39 to +48
/// 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I don't want us manually maintaining parallel structures.

@kddnewton kddnewton removed the blocked label Feb 22, 2026
@kddnewton kddnewton force-pushed the feat/rust-location-methods branch 2 times, most recently from 8e9075c to 1f8adc0 Compare March 2, 2026 19:46
@kddnewton kddnewton marked this pull request as ready for review March 2, 2026 19:47
@kddnewton kddnewton force-pushed the feat/rust-location-methods branch 2 times, most recently from cf5c4bb to 366bdcb Compare March 2, 2026 19:58
… `chop` methods for `Location`

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kddnewton kddnewton force-pushed the feat/rust-location-methods branch from 366bdcb to 18ee95e Compare March 2, 2026 20:05
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.

3 participants