Skip to content

fix: support full Unicode in account names (Cyrillic, CJK, Arabic, etc.) - #817

Merged
robcohen merged 5 commits into
mainfrom
fix/issue-816-unicode-accounts
Apr 14, 2026
Merged

robcohen merged 5 commits into
mainfrom
fix/issue-816-unicode-accounts

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

Allow account name components to start with any Unicode uppercase letter or CJK ideograph, not just ASCII [A-Z].

Before / After

; BEFORE: parse error
option "name_equity" "Капитал"
2024-01-01 open Капитал:Retained-Earnings  ; ❌ "Invalid account"

; AFTER: works
option "name_equity" "Капитал"
2024-01-01 open Капитал:Retained-Earnings  ; ✓

; Also works:
option "name_assets" "资产"
2024-01-01 open 资产:银行:支票  ; ✓ CJK

Why

The beancount v3 spec restricts account components to start with ASCII [A-Z]. This is an artifact of the C flex lexer's poor Unicode support, not a meaningful language design choice. It has been a longstanding pain point for non-Latin users:

  • beancount#161 (2015) — Russian user, Blais said "will come after 1.0". Never came.
  • beancount#398 (2017) — CJK users requesting logogram support. Still open.
  • beancount#733 (2023) — Chinese user. Still open.
  • beancount#377 — Python beancount v2's regex uses \p{Lu} but is_root_account() still uses [A-Z]. Inconsistent.

Python beancount v2 partially supports Unicode uppercase via \p{Lu} in the account regex, but internal functions are inconsistent. Rustledger now fully supports it throughout.

Change

Lexer regex: [A-Z] → [\p{Lu}\p{Lo}\p{Lt}]

  • \p{Lu} — Unicode uppercase letters (Latin A-Z, Cyrillic А-Я, Greek Α-Ω, etc.)
  • \p{Lo} — Letters without case (CJK ideographs, Arabic, Hebrew, etc.)
  • \p{Lt} — Titlecase letters

Emoji and symbols remain rejected (not letters).

Test plan

  • Cyrillic accounts: Капитал:Retained-Earnings ✓
  • CJK accounts: 资产:银行:支票 ✓
  • Mixed: Assets:銀行口座 ✓
  • Emoji still rejected: Assets:CORP✨ ✗
  • All existing tests pass (parser, validator, loader)
  • Clippy clean

Closes #816

🤖 Generated with Claude Code

Closes #816

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 14, 2026 15:52
@robcohen
robcohen requested a review from a team as a code owner April 14, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates rustledger’s account-name handling to accept Unicode scripts (e.g., Cyrillic and CJK) as valid account component starts, aligning parser behavior with the stated goal of supporting non-Latin account names.

Changes:

  • Expand the Logos lexer Account token regex to allow Unicode letter categories at component starts.
  • Update parser integration/unit tests to expect Unicode accounts to parse successfully.
  • Adjust validation helper logic/comments toward Unicode support (but see review comments for a correctness gap).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/rustledger-validate/src/validators/helpers.rs Updates account-component start validation logic intended to allow Unicode starts.
crates/rustledger-parser/src/logos_lexer.rs Expands the Account token regex and updates documentation/tests for Unicode accounts.
crates/rustledger-parser/tests/parser_integration_test.rs Changes integration test to accept Unicode accounts during parsing.
crates/rustledger-parser/src/winnow_parser.rs Updates parser unit test to assert Unicode accounts parse without errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 29ms ± 0.1ms 21.2 MB
beancount 867.6ms ± 7.1ms 50.2 MB
Comparison 29.9x faster 2.4x less

vs main branch (2026-04-14)

Metric main this PR Change
Time 40ms 29ms -27.5% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Add Unicode account examples to syntax.md showing Cyrillic and CJK
account types. Remove stale reference to beancount C lexer in
validator comment.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 782
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.58824% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-lsp/src/handlers/diagnostics.rs 28.57% 5 Missing ⚠️
crates/rustledger-parser/src/winnow_parser.rs 37.50% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 4b09f1f Apr 14, 2026
41 of 43 checks passed
@robcohen
robcohen deleted the fix/issue-816-unicode-accounts branch April 14, 2026 19:09
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.

[Bug]: rledger format error on Unicode accounts

2 participants