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

Fix incorrect col calculate for pair.line_col method, and add integration test for cover it. #768

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

huacnlee
Copy link
Member

@huacnlee huacnlee commented Jan 12, 2023

Hi @tomtau, when I use the new pair.line_col method in my project.

I found that col value is not correct:

image

https://github.com/pest-parser/pest/actions/runs/3899423161/jobs/6659084167

So I try to fix it, and add a complex integration test for cover it.

@huacnlee huacnlee requested a review from a team as a code owner January 12, 2023 04:13
@huacnlee huacnlee requested review from tomtau and removed request for a team January 12, 2023 04:13
@huacnlee huacnlee changed the title Fix incorrect col calculate, and add integration test for cover it. Fix incorrect col calculate for pair.line_col method, and add integration test for cover it. Jan 12, 2023
@huacnlee huacnlee force-pushed the fix-line-col-calc branch 2 times, most recently from 74eea2a to d0e5d70 Compare January 12, 2023 05:20
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

Would it be possible to leverage the original line-col function (to give it an extra argument)?

pest/src/iterators/pairs.rs Outdated Show resolved Hide resolved
@NoahTheDuke
Copy link
Member

The code itself looks solid. I'm a little confused by why this change is needed. I think I just don't quite understand how the lines and cols are determined. Why do we need to start at 1,1 sometimes and 0,0 other times?

@huacnlee
Copy link
Member Author

huacnlee commented Jan 12, 2023

@NoahTheDuke In Pairs#move_cursor, it calculates the (line, col) position by uses a part of string by keep accumulating.

So it call Position#line_col just need get a number of offset of that str need to move (This is not like line, col. line, col is start from 1,1 buf offset need start with 0,0).

Here is a test fail result, before I change:

https://github.com/pest-parser/pest/actions/runs/3899423161/jobs/6659084167

@NoahTheDuke
Copy link
Member

Cool, thanks.

@tomtau tomtau merged commit 56cef18 into pest-parser:master Jan 13, 2023
@huacnlee huacnlee deleted the fix-line-col-calc branch January 13, 2023 01:00
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