Repository navigation
Apply rule X10 once and leave X9-removed characters out of the sequences - #16
Merged
Merged
Conversation
apply_bidi_algorithm now calls get_isolating_run_sequences once, right after phase X, and passes the result to apply_weak_rules and apply_neutral_rules, which used to compute it themselves. Comments explain why running each phase across all sequences matches the spec's per-sequence order, and why phase I can run on the whole paragraph. Verbose mode prints the sequences in a new X10 section (print_isolating_run_sequences in verbose_table.py). README.md, CLAUDE.md, example 7's note and the reviewing-functions command are updated to match. Both conformance suites still pass in full.
get_isolating_run_sequences now builds level runs only from the characters that X9 did not remove, and skips removed characters when it computes sos and eos. Before, each BN took the level of the character before it, so a leading LRE got the paragraph level and formed a one-character sequence of its own (example 6). The sequences now match the reference implementation's trace. Verbose mode lists the removed characters after the X10 sequences. Results are unchanged: both conformance suites pass in full.
Since X10 leaves the characters removed by X9 out of every isolating run sequence, the W and N helpers never see a BN. Remove the code that skipped over BN: the _get_prev_non_bn/_get_next_non_bn and _get_prev_non_et_bn/_get_next_non_et_bn helpers, and the BN branches in W1, W4, N0 and N1. W5 is rewritten to find each sequence of ETs and look at its two neighbours, as the rule is worded. Both conformance suites still pass in full.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apply_bidi_algorithmcomputes the isolating run sequences once, right after phase X, and passes them toapply_weak_rulesandapply_neutral_rules. Before, each of those two phases computed them itself. Comments explain why running each phase across all sequences matches the spec's sequence-by-sequence order, and why phase I can run over the whole paragraph (I1 and I2 look only at each character's own type and level).get_isolating_run_sequencesbuilds level runs only from the characters that X9 did not remove. Before, a BN took the level of the character before it, so the leading LRE in example 6 formed a one-character sequence of its own at level 0. The sequences now match the trace from the reference implementation (bidiref): one sequence, characters 1-10.sos/eos) and the characters removed by X9.The example 6 and 7 notes in
demo.py, README.md and CLAUDE.md are updated to match.Testing
tests/run_bidi_tests.py: 91707 passed, 0 failedtests/run_bidi_type_tests.py: 770241 passed, 0 failedpython bidi.py --allruns every example without errors