Browse Source

Implement small vowels and small ka

Thomas Dy 7 years ago
parent
commit
8affb8e23f
2 changed files with 25 additions and 0 deletions
  1. 19 0
      src/kana.ts
  2. 6 0
      src/state.ts

+ 19 - 0
src/kana.ts

@@ -130,6 +130,13 @@ namespace kana {
     return new StateMachine(newState, base.finalState);
   }
 
+  function smallKana(base: StateMachine): StateMachine {
+    let newState = base.initialState.clone();
+    newState.addTransition('l', base.initialState);
+    newState.addTransition('x', base.initialState);
+    return new StateMachine(newState, base.finalState);
+  }
+
   interface KanaMapping {
     [index: string]: StateMachine
   }
@@ -219,6 +226,18 @@ namespace kana {
     SINGLE_KANA_MAPPING[letter] = literal(letter);
   });
 
+  [
+    ['ぁ', 'あ'],
+    ['ぃ', 'い'],
+    ['ぅ', 'う'],
+    ['ぇ', 'え'],
+    ['ぉ', 'お'],
+    ['ヵ', 'か']
+  ].forEach(pair => {
+    let [ small, big ] = pair;
+    SINGLE_KANA_MAPPING[small] = smallKana(SINGLE_KANA_MAPPING[big]);
+  });
+
   const DOUBLE_KANA_MAPPING: KanaMapping = {
     "きゃ": literal('kya'),
     "きゅ": literal('kyu'),

+ 6 - 0
src/state.ts

@@ -36,6 +36,12 @@ namespace state {
     transition(input: string): State | null {
       return this.transitions[input];
     }
+
+    clone(): State {
+      let state = new State(this.display);
+      state.transitions = {...this.transitions};
+      return state;
+    }
   }
 
   export class StateMachine {