Skip to content
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

Print locations using line / col instead of offsets #1549

Merged
merged 1 commit into from
Sep 20, 2023
Merged

Conversation

jemmaissroff
Copy link
Collaborator

This commit changes printing of locations to use the format (start_line,start_column)-(end_line,end_column) instead of using offsets.

@@ -71,7 +71,7 @@ def copy(**options)

# Returns a string representation of this location.
def inspect
"#<YARP::Location @start_offset=#{@start_offset} @length=#{@length}>"
"#<YARP::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change I'm slightly unsure of, since start_line is not an instance variable. However, this output seems helpful to me for cases like printing error messages.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's only debug code, I think it's fine.

Copy link
Collaborator

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

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

Just needs a rebase

This commit changes printing of locations to use the format
(start_line,start_column)-(end_line,end_column) instead of using
offsets.
@eregon
Copy link
Member

eregon commented Sep 19, 2023

A more concise format that RubyVM::AST uses is 1:0-1:9, but I think the format in this PR is easier to read 👍

Columns are currently in number of bytes, that seems the case for RubyVM::AST too.
I think it's fine internally but e.g. in an editor it might not match for a UTF-8 file with non-ASCII characters.

@kddnewton
Copy link
Collaborator

@jemmaissroff could you look into the memcheck failure? Weird that it's failing on this, but I'm hoping it's surfacing something we can fix. I've found spin to be the best way to get access to valgrind.

@jemmaissroff jemmaissroff merged commit 0066cda into main Sep 20, 2023
38 checks passed
@jemmaissroff jemmaissroff deleted the line-col branch September 20, 2023 18:30
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