Skip to content

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

Draft
sei40kr wants to merge 5 commits intoruby:mainfrom
sei40kr:feat/rust-location-methods
Draft

[rust] add Location line/column and chop methods#3890
sei40kr wants to merge 5 commits 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 and others added 4 commits February 19, 2026 02:07
Port Ruby's `node_ext.rb` functionality to Rust bindings, providing
`full_name` and `full_name_parts` methods for `ConstantReadNode`,
`ConstantWriteNode`, `ConstantTargetNode`, `ConstantPathNode`, and
`ConstantPathTargetNode`.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… `chop` methods for `Location`

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…list_line_column

Bindgen cannot generate bindings for these symbols on the WASM target,
causing CI failures. Replace the bindgen allowlist entries with hand-
written repr(C) struct and extern C declarations so they work on all
targets (native and WASM).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add pm_line_offset_list_t to the bindgen allowlist and update the
manual FFI declarations and usage to match the upstream rename.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments