Skip to content

Fix full-width character alignment - #1593

Open
Selina-0017 wants to merge 1 commit into
lark-parser:masterfrom
Selina-0017:fix-fullwidth-error-location
Open

Fix full-width character alignment#1593
Selina-0017 wants to merge 1 commit into
lark-parser:masterfrom
Selina-0017:fix-fullwidth-error-location

Conversation

@Selina-0017

Copy link
Copy Markdown

Summary

Fix incorrect caret alignment in error context rendering when input contains full-width Unicode characters (e.g. Chinese characters).

Previously, caret positioning used character length (len()), which does not reflect terminal display width for full-width characters.

This caused misaligned error indicators in UnexpectedInput.get_context().

Changes

  • Replace naive character-count spacing with display-width-aware computation
  • Add regression test for full-width Unicode input

Testing

  • Added test covering full-width character alignment
  • All existing tests pass

Notes

No external dependencies added. Uses Python standard library only.

@erezsh

erezsh commented Jul 18, 2026

Copy link
Copy Markdown
Member

Hi, I ran it through a reviewer, can you address this finding?

Tab + full-width lines now overshoot the caret (a small regression). expandtabs() computes tab stops by character count while _display_width counts display columns, and the two compose
incorrectly. Verified: for before = "你好\tX", a terminal renders the error at display column 9, the old code correctly emitted 9 spaces, and the new code emits 11. So for lines mixing wide chars and tabs, the PR
makes alignment worse than before. Fixing it properly needs a width-aware tab expansion (advance to the next multiple of 8 in display columns) instead of _display_width(before.expandtabs()).

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.

2 participants