polytypo 1.17.5 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/polytypo/data/VERSION +1 -1
  3. data/lib/polytypo/data/fixtures/bg.json +1 -1
  4. data/lib/polytypo/data/fixtures/cs.json +1 -1
  5. data/lib/polytypo/data/fixtures/de-CH.json +1 -1
  6. data/lib/polytypo/data/fixtures/de-DE.json +1 -1
  7. data/lib/polytypo/data/fixtures/el.json +46 -4
  8. data/lib/polytypo/data/fixtures/en-GB.json +1 -1
  9. data/lib/polytypo/data/fixtures/en-US.json +1 -1
  10. data/lib/polytypo/data/fixtures/es.json +272 -7
  11. data/lib/polytypo/data/fixtures/fi.json +1 -1
  12. data/lib/polytypo/data/fixtures/fr-CA.json +1 -1
  13. data/lib/polytypo/data/fixtures/fr.json +1 -1
  14. data/lib/polytypo/data/fixtures/hr.json +1 -1
  15. data/lib/polytypo/data/fixtures/hu.json +1 -1
  16. data/lib/polytypo/data/fixtures/it.json +1 -1
  17. data/lib/polytypo/data/fixtures/locale-resolution.json +1 -1
  18. data/lib/polytypo/data/fixtures/lt.json +1 -1
  19. data/lib/polytypo/data/fixtures/nl.json +1 -1
  20. data/lib/polytypo/data/fixtures/pl.json +1 -1
  21. data/lib/polytypo/data/fixtures/pt-BR.json +1 -1
  22. data/lib/polytypo/data/fixtures/pt-PT.json +1 -1
  23. data/lib/polytypo/data/fixtures/ro.json +1 -1
  24. data/lib/polytypo/data/fixtures/ru.json +1 -1
  25. data/lib/polytypo/data/fixtures/sk.json +1 -1
  26. data/lib/polytypo/data/fixtures/sl.json +1 -1
  27. data/lib/polytypo/data/fixtures/sr.json +1 -1
  28. data/lib/polytypo/data/fixtures/sv.json +1 -1
  29. data/lib/polytypo/data/fixtures/tr.json +1 -1
  30. data/lib/polytypo/data/fixtures/uk.json +1 -1
  31. data/lib/polytypo/data/locales/el.json +2 -2
  32. data/lib/polytypo/data/locales/es.json +2 -2
  33. data/lib/polytypo/data/locales/registry.json +1 -1
  34. data/lib/polytypo/data/rules/dashes.md +115 -44
  35. data/lib/polytypo/data/rules/modes.md +0 -1
  36. data/lib/polytypo/data/rules/order.json +2 -2
  37. data/lib/polytypo/data/rules/pipeline-idempotency.md +7 -0
  38. data/lib/polytypo/data/schema/locale.schema.json +2 -2
  39. data/lib/polytypo/engine/rules/dash_shared.rb +32 -21
  40. data/lib/polytypo/engine/rules/dashes.rb +4 -1
  41. data/lib/polytypo/engine/rules/dashes_paired.rb +160 -0
  42. data/lib/polytypo/version.rb +1 -1
  43. metadata +2 -1
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "dash": {
22
- "parenthetical": "em-spaced",
22
+ "parenthetical": "em-paired",
23
23
  "range": "none"
24
24
  },
25
25
  "ellipsis": {
@@ -67,7 +67,7 @@
67
67
  "rule": "dashes",
68
68
  "cite": "RAE y ASALE, Diccionario panhispánico de dudas, entrada «raya», apartado 2: «Como el resto de los signos dobles, se escriben pegadas a la primera y a la última palabra del periodo que enmarcan, y separadas por un espacio de la palabra o signo que las precede o las sigue»",
69
69
  "url": "https://www.rae.es/dpd/raya",
70
- "note": "parenthetical = \"em-spaced\" ES UNA APROXIMACIÓN CONSCIENTE, no la norma, y se fijó por decisión del operador (27.10.2026). La fuente es explícita y prescribe espacios ORDINARIOS FUERA del par y ninguno en los bordes interiores («Llegó —por fin— a casa»). El enum no expresa esa asimetría: \"em-spaced\" pone un espacio a cada lado de CADA raya, de modo que el texto resultante lleva dos espacios interiores que el DPD no admite («Llegó — por fin — a casa»); \"em-tight\" suprimiría los exteriores que la frase exige y pegaría la raya a la palabra anterior, que es peor. Se eligió \"em-spaced\" porque conserva la longitud correcta del signo (U+2014, no el guion U+002D que el autor escribió) y los espacios exteriores, y solo falla en los interiores. Mientras el esquema no pueda expresar la asimetría, este valor sigue siendo una aproximación y no indica que el DPD prescriba espacios interiores. Hasta spec 1.16.0 el valor era \"none\" (la regla no tocaba nada). Consultado el 18.09.2026."
70
+ "note": "parenthetical = \"em-paired\": la raya en U+2014 escrita como par, con un espacio ORDINARIO fuera del par y ninguno en los bordes interiores («Llegó —por fin— a casa»), que es lo que prescribe la fuente. La regla solo convierte una frase que contiene exactamente dos rayas candidatas; un guion suelto («Madrid - la capital») o una frase con más de dos rayas se deja como está, porque el DPD no describe el uso de la raya en esas posiciones y nada permite decidir cuál abre y cuál cierra. Las rayas de diálogo («—Hola —dijo—.») no se tocan. Hasta spec 1.17.5 el valor era \"em-spaced\", una aproximación que dejaba dos espacios interiores que el DPD no admite; hasta spec 1.16.0 era \"none\". Consultado el 18.09.2026."
71
71
  },
72
72
  {
73
73
  "rule": "ranges",
@@ -1,5 +1,5 @@
1
1
  {
2
- "spec": "1.17.5",
2
+ "spec": "1.19.0",
3
3
  "$comment": "Locale resolution input. Algorithm is specified in spec/rules/locale-resolution.md and is identical in every runtime — never delegate it to a platform locale-negotiation library. \"spec\" here must track spec/VERSION exactly — it is not itself the global version source; scripts/validate-spec.mjs enforces the match.",
4
4
  "locales": [
5
5
  "en-US",
@@ -4,7 +4,7 @@
4
4
  **Spec version:** 0.6.0 (0.2.0 for everything except the 0.5.0/0.6.0 changes noted inline and in
5
5
  §8 History), amended in **1.3.0**: §1 and §3.4's statement of what belongs to `ranges`, §3.2a's
6
6
  re-entry condition, and §3.2 steps 7 and 8, all for [ranges.md](ranges.md) §3.2a's closed-up
7
- symbols.
7
+ symbols, and again in **1.18.0**: the value `"em-paired"` and its own algorithm, §3.4a; `el` adopts it in **1.19.0** (§6).
8
8
 
9
9
  ---
10
10
 
@@ -39,14 +39,17 @@ in every prior spec version, since the two branches were always mutually exclusi
39
39
  0.5.0 split makes that exclusivity a boundary between two rules instead of two branches of one.
40
40
 
41
41
  The parenthetical form is governed by one enum in the locale file: a dash _length_ (`em` or `en`)
42
- and a _spacing_ (`tight` or `spaced`), or the opt-out value `none`.
42
+ and a _spacing_ (`tight` or `spaced`), the opt-out value `none`, or — since spec 1.18.0 — the one
43
+ value that is neither symmetric nor decided token by token, `em-paired` (§3.4a).
43
44
 
44
45
  ---
45
46
 
46
47
  ## 2. Locale data consumed
47
48
 
48
- - `dash.parenthetical` — one of `"em-tight"`, `"em-spaced"`, `"en-tight"`, `"en-spaced"`,
49
- `"none"`.
49
+ - `dash.parenthetical` — one of `"em-tight"`, `"em-spaced"`, `"em-paired"`, `"en-tight"`,
50
+ `"en-spaced"`, `"none"`. `"em-paired"` (spec 1.18.0) writes the pair as an em dash with a space
51
+ **outside** the pair and none inside it (`a —b— c`); it is specified in §3.4a, because it is the
52
+ one value whose result depends on which stroke opens the pair and which closes it.
50
53
 
51
54
  **As of spec 0.5.0, `dashes` no longer reads `dash.range`** — that field is now read exclusively
52
55
  by `ranges` ([ranges.md](ranges.md) §2), under the same key, with the same values and the same
@@ -164,7 +167,9 @@ U+2011 they meant it.
164
167
  then "counts on the left only") each fixed the witness in front of them and left the next
165
168
  one reachable; §8.2 defect (d) records how.
166
169
 
167
- 4. **Symmetry guard.** If `lsp ≠ rsp`, emit nothing and continue. A stroke that is spaced on
170
+ 4. **Symmetry guard.** If `lsp ≠ rsp`, emit nothing and continue. (`"em-paired"` is the one
171
+ exception: §3.4a counts such a stroke and, when it is a single U+2014, reads it as half of a
172
+ pair.) A stroke that is spaced on
168
173
  one side and tight on the other is not a dash: it is `--force`, `-5 °C`, a Markdown bullet
169
174
  `- item`, a signature `-- Iurii`, or an arrow `->`. This single guard removes the large
170
175
  majority of false positives and it applies to both the range and the parenthetical
@@ -500,6 +505,7 @@ Emit one edit replacing `cp[s - lsp … e - 1 + rsp]` with:
500
505
  | -------------------- | ------------------------------------------------------- |
501
506
  | `"em-tight"` | U+2014 |
502
507
  | `"em-spaced"` | U+0020 U+2014 U+0020 |
508
+ | `"em-paired"` | _(not a per-token replacement — see §3.4a)_ |
503
509
  | `"en-tight"` | U+2013 |
504
510
  | `"en-spaced"` | U+0020 U+2013 U+0020 |
505
511
  | `"none"` | _(emit nothing — the token is left exactly as written)_ |
@@ -507,6 +513,55 @@ Emit one edit replacing `cp[s - lsp … e - 1 + rsp]` with:
507
513
  **Subject to guards T1 and T2 (§3.2 steps 8 and 9), evaluated now that the form is known.** If the replacement is identical to the span it replaces, emit
508
514
  nothing.
509
515
 
516
+ ### 3.4a `"em-paired"` — the pair as a unit (spec 1.18.0)
517
+
518
+ When `dash.parenthetical` is `"em-paired"`, §3.4 is replaced by this section and the token loop
519
+ of §3.2 is replaced by a loop over **segments**. Everything else a stroke must satisfy — steps 2,
520
+ 5, 6 and 7 of §3.2, §3.2a, P1, P4 and P5 — still applies, because those guards decide whether a
521
+ stroke is a dash at all.
522
+
523
+ **Segment.** A segment is a stretch of the text unit bounded by the unit's start and end and by
524
+ a *terminal*: U+002E, U+003F, U+0021 or U+2026 that is followed by U+0020, a `NOBREAK-SPACE`, a
525
+ `BREAK`, a marker, or the end of the unit. A `NOBREAK-SPACE` counts because `nbsp` (order 70) puts
526
+ one after a terminal (`Sr. Pérez`, `p. ej.`); if only U+0020 closed a segment, that edit would
527
+ move the boundary and a second pass would pair strokes the first had kept apart. A terminal followed by anything else (`3.5`, `—¿quién?—`) does not end a
528
+ segment. A `BREAK` is **not** a segment boundary.
529
+
530
+ **Counted strokes.** Every maximal `DASH` run of §3.2 step 1 in a segment is classified:
531
+
532
+ - *Not a stroke*, and not counted: a run with `k > 3`; a range candidate (§3.3, ranges.md §3.2),
533
+ decided by its flanks alone, **whether or not the run is symmetric** (`5 -10` is a candidate);
534
+ a single hyphen-shaped run (U+002D, U+2010, U+2212) with `lsp = rsp = 0`, which is a compound;
535
+ and the U+002D of the literal sequence `+/-`, which `symbols` (order 80) turns into `±`.
536
+ - *Counted and eligible:* every other run that passes steps 5, 6 and 7, §3.2a, P4 and P5 and is
537
+ either symmetric (`lsp = rsp`) or a **single U+2014** spaced on one side only.
538
+ - *Counted and ineligible:* every other run — including a stroke at the start or end of a line
539
+ (the dialogue dash), one next to a `NOBREAK-SPACE`, `-mente`, `pre-`, `--force`, a Markdown
540
+ bullet and a lone U+2013.
541
+
542
+ **Decision.** A segment is converted if and only if **all** of the following hold; otherwise the
543
+ whole segment is left exactly as typed:
544
+
545
+ 1. it has **exactly two** counted strokes, and both are eligible;
546
+ 2. no `BREAK` lies between them;
547
+ 3. the first is not shaped like a closer (`lsp = 0`, `rsp = 1`) and the second is not shaped like
548
+ an opener (`lsp = 1`, `rsp = 0`);
549
+ 4. T1 (§3.2 step 8) does not block a side on which a space is inserted (step 5 below).
550
+
551
+ **Emission.** For the first stroke (the opener) and the second (the closer), the glyph is U+2014
552
+ and the **inner** side — to the right of the opener, to the left of the closer — is made tight,
553
+ removing a U+0020 if there was one. The **outer** side keeps a U+0020 if it had one; if it had
554
+ none, a U+0020 is inserted when the neighbouring code point `cp[L]` (opener) or `cp[R]` (closer)
555
+ is in `LETTER` or `DIGIT`, and otherwise the side stays tight, so `(—`, `«—`, `—»` and
556
+ `—por fin—.` are produced without a space the `spaces` rule would remove. T2 (§3.2 step 9) is
557
+ therefore vacuous: a space is only ever inserted beside a letter or a digit. A replacement
558
+ identical to the span it replaces is not emitted.
559
+
560
+ **What is left alone, by construction.** A lone stroke (`Madrid - la capital`); three or more
561
+ strokes in a segment; a pair split by a terminal (`p. ej.`) or by a line break; the dialogue dash
562
+ and any segment holding it (`—Hola —dijo—.`); affix hyphens; a pair whose strokes are separated by
563
+ a `NOBREAK-SPACE`. These are the accepted cost of not guessing which stroke opens which (§7.8).
564
+
510
565
  ### 3.5 Continue, and the non-overlap guarantee
511
566
 
512
567
  Set `i` to the index just past the token's run in the **input** array and continue from §3.2
@@ -689,6 +744,33 @@ Every input to a declined token's verdict is therefore unaffected by any edit `T
689
744
  pass: `T(T(x))` declines exactly where `T(x)` declined. The historical counterexamples that led to
690
745
  this guard set — before it closed every gap — are summarised in §8.2.
691
746
 
747
+ ### 5.2a `"em-paired"` — the segment verdict is stable (spec 1.18.0)
748
+
749
+ Under `"em-paired"` the verdict is made per segment (§3.4a), not per token, so §5.1's table does
750
+ not apply and the argument is rebuilt on the three facts a segment verdict reads.
751
+
752
+ - **Fixed points.** The output form has two U+2014 strokes, each spaced on its outer side only (or
753
+ tight beside a non-letter), which is eligible and correctly shaped, and the replacement of each
754
+ is byte-identical to its span: nothing is emitted.
755
+ - **The segment boundaries do not move.** Edits touch only a dash run and the U+0020 beside it.
756
+ A U+0020 is inserted only after a letter, a digit or a dash, never after a terminal, and the
757
+ first stroke after a terminal is an opener whose outer U+0020 is kept, so a terminal followed by
758
+ a space stays followed by one. No edit creates or removes a terminal.
759
+ - **The counted set does not change in the dangerous direction.** A converted segment can become
760
+ declined on the next pass (`a - 5 - b` gives `a —5— b`, whose two strokes then share a
761
+ cluster with the digit, §3.2 step 7), and that is harmless: a declined segment emits nothing, so
762
+ the text is already a fixed point. What would break idempotency is "declined → converted" on a
763
+ later pass, which needs a counted stroke to disappear, or the segment to change. A stroke that
764
+ was declined stays declined for the reasons of §5.2.
765
+ - **Composition obligation on later rules.** Every rule after `dashes` must leave the count of
766
+ counted strokes in a segment alone. `hyphen` (order 35) emits only `INERT-DASH`, which is not a
767
+ `DASH`; `symbols` rewrites `+/-` into `±`, which is why that hyphen is *not a stroke* above;
768
+ `nbsp` changes only U+0020 into `NOBREAK-SPACE`, which can make a stroke ineligible but moves
769
+ no segment boundary, because a terminal closes a segment before either.
770
+
771
+ The one direction that would break idempotency is "declined → converted" on the second pass. It
772
+ needs a counted stroke to disappear or a segment boundary to move; neither can happen.
773
+
692
774
  ### 5.3 Interaction with `ranges` is stable
693
775
 
694
776
  `ranges` (order 25) runs before `dashes` (order 30) in every pass. Three guarantees hold between
@@ -898,49 +980,28 @@ never reaches a digit-flanked token at all.
898
980
  | 46 | `de-DE` | `1–1␣-␣1` | ⟶ | digit-flanked — never reaches `dashes`; see [ranges.md](ranges.md) §6 row 46 (the control for row 45) |
899
981
  | 47 | `ru` | `1-1␣-␣1` | ⟶ | digit-flanked — never reaches `dashes`; see [ranges.md](ranges.md) §6 row 47 |
900
982
 
901
- ### `el` — `parenthetical: "none"` (`range` is now [ranges.md](ranges.md)'s field, also `"none"`, not this rule's)
902
-
903
- The first locale with `"none"` on **both** fields, so the rule is a **total no-op** for it in the
904
- same provable sense `hyphen` is a no-op for a locale with empty lists. It is no longer the only
905
- one: `tr` (spec 1.6.0) is both-`none` too, and `es` was from spec 1.3.0 until 1.17.1, each for its
906
- own reason and each recorded in its own locale file. (`es` now sets `parenthetical` to `"em-spaced"`
907
- as a known approximation — see its locale file — and keeps `range` at `"none"`.) This section stays written about `el` because its two fields are
908
- `"none"` for two *different* reasons, which is what makes it worth reading. Tokens are still
909
- classified — §3.3's "a range token is never reconsidered as a parenthetical" still holds — but no
910
- classification has an emission to make. The rows below are therefore all "no change" rows by
911
- construction, and they are worth pinning precisely because nothing else in the suite exercises
912
- the both-`none` combination.
913
-
914
- **The two fields are `"none"` for two different reasons, and collapsing them into one sentence
915
- misrepresents the source.** An earlier revision of this section said the Greek source "is not
916
- silent here, it is _ambivalent_". That is true of `range` and **false of `parenthetical`**, where
917
- the guide is explicit.
918
-
919
- - **`range: "none"` — genuine ambivalence.** The rule appears **twice** in §10.1.8 of the EU
920
- Interinstitutional Style Guide (Greek edition), once under «Ενωτικό (-)» and once under «Παύλα
921
- μεσαίου μεγέθους (–)», and **each occurrence explicitly concedes the other mark**. A source
922
- that names both forms in both places is not being vague; it is declining to rank them.
923
- Emitting either would express a preference the citation does not carry, so the rule emits
924
- nothing.
925
- - **`parenthetical: "none"` — a schema limit, not ambivalence.** The guide prescribes a U+2014
926
- pair (its own header gives «Alt 0151») and states the spacing exactly: «Όπως η παρένθεση, η
927
- διπλή παύλα δεν χωρίζεται με κενά διαστήματα από τη λέξη, φράση ή πρόταση που περικλείει·
928
- αντίθετα, μπαίνουν διαστήματα πριν από την πρώτη και μετά τη δεύτερη παύλα.» — ordinary spaces
929
- **outside** the pair, none on the **inner** edges. `dash.parenthetical`'s enum has no value for
930
- that asymmetry: `"em-spaced"` puts a space on each side of _each_ dash, which is precisely what
931
- the sentence forbids, and `"em-tight"` drops the outer spaces the sentence requires. So the
932
- source is clear and the schema cannot record it. `"none"` is what the file must say until the
933
- enum grows; the gap is with the operator and is **not** a licence to approximate.
934
-
935
- In both cases `"none"` is the honest encoding, not a placeholder awaiting a default (§2) — but
936
- only one of them is waiting on a _source_. `spec/locales/el.json`'s `dashes.note` carries the
937
- detail, including a **source conflict** this document does not try to settle: the EU guide sets
938
- U+2014 parenthetically while the state school grammar appears to set U+2013.
983
+ ### `el` — `parenthetical: "em-paired"`, `range: "none"` (`range` is now [ranges.md](ranges.md)'s field)
984
+
985
+ `el` has been `parenthetical: "em-paired"` since spec 1.19.0 (it was `"none"` before, because the
986
+ enum had no value for the asymmetric spacing until 1.18.0 and the em/en choice was unsettled). The
987
+ EU Interinstitutional Style Guide (Greek edition) §10.1.8 prescribes a U+2014 pair (its own header
988
+ gives «Alt 0151») and states the spacing exactly: «Όπως η παρένθεση, η διπλή παύλα δεν χωρίζεται με
989
+ κενά διαστήματα από τη λέξη, φράση ή πρόταση που περικλείει· αντίθετα, μπαίνουν διαστήματα πριν από
990
+ την πρώτη και μετά τη δεύτερη παύλα.» — ordinary spaces **outside** the pair, none on the **inner**
991
+ edges, which is what §3.4a writes. The state school grammar (ΥΠΕΠΘ/ΙΤΥΕ §3.3) appears to set an en
992
+ dash in the same role; that conflict is recorded in `spec/locales/el.json`'s `dashes.note` and
993
+ settled by operator decision for the cited source, not by a source that ranks the two. The
994
+ conditions and the accepted cost of §3.4a and §7 item 8 apply to `el` unchanged.
995
+
996
+ `range` stays `"none"` for a different reason: genuine ambivalence. The rule appears **twice** in
997
+ §10.1.8, once under «Ενωτικό (-)» and once under «Παύλα μεσαίου μεγέθους (–)», and **each
998
+ occurrence explicitly concedes the other mark**. Emitting either would express a preference the
999
+ citation does not carry, so `ranges` emits nothing.
939
1000
 
940
1001
  | # | Input | Output | Why |
941
1002
  | --- | -------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
942
1003
  | 48 | `άτομα ηλικίας 25-45 ετών` | ⟶ | digit-flanked — never reaches `dashes` (§1, §3.3); see [ranges.md](ranges.md) §6 row 48 for `ranges`' own no-op here (`range: "none"` — nothing to emit even when explicitly enabled) |
943
- | 49 | `Το σχέδιο␣-␣αν υπάρχει␣-␣αποτυγχάνει` | ⟶ | classified as a parenthetical, `parenthetical: "none"` → nothing emitted |
1004
+ | 49 | `Το σχέδιο␣-␣αν υπάρχει␣-␣αποτυγχάνει` | `Το σχέδιο␣—αν υπάρχει—␣αποτυγχάνει` | two strokes in one segment, `parenthetical: "em-paired"` → §3.4a |
944
1005
  | 50 | `την περίοδο 1989–1991` | ⟶ | digit-flanked — never reaches `dashes` (§1, §3.3); already an en dash in the form the source prints, so [ranges.md](ranges.md) is inert here too even when explicitly enabled |
945
1006
 
946
1007
  ### A locale with no verified convention — `parenthetical: "none"` (`range` is now [ranges.md](ranges.md)'s field, also `"none"`, not this rule's)
@@ -1038,6 +1099,16 @@ development, the compound-label widening's original acceptance) moved to §8.
1038
1099
  exists, a port could transcribe either set and stay green. (T2 is shared with `ranges`, §3.3
1039
1100
  there — the same gap applies to a `-spaced` range replacement before U+2026.)
1040
1101
 
1102
+ 8. **`"em-paired"` converts only a segment with exactly two strokes (spec 1.18.0).** The rule has
1103
+ no syntax to read, so which stroke opens and which closes can only be inferred from there being
1104
+ two. The price, measured on fixtures and not yet on a corpus, is that these stay as typed:
1105
+ a lone spaced hyphen (`Madrid - la capital`), a sentence with two incisos (four strokes), an
1106
+ inciso holding an abbreviation or a `?`/`!` followed by a space, an inciso split by a line break,
1107
+ and any sentence that also holds a dialogue dash. The converse risk is a list written with
1108
+ spaced hyphens: `Madrid - Barcelona - Sevilla` becomes `Madrid —Barcelona— Sevilla`. The DPD
1109
+ names neither case, so both are recorded here and pinned by fixtures in `fixtures/es.json`
1110
+ rather than decided by a heuristic.
1111
+
1041
1112
  ---
1042
1113
 
1043
1114
  ## 8. History
@@ -2170,7 +2170,6 @@ each, the rule is given fewer chances to fire and the text is left as typed.
2170
2170
  | `en-US` | `em-tight` | **converts** — `a<em>—</em>b`, since 2 → 1 is a contraction | converts |
2171
2171
  | `de-CH`, `de-DE`, `en-GB`, `fi`, `sv` | `en-spaced` | unchanged — 2 → 3 grows both edges | converts, `a<em>x – y</em>b` |
2172
2172
  | `fr`, `ru` | `em-spaced` | unchanged — same reason | converts |
2173
- | `el` | `none` | unchanged — emits nothing anywhere | unchanged |
2174
2173
 
2175
2174
  `en-US` is the only locale whose parenthetical form is shorter than the `--` that triggers it,
2176
2175
  and it is therefore the only one that converts at an edge. The asymmetry is real — the same
@@ -1,5 +1,5 @@
1
1
  {
2
- "spec": "1.17.5",
2
+ "spec": "1.19.0",
3
3
  "$comment": "Single source of truth for pipeline order. Rules run in ascending `order`. Disabling a rule removes it from the sequence and never reorders the rest. Rule ids are public API (see docs/ARCHITECTURE.md section 5). \"spec\" here must track spec/VERSION exactly — it is not itself the global version source; scripts/validate-spec.mjs enforces the match.",
4
4
  "rules": [
5
5
  {
@@ -32,7 +32,7 @@
32
32
  "default": "on",
33
33
  "modes": ["text", "html", "markdown", "yaml"],
34
34
  "localeData": ["dash"],
35
- "summary": "Parenthetical dash per locale convention (dash.parenthetical). Never reinterprets a range candidate as a parenthetical dash — that shape belongs to `ranges` alone, whether or not `ranges` is enabled (spec 0.5.0; range detection moved out of this rule). A candidate is digit-flanked, or flanked by a closed-up symbol matched on the opposite member (spec 1.3.0; ranges.md §3.2a)."
35
+ "summary": "Parenthetical dash per locale convention (dash.parenthetical). Never reinterprets a range candidate as a parenthetical dash — that shape belongs to `ranges` alone, whether or not `ranges` is enabled (spec 0.5.0; range detection moved out of this rule). A candidate is digit-flanked, or flanked by a closed-up symbol matched on the opposite member (spec 1.3.0; ranges.md §3.2a). The value `em-paired` (spec 1.18.0) is decided per sentence rather than per token: it converts a sentence holding exactly two eligible strokes (dashes.md §3.4a)."
36
36
  },
37
37
  {
38
38
  "id": "hyphen",
@@ -190,6 +190,13 @@ or G3.
190
190
  violates `I₃` when it changes the **spacing** around a U+002D/U+2013/U+2014, because spacing
191
191
  is what `dashes` reads to decide whether a stroke is a parenthetical dash at all.
192
192
 
193
+ Under `dash.parenthetical = "em-paired"` (spec 1.18.0) the verdict is no longer local to a token:
194
+ `dashes` decides per segment, from the count and eligibility of the strokes in it (`dashes.md`
195
+ §3.4a, §5.2a). A later rule violates `I₃` there only by changing the count of counted strokes
196
+ or moving a segment boundary. `nbsp` changes U+0020 into a `NOBREAK-SPACE`, which dashes.md §3.4a
197
+ treats as closing a segment exactly as U+0020 does; `symbols` consumes the hyphen of `+/-`, which
198
+ §3.4a already excludes; `hyphen` emits only an `INERT-DASH`.
199
+
193
200
  **Who can violate it.** Nobody, since spec 0.1.0 — and it is worth recording that this line
194
201
  previously read _"`nbsp`, which inserts and converts space-like code points"_, which was true
195
202
  and was the source of two defects. `dashes` now treats both U+00A0 and U+202F as making an
@@ -38,8 +38,8 @@
38
38
  "required": ["parenthetical", "range"],
39
39
  "properties": {
40
40
  "parenthetical": {
41
- "enum": ["em-tight", "em-spaced", "en-tight", "en-spaced", "none"],
42
- "description": "Dash used for a parenthetical break. `-tight` means no surrounding spaces, `-spaced` means a regular space on each side (the leading one may later be made non-breaking by the nbsp rule). `none` means the rule must not substitute anything: either the locale has no verified convention, or the cited sources attest more than one form and rank none."
41
+ "enum": ["em-tight", "em-spaced", "em-paired", "en-tight", "en-spaced", "none"],
42
+ "description": "Dash used for a parenthetical break. `-tight` means no surrounding spaces, `-spaced` means a regular space on each side (the leading one may later be made non-breaking by the nbsp rule). `em-paired` is the em dash written as a pair, with a space outside the pair and none inside it (`a —b— c`). `none` means the rule must not substitute anything: either the locale has no verified convention, or the cited sources attest more than one form and rank none."
43
43
  },
44
44
  "range": {
45
45
  "enum": ["em-tight", "em-spaced", "en-tight", "en-spaced", "none"],
@@ -131,7 +131,7 @@ module Polytypo
131
131
 
132
132
  # The target dash glyph for a style value.
133
133
  def dash_code_point(style)
134
- style == "em-tight" || style == "em-spaced" ? EM_DASH : EN_DASH
134
+ style == "em-tight" || style == "em-spaced" || style == "em-paired" ? EM_DASH : EN_DASH
135
135
  end
136
136
 
137
137
  # Whether cp[start...end] is exactly `next`, code point for code point.
@@ -285,36 +285,47 @@ module Polytypo
285
285
  # `dashes` token becoming spaced can insert a space next to a `ranges` token's digit run,
286
286
  # and vice versa.
287
287
  def spacing_transition_blocked?(cp, left, right)
288
+ spacing_transition_blocked_left?(cp, left) || spacing_transition_blocked_right?(cp, right)
289
+ end
290
+
291
+ # The left half of T1, for a form that inserts a space on one side only (`em-paired`).
292
+ def spacing_transition_blocked_left?(cp, left)
288
293
  n = cp.length
289
294
 
290
295
  # Spec 1.3.0, position p1: step over a CLOSED-SYMBOL between the token and the run.
291
296
  left -= 1 if left >= 0 && left < n && closed_up_symbol?(cp[left]) && left.positive? &&
292
297
  digit?(cp[left - 1])
298
+
299
+ return false unless left >= 0 && left < n && digit?(cp[left])
300
+
301
+ d = left
302
+ d -= 1 while d.positive? && digit?(cp[d - 1])
303
+ # Position p2: and over one at the far end of the run.
304
+ i1 = effective_index(cp, skip_closed_up_symbol(cp, d - 1, -1), -1)
305
+ one = i1.nil? ? Polytypo::Engine::NONE : cp[i1]
306
+ two = i1.nil? ? Polytypo::Engine::NONE : effective_neighbour(cp, i1 - 1, -1)
307
+ return true if dash_union?(one)
308
+
309
+ (one == SPACE || no_break_space?(one)) && dash_union?(two)
310
+ end
311
+
312
+ # The right half of T1; see spacing_transition_blocked_left?.
313
+ def spacing_transition_blocked_right?(cp, right)
314
+ n = cp.length
315
+
293
316
  right += 1 if right >= 0 && right < n && closed_up_symbol?(cp[right]) &&
294
317
  right + 1 < n && digit?(cp[right + 1])
295
318
 
296
- if left >= 0 && left < n && digit?(cp[left])
297
- d = left
298
- d -= 1 while d.positive? && digit?(cp[d - 1])
299
- # Position p2: and over one at the far end of the run.
300
- i1 = effective_index(cp, skip_closed_up_symbol(cp, d - 1, -1), -1)
301
- one = i1.nil? ? Polytypo::Engine::NONE : cp[i1]
302
- two = i1.nil? ? Polytypo::Engine::NONE : effective_neighbour(cp, i1 - 1, -1)
303
- return true if dash_union?(one)
304
- return true if (one == SPACE || no_break_space?(one)) && dash_union?(two)
305
- end
319
+ return false unless right >= 0 && right < n && digit?(cp[right])
306
320
 
307
- if right >= 0 && right < n && digit?(cp[right])
308
- d = right
309
- d += 1 while d + 1 < n && digit?(cp[d + 1])
310
- i1 = effective_index(cp, skip_closed_up_symbol(cp, d + 1, 1), 1)
311
- one = i1.nil? ? Polytypo::Engine::NONE : cp[i1]
312
- two = i1.nil? ? Polytypo::Engine::NONE : effective_neighbour(cp, i1 + 1, 1)
313
- return true if dash_union?(one)
314
- return true if (one == SPACE || no_break_space?(one)) && dash_union?(two)
315
- end
321
+ d = right
322
+ d += 1 while d + 1 < n && digit?(cp[d + 1])
323
+ i1 = effective_index(cp, skip_closed_up_symbol(cp, d + 1, 1), 1)
324
+ one = i1.nil? ? Polytypo::Engine::NONE : cp[i1]
325
+ two = i1.nil? ? Polytypo::Engine::NONE : effective_neighbour(cp, i1 + 1, 1)
326
+ return true if dash_union?(one)
316
327
 
317
- false
328
+ (one == SPACE || no_break_space?(one)) && dash_union?(two)
318
329
  end
319
330
 
320
331
  # dashes.md 3.2 steps 1-7 and 3.2a, exactly as they read before the `ranges` split -- the
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "dash_shared"
4
+ require_relative "dashes_paired"
4
5
  require_relative "../edits"
5
6
  require_relative "../registry"
6
7
  require_relative "../unicode_util"
@@ -66,8 +67,10 @@ module Polytypo
66
67
  end
67
68
 
68
69
  def scan(cp, locale_data, _ctx)
69
- edits = []
70
70
  style = locale_data["dash"]["parenthetical"]
71
+ return DashesPaired.scan(cp) if style == "em-paired"
72
+
73
+ edits = []
71
74
 
72
75
  DashShared.find_tokens(cp).each do |token|
73
76
  # A digit-flanked token is `ranges`' territory, never `dashes`' -- declined
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "dash_shared"
4
+ require_relative "../edits"
5
+ require_relative "../sentinels"
6
+ require_relative "../unicode_util"
7
+
8
+ module Polytypo
9
+ module Engine
10
+ module Rules
11
+ # `dash.parenthetical = "em-paired"` -- spec/rules/dashes.md 3.4a. The pair is written with a
12
+ # space outside it and none inside (`Llego —por fin— a casa`), which no per-token rule can
13
+ # express: which stroke opens and which closes is a property of the sentence, not of the
14
+ # token. A sentence is converted only when it holds exactly two counted strokes and both are
15
+ # eligible; anything else is left as typed. Mirrors dashes-paired.ts in the JS reference
16
+ # implementation.
17
+ module DashesPaired
18
+ # One counted DASH run of a segment: its span [s, e), outer spacing, the flanking indices
19
+ # after the joiner walk, and whether it may take part in a conversion.
20
+ Run = Struct.new(:s, :e, :lsp, :rsp, :left, :right, :eligible, keyword_init: true)
21
+
22
+ TERMINALS = [0x2e, 0x3f, 0x21, 0x2026].freeze
23
+
24
+ module_function
25
+
26
+ def terminal?(cp)
27
+ TERMINALS.include?(cp)
28
+ end
29
+
30
+ # A terminal ends a segment only before a space (U+0020 or a no-break space, which `nbsp`
31
+ # puts there later), a line break, a marker or the end of input.
32
+ def ends_segment?(cp, i)
33
+ return false unless terminal?(cp[i])
34
+ return true if i + 1 >= cp.length
35
+
36
+ nxt = cp[i + 1]
37
+ nxt == DashShared::SPACE || DashShared.no_break_space?(nxt) || DashShared.break?(nxt) ||
38
+ Polytypo::Engine.marker?(nxt)
39
+ end
40
+
41
+ def wants_space?(cp)
42
+ Polytypo::Engine::UnicodeUtil.letter?(cp) || DashShared.digit?(cp)
43
+ end
44
+
45
+ # dashes.md 3.2 steps 5-7: content on the same line, no dash or space beside the stroke's
46
+ # outer spacing, and not part of a cluster holding another dash run.
47
+ def neighbours_clean?(cp, s, e, left, right)
48
+ left_cp = cp[left]
49
+ right_cp = cp[right]
50
+ return false if DashShared.break?(left_cp) || DashShared.break?(right_cp)
51
+ return false if DashShared.inert_dash?(left_cp) || DashShared.inert_dash?(right_cp)
52
+ return false if DashShared.dash?(left_cp) || DashShared.dash?(right_cp)
53
+ return false if left_cp == DashShared::SPACE || DashShared.no_break_space?(left_cp)
54
+ return false if right_cp == DashShared::SPACE || DashShared.no_break_space?(right_cp)
55
+
56
+ !DashShared.cluster_inert?(cp, s, e)
57
+ end
58
+
59
+ # Returns nil when the run is not a stroke at all, otherwise a Run (eligible or not).
60
+ def classify(cp, s, e)
61
+ n = cp.length
62
+ k = e - s
63
+ return nil if k > 3
64
+
65
+ lsp = s.positive? && cp[s - 1] == DashShared::SPACE ? 1 : 0
66
+ rsp = e < n && cp[e] == DashShared::SPACE ? 1 : 0
67
+ first = cp[s]
68
+ is_hyphen_shaped = first == DashShared::HYPHEN_MINUS || first == DashShared::HYPHEN ||
69
+ first == DashShared::MINUS_SIGN
70
+ # A hyphen inside a word is a compound, not a stroke.
71
+ return nil if k == 1 && is_hyphen_shaped && lsp.zero? && rsp.zero?
72
+ # The hyphen of `+/-`, which `symbols` (order 80) turns into a plus-minus sign: counting
73
+ # it would let that later rule change the number of strokes in the segment.
74
+ return nil if k == 1 && first == DashShared::HYPHEN_MINUS && s >= 2 && cp[s - 1] == 0x2f && cp[s - 2] == 0x2b
75
+
76
+ left = s - 1 - lsp
77
+ right = e + rsp
78
+ counted = lambda do |eligible|
79
+ Run.new(s: s, e: e, lsp: lsp, rsp: rsp, left: left, right: right, eligible: eligible)
80
+ end
81
+ return counted.call(false) if left.negative? || right >= n
82
+
83
+ join_start = left + 1
84
+ join_end = right
85
+ left -= 1 while left >= 0 && cp[left] == DashShared::WORD_JOINER
86
+ right += 1 while right < n && cp[right] == DashShared::WORD_JOINER
87
+ return counted.call(false) if left.negative? || right >= n
88
+
89
+ crossed_joiner = left + 1 != join_start || right != join_end
90
+
91
+ return nil unless DashShared.range_flanks(cp, left, right).nil?
92
+ return counted.call(false) if crossed_joiner
93
+
94
+ return counted.call(false) unless neighbours_clean?(cp, s, e, left, right)
95
+
96
+ # A stroke spaced on one side only is eligible solely as the one em dash that is already
97
+ # half of the target form; `-mente`, `pre-`, `--force` and `- item` are not dashes.
98
+ return counted.call(false) if lsp != rsp && !(k == 1 && first == DashShared::EM_DASH)
99
+ # P4: a tight stroke between two Roman numerals is a range already in its correct form.
100
+ return counted.call(false) if lsp.zero? && rsp.zero? && Dashes.roman_flanked?(cp, left, right)
101
+ # P5: an authored lone en dash is declined in every locale.
102
+ return counted.call(false) if k == 1 && first == DashShared::EN_DASH
103
+
104
+ counted.call(true)
105
+ end
106
+
107
+ def scan(cp)
108
+ n = cp.length
109
+ edits = []
110
+ segment = []
111
+ i = 0
112
+
113
+ while i < n
114
+ if DashShared.dash?(cp[i])
115
+ s = i
116
+ e = s
117
+ e += 1 while e < n && DashShared.dash?(cp[e])
118
+ i = e
119
+ run = classify(cp, s, e)
120
+ segment << run unless run.nil?
121
+ next
122
+ end
123
+
124
+ if ends_segment?(cp, i)
125
+ emit_pair(cp, segment[0], segment[1], edits) if segment.length == 2
126
+ segment = []
127
+ end
128
+ i += 1
129
+ end
130
+ emit_pair(cp, segment[0], segment[1], edits) if segment.length == 2
131
+
132
+ edits
133
+ end
134
+
135
+ def emit_pair(cp, a, b, edits)
136
+ return unless a.eligible && b.eligible
137
+ return if a.lsp.zero? && a.rsp == 1 # the first stroke is shaped like a closer
138
+ return if b.lsp == 1 && b.rsp.zero? # the second stroke is shaped like an opener
139
+ return if (a.e...b.s).any? { |j| DashShared.break?(cp[j]) }
140
+
141
+ insert_before = a.lsp.zero? && wants_space?(cp[a.left])
142
+ insert_after = b.rsp.zero? && wants_space?(cp[b.right])
143
+ return if insert_before && DashShared.spacing_transition_blocked_left?(cp, a.left)
144
+ return if insert_after && DashShared.spacing_transition_blocked_right?(cp, b.right)
145
+
146
+ opener = a.lsp == 1 || insert_before ? [DashShared::SPACE, DashShared::EM_DASH] : [DashShared::EM_DASH]
147
+ closer = b.rsp == 1 || insert_after ? [DashShared::EM_DASH, DashShared::SPACE] : [DashShared::EM_DASH]
148
+
149
+ [[a, opener], [b, closer]].each do |run, replacement|
150
+ span_start = run.s - run.lsp
151
+ span_end = run.e + run.rsp
152
+ next if DashShared.same_content?(cp, span_start, span_end, replacement)
153
+
154
+ edits << Polytypo::Engine::Edit.new(span_start, span_end, replacement, "dashes")
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polytypo
4
- VERSION = "1.17.5"
4
+ VERSION = "1.19.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polytypo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.5
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iurii Rogulia
@@ -125,6 +125,7 @@ files:
125
125
  - lib/polytypo/engine/rules/apostrophe.rb
126
126
  - lib/polytypo/engine/rules/dash_shared.rb
127
127
  - lib/polytypo/engine/rules/dashes.rb
128
+ - lib/polytypo/engine/rules/dashes_paired.rb
128
129
  - lib/polytypo/engine/rules/ellipsis.rb
129
130
  - lib/polytypo/engine/rules/hyphen.rb
130
131
  - lib/polytypo/engine/rules/nbsp.rb