dd1adf7

Pinchord · pinchord.git · Tickets · Changelog

Branches > main > dd1adf7 > files

Remove repeated repetition (hehe) from generate-mods.clj

Grahp, 2026-10-26

Commit: dd1adf75fcc3a748cac026aeacbcb5286005f64b
Parent: 476548e

1 changed file:

generate-mods.clj modified (view file)

@@ -1,7 +1,3 @@-; Map of symbols to names-#_(def symbol-names-    {"." "period"})- (def symbol-names   {"á" "aacute"    "â" "acircumflex"@@ -152,6 +148,13 @@                    "LS" {:no-mods "{^}\t"                          :with-mods "tab"}}}) +(defn apply-mods [mod-set chord _]+  (str "{#"+       (reduce (fn [acc mod]+                 (str mod "(" acc ")"))+               chord mod-set)+       "}"))+ (def vowel-chords   {"A"    ["control"]    "O"    ["shift"]@@ -169,64 +172,71 @@    "OIU"  ["shift" "super" "alt"]    "AOIU" ["control" "shift" "super" "alt"]}) -; combos: vector of combos-(defn apply-mods [x combos]-  (str "{#"-       (reduce (fn [acc mod]-                 (str mod "(" acc ")"))-               x combos)-       "}"))+(def no-mods {"-" []})+(def all-mods (merge vowel-chords no-mods)) -(defn ->map [xs]-  (update-keys (apply hash-map (flatten xs))-               (fn [x]-                 (str/replace x #"-\^" "^"))))+(def repetitions+  {"" 1+   "*" 2+   "T" 3+   "T*" 4})+(def no-repetition+  {"" 1}) -(defn rep [n s]-  (apply str (repeat n s)))+(def always-attach {"" "{^}"+                    "+" "{^}"})+(def never-attach {"" ""+                   "+" ""})+(def attach {"" "{}"+             "+" "{^}"})+(def attach-and-capitalize+  (assoc attach+         "#" "{}{-|}"+         "#+" "{^}{-|}"))++(defn flatten-map+  "Flattens a nested sequence of key value pairs into a map."+  [xs]+  (apply hash-map (flatten xs)))++(defn with-mod-chord+  "Joins a chord with a mod chord. If the mod chord is -, and the chord+   contains ^, properly formats the returned chord."+  [mod-chord chord]+  (if (and (= mod-chord "-") (str/starts-with? chord "^"))+    chord+    (str mod-chord chord)))++(defn generate-entries+  "Generates a nested sequence of key value pair entries for each combination+   of prefixes, the starter, the mods, the chords, and the suffixes.+   Calls ->translation with the set of mods, the chord translation, and the+   suffix translation."+  [prefixes starter mods chords suffixes ->translation]+  (for [[prefix-chord prefix-translation] prefixes+        [mod-chord mod-set] mods+        [chord translation] chords+        [suffix-chord suffix-translation] suffixes]+    [(str prefix-chord starter (with-mod-chord mod-chord chord) suffix-chord)+     (str prefix-translation (->translation mod-set translation suffix-translation))]))++(defn repeated [_ translation suffix]+  (apply str (repeat suffix translation)))  (def symbols-dict-  (->map-   (let [{:keys [starter chords shortcuts mod-shortcuts]} symbols]-     [(for [[mod symbol] chords-            [chord combo] vowel-chords]-        [(str starter chord mod) (str "{^}" (apply-mods (symbol-name symbol) combo))-         (str "+" starter chord mod) (str "{^}" (apply-mods (symbol-name symbol) combo))])--      (for [[mod shortcut] shortcuts-            [chord combo] (assoc vowel-chords "-" [])]-        [(str starter chord mod) (apply-mods shortcut combo)-         (str "+" starter chord mod) (apply-mods shortcut combo)])--      (for [[mod {:keys [no-mods with-mods]}] mod-shortcuts]-        [          ; TODO need to add repitition for these?-         [(str starter "-" mod) no-mods-          (str "+" starter "-" mod) no-mods]-         (for [[chord combo] vowel-chords]-           [(str starter chord mod) (apply-mods with-mods combo)-            (str "+" starter chord mod) (apply-mods with-mods combo)])])--      (for [[mod symbol] chords]-        [          ; the 4 combos of T* with and without e-         (str starter "-" mod) (str "{}" symbol)-         (str "+" starter "-" mod) (str "{^}" symbol)-         (str starter "-" mod "e") (str "{}" symbol "=")-         (str "+" starter "-" mod "e") (str "{^}" symbol "=")--         (str starter "-" mod "*") (str "{}" (rep 2 symbol))-         (str "+" starter "-" mod "*") (str "{^}" (rep 2 symbol))-         (str starter "-" mod "*e") (str "{}" (rep 2 symbol) "=")-         (str "+" starter "-" mod "*e") (str "{^}" (rep 2 symbol) "=")--         (str starter "-" mod "T") (str "{}" (rep 3 symbol))-         (str "+" starter "-" mod "T") (str "{^}" (rep 3 symbol))-         (str starter "-" mod "Te") (str "{}" (rep 3 symbol) "=")-         (str "+" starter "-" mod "Te") (str "{^}" (rep 3 symbol) "=")--         (str starter "-" mod "T*") (str "{}" (rep 4 symbol))-         (str "+" starter "-" mod "T*") (str "{^}" (rep 4 symbol))-         (str starter "-" mod "T*e") (str "{}" (rep 4 symbol) "=")-         (str "+" starter "-" mod "T*e") (str "{^}" (rep 4 symbol) "=")])])))+  (flatten-map+   (let [{:keys [starter chords shortcuts mod-shortcuts]} symbols+         mapped-symbols (update-vals chords symbol-name)+         symbols-without-mods (update-vals mod-shortcuts :no-mods)+         symbols-with-mods (update-vals mod-shortcuts :with-mods)+         e-repetitions (update-keys repetitions #(str % "e"))+         repeated= #(str (apply repeated %&) "=")]+     [(generate-entries always-attach starter vowel-chords mapped-symbols       no-repetition apply-mods)+      (generate-entries never-attach  starter all-mods     shortcuts            no-repetition apply-mods)+      (generate-entries never-attach  starter no-mods      symbols-without-mods no-repetition repeated)+      (generate-entries never-attach  starter vowel-chords symbols-with-mods    no-repetition apply-mods)+      (generate-entries attach   starter no-mods      chords               repetitions   repeated)+      (generate-entries attach   starter no-mods      chords               e-repetitions repeated=)])))  (def numbers   {:starter "TPWHR"@@ -276,31 +286,17 @@             "RS*"  "F12"}})  (def numbers-dict-  (->map+  (flatten-map    (let [{:keys [starter left right F-starter F-keys]} numbers]-     [(for [[number-chord number] (merge left right)-            [mod-chord combo] vowel-chords]-        [(str starter mod-chord number-chord) (str "{^}" (apply-mods number combo))-         (str "+" starter mod-chord number-chord) (str "{^}" (apply-mods number combo))])--      (for [[f-chord f-key] F-keys-            [mod-chord combo] (assoc vowel-chords "-" [])]-        [(str F-starter mod-chord f-chord) (apply-mods f-key combo)-         (str "+" F-starter mod-chord f-chord) (apply-mods f-key combo)])--      (for [[left-chord left-number] left-            [right-chord right-number] right]-        [(str starter left-chord right-chord) (str "{}" left-number right-number)-         (str "+" starter left-chord right-chord) (str "{^}" left-number right-number)--         (str starter "^" left-chord right-chord) (str "{}" left-number right-number "0")-         (str "+" starter "^" left-chord right-chord) (str "{^}" left-number right-number "0")--         (str starter left-chord right-chord "e") (str "{}" left-number right-number "00")-         (str "+" starter left-chord right-chord "e") (str "{^}" left-number right-number "00")--         (str starter "^" left-chord right-chord "e") (str "{}" left-number right-number "000")-         (str "+" starter "^" left-chord right-chord "e") (str "{^}" left-number right-number "000")])])))+     [(generate-entries always-attach starter vowel-chords (merge left right) no-repetition apply-mods)+      (generate-entries never-attach F-starter all-mods F-keys no-repetition apply-mods)+      (generate-entries attach starter+                        {"" "" "^" "0"}+                        (for [[left-chord left-number] left+                              [right-chord right-number] right]+                          [(str left-chord right-chord) (str left-number right-number)])+                        {"" "" "e" "00"}+                        (fn [zeroes n suffix] (str n zeroes suffix)))])))  (def movement-starter "PWH") (def movement-chords@@ -314,11 +310,8 @@    "FS" "end"})  (def movement-dict-  (->map-   [(for [[mod-chord combo] (assoc vowel-chords "-" [])-          [chord movement] movement-chords]-      [(str movement-starter mod-chord chord) (apply-mods movement combo)-       (str "+" movement-starter mod-chord chord) (apply-mods movement combo)])]))+  (flatten-map+   (generate-entries never-attach movement-starter all-mods movement-chords no-repetition apply-mods)))  (def fingerspelling-starter "TWR") (def letters@@ -353,16 +346,10 @@    "PFS" "z"})  (def fingerspelling-dict-  (->map-   [(for [[mod-chord combo] vowel-chords-          [chord letter] letters]-      [(str fingerspelling-starter mod-chord chord) (apply-mods letter combo)-       (str "+" fingerspelling-starter mod-chord chord) (apply-mods letter combo)])--    (for [[chord letter] letters]-      [(str fingerspelling-starter "-" chord) (str "{}" letter)-       (str "#" fingerspelling-starter "-" chord) (str "{}{-|}" letter)-       (str "+" fingerspelling-starter "-" chord) (str "{^}" letter)-       (str "#+" fingerspelling-starter "-" chord) (str "{^}{-|}" letter)])]))+  (flatten-map+   [(generate-entries never-attach fingerspelling-starter+                      vowel-chords letters no-repetition apply-mods)+    (generate-entries attach-and-capitalize fingerspelling-starter+                      no-mods letters no-repetition (fn [_ translation _] translation))]))  (spit "pinchord-mods.json" (json/generate-string (merge symbols-dict fingerspelling-dict numbers-dict movement-dict)))