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

export const pState = new State(
  "p",
  [
    "h", "oup", "drap", "trop", "sculpt", "sirop", "sgalop",
    "rps", "amp", "compt", "bapti", "sept", "p"
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["p"], 1)], // fallback

    ["h", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /h/ }
    ]}, SAMPA.FR.consonants["f"], 2)],

    ["amp", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /ch?am/ }
    ]}, SAMPA.specials["#"], 1)],

    ["bapti", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /ti/ },
      { direction: "before", regExp: /ba/ }
    ]}, SAMPA.specials["#"], 1)],

    ["compt", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t/ },
      { direction: "before", regExp: /com/ }
    ]}, SAMPA.specials["#"], 1)],

    ["drap", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /dra/ }
    ]}, SAMPA.specials["#"], 1)],

    ["oup", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /[cl]ou/ }
    ]}, SAMPA.specials["#"], 1)],

    ["rps", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s$/ },
      { direction: "before", regExp: /[rm]/ }
    ]}, SAMPA.specials["#"], 1)],

    ["sculpt", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t/ },
      { direction: "before", regExp: /scul/ }
    ]}, SAMPA.specials["#"], 1)],

    ["sept", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /ts?$/ },
      { direction: "before", regExp: /^se/ }
    ]}, SAMPA.specials["#"], 1)],

    ["sgalop", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /[gs]alo/ }
    ]}, SAMPA.specials["#"], 1)],

    ["sirop", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /siro/ }
    ]}, SAMPA.specials["#"], 1)],

    ["trop", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /tro/ }
    ]}, SAMPA.specials["#"], 1)],

    ["p", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /p/ }
    ]}, SAMPA.FR.consonants["p"], 2)]
  ])
);
