import { SAMPA } from "../../sampa";
import { State, Rule } from "../../state-machine";

export const gState = new State(
  "g",
  [
    "g", "ao", "eiy", "aiguille", "u_consonne", "u",
    "n", "vingt", "g_muet_oin", "g_muet_our",
    "g_muet_an", "g_muet_fin"
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["g"], 1)],
    ["g", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /g/ }] }, SAMPA.FR.consonants["g"], 2)],
    ["eiy", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /[eéèêëïiy]/ }] }, SAMPA.FR.consonants["Z"], 1)],
    ["ao", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /[ao]/ }] }, SAMPA.FR.consonants["g"], 1)],
    ["aiguille", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /u/ }, { direction: "before", regExp: /ai/ }] }, SAMPA.FR.consonants["g"], 1)],
    ["u_consonne", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /u[bcçdfghjklmnpqrstvwxz]/ }] }, SAMPA.FR.consonants["g"], 1)],
    ["u", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /u/ }] }, SAMPA.FR.consonants["g"], 2)],
    ["n", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /n/ }] }, SAMPA.FR.consonants['n~'], 2)],
    ["vingt", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /t/ }, { direction: "before", regExp: /vin/ }] }, SAMPA.specials["#"], 1)],
    ["g_muet_oin", new Rule({ type: "regExp", regExps: [{ direction: "before", regExp: /oin?/ }] }, SAMPA.specials["#"], 1)],
    ["g_muet_our", new Rule({ type: "regExp", regExps: [{ direction: "before", regExp: /our?/ }] }, SAMPA.specials["#"], 1)],
    ["g_muet_an", new Rule({ type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }, { direction: "before", regExp: /(s|^ét|^r)an/ }] }, SAMPA.specials["#"], 1)],
    ["g_muet_fin", new Rule({ type: "regExp", regExps: [{ direction: "before", regExp: /lon|haren/ }] }, SAMPA.specials["#"], 1)]
  ])
);
