polytypo 1.20.0 → 1.21.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/polytypo/data/VERSION +1 -1
  3. data/lib/polytypo/data/fixtures/bg.json +12 -1
  4. data/lib/polytypo/data/fixtures/cs.json +12 -1
  5. data/lib/polytypo/data/fixtures/de-CH.json +12 -1
  6. data/lib/polytypo/data/fixtures/de-DE.json +12 -1
  7. data/lib/polytypo/data/fixtures/el.json +12 -1
  8. data/lib/polytypo/data/fixtures/en-GB.json +12 -1
  9. data/lib/polytypo/data/fixtures/en-US.json +403 -1
  10. data/lib/polytypo/data/fixtures/es.json +12 -1
  11. data/lib/polytypo/data/fixtures/fi.json +12 -1
  12. data/lib/polytypo/data/fixtures/fr-CA.json +12 -1
  13. data/lib/polytypo/data/fixtures/fr.json +12 -1
  14. data/lib/polytypo/data/fixtures/hr.json +12 -1
  15. data/lib/polytypo/data/fixtures/hu.json +12 -1
  16. data/lib/polytypo/data/fixtures/it.json +12 -1
  17. data/lib/polytypo/data/fixtures/locale-resolution.json +1 -1
  18. data/lib/polytypo/data/fixtures/lt.json +12 -1
  19. data/lib/polytypo/data/fixtures/nl.json +12 -1
  20. data/lib/polytypo/data/fixtures/pl.json +12 -1
  21. data/lib/polytypo/data/fixtures/pt-BR.json +12 -1
  22. data/lib/polytypo/data/fixtures/pt-PT.json +12 -1
  23. data/lib/polytypo/data/fixtures/ro.json +12 -1
  24. data/lib/polytypo/data/fixtures/ru.json +12 -1
  25. data/lib/polytypo/data/fixtures/sk.json +12 -1
  26. data/lib/polytypo/data/fixtures/sl.json +12 -1
  27. data/lib/polytypo/data/fixtures/sr.json +12 -1
  28. data/lib/polytypo/data/fixtures/sv.json +12 -1
  29. data/lib/polytypo/data/fixtures/tr.json +12 -1
  30. data/lib/polytypo/data/fixtures/uk.json +12 -1
  31. data/lib/polytypo/data/locales/bg.json +1 -0
  32. data/lib/polytypo/data/locales/cs.json +1 -0
  33. data/lib/polytypo/data/locales/de-CH.json +6 -0
  34. data/lib/polytypo/data/locales/de-DE.json +7 -0
  35. data/lib/polytypo/data/locales/el.json +1 -0
  36. data/lib/polytypo/data/locales/en-GB.json +7 -0
  37. data/lib/polytypo/data/locales/en-US.json +7 -0
  38. data/lib/polytypo/data/locales/es.json +1 -0
  39. data/lib/polytypo/data/locales/fi.json +1 -0
  40. data/lib/polytypo/data/locales/fr-CA.json +1 -0
  41. data/lib/polytypo/data/locales/fr.json +1 -0
  42. data/lib/polytypo/data/locales/hr.json +1 -0
  43. data/lib/polytypo/data/locales/hu.json +1 -0
  44. data/lib/polytypo/data/locales/it.json +1 -0
  45. data/lib/polytypo/data/locales/lt.json +1 -0
  46. data/lib/polytypo/data/locales/nl.json +1 -0
  47. data/lib/polytypo/data/locales/pl.json +1 -0
  48. data/lib/polytypo/data/locales/pt-BR.json +1 -0
  49. data/lib/polytypo/data/locales/pt-PT.json +1 -0
  50. data/lib/polytypo/data/locales/registry.json +1 -1
  51. data/lib/polytypo/data/locales/ro.json +1 -0
  52. data/lib/polytypo/data/locales/ru.json +1 -0
  53. data/lib/polytypo/data/locales/sk.json +1 -0
  54. data/lib/polytypo/data/locales/sl.json +1 -0
  55. data/lib/polytypo/data/locales/sr.json +2 -1
  56. data/lib/polytypo/data/locales/sv.json +1 -0
  57. data/lib/polytypo/data/locales/tr.json +1 -0
  58. data/lib/polytypo/data/locales/uk.json +1 -0
  59. data/lib/polytypo/data/rules/order.json +9 -1
  60. data/lib/polytypo/data/rules/pipeline-idempotency.md +23 -3
  61. data/lib/polytypo/data/rules/quote-punctuation.md +334 -0
  62. data/lib/polytypo/data/rules/quotes.md +9 -0
  63. data/lib/polytypo/data/schema/fixtures.schema.json +1 -0
  64. data/lib/polytypo/data/schema/locale.schema.json +12 -1
  65. data/lib/polytypo/engine/locale.rb +22 -1
  66. data/lib/polytypo/engine/pipeline.rb +1 -1
  67. data/lib/polytypo/engine/rules/quote_punctuation.rb +79 -0
  68. data/lib/polytypo/engine/rules.rb +1 -0
  69. data/lib/polytypo/version.rb +1 -1
  70. metadata +3 -1
@@ -94,7 +94,7 @@ module Polytypo
94
94
  # spec data in Registry/Locale (ARCHITECTURE.md section 7).
95
95
  module Pipeline
96
96
  # Defaults + opt-out overrides. rules_option is opt-out only (ARCHITECTURE.md section 7):
97
- # it may only disable a default-on rule or enable the one default-off rule ("ranges"). An
97
+ # it may only disable a default-on rule or enable a default-off one ("ranges", "quote-punctuation"). An
98
98
  # unknown key raises POLYTYPO_UNKNOWN_RULE.
99
99
  def self.resolve_rule_plan(rules_option)
100
100
  defaults = Registry.rule_defaults
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "quote_ambiguity"
4
+ require_relative "../sentinels"
5
+ require_relative "../unicode_util"
6
+ require_relative "../edits"
7
+ require_relative "../registry"
8
+
9
+ module Polytypo
10
+ module Engine
11
+ module Rules
12
+ # `quote-punctuation` -- spec/rules/quote-punctuation.md (spec 1.21.0), order 45, off by
13
+ # default.
14
+ #
15
+ # Moves a comma or a full stop from after the locale's closing primary quotation mark to
16
+ # before it, only where `quotes.punctuationPlacement` is "inside". One left-to-right scan
17
+ # over code points; every edit swaps two adjacent code points, so the text never changes
18
+ # length and no regex or normalization is involved. The inline marker is in no class below,
19
+ # so a span boundary or protected run on any of the three sides declines the move.
20
+ module QuotePunctuation
21
+ COMMA = 0x2C
22
+ FULL_STOP = 0x2E
23
+
24
+ # SPACELIKE (quotes.md 3.1): INLINE-SPACE plus BREAK, with Engine::LINE_MARKER a member of
25
+ # BREAK for every rule (modes.md 3.2).
26
+ BREAK = [0x0A, 0x0D, 0x0B, 0x0C, 0x85, 0x2028, 0x2029, Engine::LINE_MARKER].freeze
27
+
28
+ def self.spacelike?(cp)
29
+ QuoteAmbiguity.inline_space?(cp) || BREAK.include?(cp)
30
+ end
31
+
32
+ # cp[i], or NONE if i is out of bounds -- the spec's own boundary value.
33
+ def self.at(cp, i)
34
+ return NONE if i.negative? || i >= cp.length
35
+
36
+ cp[i]
37
+ end
38
+
39
+ # quote-punctuation.md 3.2: C1-C4 for the pair at i, i + 1.
40
+ def self.edit_at?(cp, i, close)
41
+ return false unless cp[i] == close && i >= 1
42
+
43
+ next_cp = cp[i + 1]
44
+ return false unless next_cp == COMMA || next_cp == FULL_STOP
45
+ return false unless UnicodeUtil.letter?(cp[i - 1])
46
+
47
+ after = at(cp, i + 2)
48
+ after == NONE || spacelike?(after)
49
+ end
50
+ private_class_method :edit_at?
51
+
52
+ def self.scan(cp, locale_data, _ctx)
53
+ quotes = locale_data["quotes"]
54
+ return [] unless quotes["punctuationPlacement"] == "inside"
55
+
56
+ close = quotes["primary"]["close"].codepoints.first
57
+ return [] if close.nil?
58
+
59
+ edits = []
60
+ i = 0
61
+ while i + 1 < cp.length
62
+ if edit_at?(cp, i, close)
63
+ edits << Edit.new(i, i + 2, [cp[i + 1], close], "quote-punctuation")
64
+ i += 2
65
+ else
66
+ i += 1
67
+ end
68
+ end
69
+ edits
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ Polytypo::Engine::Registry.register(
77
+ "quote-punctuation",
78
+ ->(cp, locale_data, ctx) { Polytypo::Engine::Rules::QuotePunctuation.scan(cp, locale_data, ctx) },
79
+ )
@@ -14,6 +14,7 @@ require_relative "rules/ranges"
14
14
  require_relative "rules/dashes"
15
15
  require_relative "rules/hyphen"
16
16
  require_relative "rules/quotes"
17
+ require_relative "rules/quote_punctuation"
17
18
  require_relative "rules/apostrophe"
18
19
  require_relative "rules/symbols"
19
20
  require_relative "rules/nbsp"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polytypo
4
- VERSION = "1.20.0"
4
+ VERSION = "1.21.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.20.0
4
+ version: 1.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iurii Rogulia
@@ -106,6 +106,7 @@ files:
106
106
  - lib/polytypo/data/rules/nbsp.md
107
107
  - lib/polytypo/data/rules/order.json
108
108
  - lib/polytypo/data/rules/pipeline-idempotency.md
109
+ - lib/polytypo/data/rules/quote-punctuation.md
109
110
  - lib/polytypo/data/rules/quotes.md
110
111
  - lib/polytypo/data/rules/ranges.md
111
112
  - lib/polytypo/data/rules/spaces.md
@@ -130,6 +131,7 @@ files:
130
131
  - lib/polytypo/engine/rules/hyphen.rb
131
132
  - lib/polytypo/engine/rules/nbsp.rb
132
133
  - lib/polytypo/engine/rules/quote_ambiguity.rb
134
+ - lib/polytypo/engine/rules/quote_punctuation.rb
133
135
  - lib/polytypo/engine/rules/quotes.rb
134
136
  - lib/polytypo/engine/rules/ranges.rb
135
137
  - lib/polytypo/engine/rules/spaces.rb