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

export const lState = new State(
  "l",
  [
    "vill", "mill", "tranquille", "illdeb", "ill", "eil",
    "ll", "excep_il", "apostrophe", "lisole"
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["l"], 1)], // fallback

    ["vill", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /l/ },
      { direction: "before", regExp: /^vi/ }
    ]}, SAMPA.FR.consonants["l"], 2)],

    ["mill", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /l/ },
      { direction: "before", regExp: /^mi/ }
    ]}, SAMPA.FR.consonants["l"], 2)],

    ["tranquille", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /l/ },
      { direction: "before", regExp: /tranqui/ }
    ]}, SAMPA.FR.consonants["l"], 2)],

    ["illdeb", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /l/ },
      { direction: "before", regExp: /^i/ }
    ]}, SAMPA.FR.consonants["l"], 2)],

    ["ill", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /l/ },
      { direction: "before", regExp: /.i/ }
    ]}, SAMPA.FR.semiVowels["j"], 2)],

    ["eil", new Rule({ type: "regExp", regExps: [
      { direction: "before", regExp: /eu?i/ }
    ]}, SAMPA.FR.semiVowels["j"], 1)],

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

    ["excep_il", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ },
      { direction: "before", regExp: /fusi|outi|genti/ }
    ]}, SAMPA.specials["#"], 1)],

    ["apostrophe", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: apostropheRegExp }
    ]}, SAMPA.FR.consonants["l"], 1)],

    ["lisole", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /^/ }
    ]}, SAMPA.FR.consonants["l"], 1)]
  ])
);
