Skip to content

Commit

Permalink
add Lowercase and Uppercase rules, rename objects to Rule and Replace…
Browse files Browse the repository at this point in the history
…ments to match documentation
  • Loading branch information
Fogapod committed Nov 15, 2023
1 parent 7314c74 commit 860b88f
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 173 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ Each rule consists of regex pattern and a replacement. When regex match occurs t

Possible replacements are:

- `Noop`: Do not replace
- `Original`: Do not replace
- `Simple`: Puts string as is
- `Any` (recursive): Selects random replacement with equal weights
- `Weights` (recursive): Selects replacement based on relative weights
- `Uppercase` (recursive): Converts inner result to uppercase
- `Lowercase` (recursive): Converts inner result to lowercase

## Serialized format

Expand Down Expand Up @@ -57,6 +59,10 @@ Full reference:
// ultra rare sigma honk - 1 / 56
(01, Simple(" HONK HONK HONK HONK!!!!!!!!!!!!!!!")),
])),
// lowercases all `p` letters (use "p" match from `Original`, then lowercase)
("p", Lowercase(Original)),
// uppercases all `p` letters, undoing previous operation
("p", Uppercase(Original)),
],
// accent can be used with severity (non negative value). higher severities can either extend
Expand Down Expand Up @@ -88,7 +94,7 @@ Full reference:
Simple("É"),
])),
// 50% to do nothing, no replacement
(1, Noop),
(1, Original),
])),
],
),
Expand Down
2 changes: 1 addition & 1 deletion benches/accents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn read_sample_file_lines() -> Vec<String> {
fn accents(c: &mut Criterion) {
let lines = read_sample_file_lines();

for replacement in ["noop", "simple", "any", "weights"] {
for replacement in ["original", "simple", "any", "weights", "uppercase", "lowercase"] {
let accent = read_accent(&format!("benches/{replacement}.ron"));

c.bench_function(&format!("accents::{replacement}"), |b| {
Expand Down
4 changes: 2 additions & 2 deletions benches/any.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

patterns: [
("a", Any([
Noop,
Original,
Simple("B"),
Simple("Flat"),
])),
("VeryLongNonExistent12344343243244234", Any([Noop])),
("VeryLongNonExistent12344343243244234", Any([Original])),
("you", Any([
Any([
Any([
Expand Down
9 changes: 9 additions & 0 deletions benches/lowercase.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(
normalize_case: true,

patterns: [
("a", Lowercase(Original)),
("VeryLongNonExistent12344343243244234", Lowercase(Original)),
("you", Lowercase(Original)),
],
)
9 changes: 0 additions & 9 deletions benches/noop.ron

This file was deleted.

9 changes: 9 additions & 0 deletions benches/original.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(
normalize_case: true,

patterns: [
("a", Original),
("VeryLongNonExistent12344343243244234", Original),
("you", Original),
],
)
9 changes: 9 additions & 0 deletions benches/uppercase.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(
normalize_case: true,

patterns: [
("a", Uppercase(Original)),
("VeryLongNonExistent12344343243244234", Uppercase(Original)),
("you", Uppercase(Original)),
],
)
2 changes: 1 addition & 1 deletion benches/weights.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

patterns: [
("a", Weights([(1, Simple("B"))])),
("VeryLongNonExistent12344343243244234", Weights([(10000, Noop)])),
("VeryLongNonExistent12344343243244234", Weights([(10000, Original)])),
("you", Weights([
(1, Weights([(1, Simple("1"))])),
(2, Weights([(1, Simple("2"))])),
Expand Down
1 change: 1 addition & 0 deletions examples/clown.ron
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)),
2: Extend((
patterns: [
(".+", Uppercase(Original)),
("$", Any([
Simple(" HONK HONK HONK!"),
Simple(" HONK HONK HONK HONK!"),
Expand Down
6 changes: 5 additions & 1 deletion examples/example.ron
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
// ultra rare sigma honk - 1 / 56
(01, Simple(" HONK HONK HONK HONK!!!!!!!!!!!!!!!")),
])),
// lowercases all `p` letters (use "p" match from `Original`, then lowercase)
("p", Lowercase(Original)),
// uppercases all `p` letters, undoing previous operation
("p", Uppercase(Original)),
],

// accent can be used with severity (non negative value). higher severities can either extend
Expand Down Expand Up @@ -67,7 +71,7 @@
Simple("É"),
])),
// 50% to do nothing, no replacement
(1, Noop),
(1, Original),
])),
],
),
Expand Down
4 changes: 2 additions & 2 deletions examples/linux.ron
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
Simple("zaazaa "),
Simple("(=;ェ;=) "),
])),
(9, Noop),
(9, Original),
])),
// 80% for ending
("$", Weights([
Expand Down Expand Up @@ -142,7 +142,7 @@
Simple(" zaazaa"),
Simple(" (=;ェ;=)"),
])),
(2, Noop),
(2, Original),
])),
],
)
4 changes: 2 additions & 2 deletions examples/scotsman.ron
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,15 @@
("ow", Simple("ou")),
("$", Weights([
(2, Simple(" ye daft cunt")),
(8, Noop),
(8, Original),
])),
],
severities: {
1: Extend((
patterns: [
("$", Weights([
(1, Simple(" ye daft cunt")),
(1, Noop),
(1, Original),
])),
],
)),
Expand Down
4 changes: 2 additions & 2 deletions examples/slav.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
patterns: [
(r"\b(a|the) +", Weights([
(1, Noop),
(1, Original),
(1, Simple("")),
])),
(r"\bha", Simple("ga")),
Expand All @@ -26,7 +26,7 @@
])),
("w", Simple("v")),
("$", Weights([
(1, Noop),
(1, Original),
(1, Any([
Simple("cyka"),
Simple("blyat"),
Expand Down
4 changes: 2 additions & 2 deletions examples/spurdo.ron
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
("x", Simple("gs")),
(r"\Bng\b", Simple("gn")),
("$", Weights([
(1, Noop),
(1, Original),
(1, Any([
Simple(" :D"),
Simple(" :DD"),
Expand All @@ -30,7 +30,7 @@
1: Extend((
patterns: [
("$", Weights([
(1, Noop),
(1, Original),
(2, Any([
Simple(" :DD"),
Simple(" :DDD"),
Expand Down
Loading

0 comments on commit 860b88f

Please sign in to comment.