%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%            post-processing rules              %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%     Variables / Shorthands     %%%%%%%%%%%%%%%

% These define shorthands used for readability & brevity in
% the rules

%%%% 1. Consonants

::consonant:: = b|k|d|f|g|h|j|l|m|n|p|r|s|t|ʋ
::m:: = [\+]*

%%%%%%%%%%%%%%%    Orthography    %%%%%%%%%%%%%%%

%%%% 2. Remove ˀ when it is not intervocalic

ˀ -> 0  / _ ::m::::consonant::
ˀ -> 0  / ::consonant::::m:: _

%%%%%%%%%%%%%%%     Allophony     %%%%%%%%%%%%%%%

%%%% 3. Velar nasals

n -> ŋ / _ ::m::k
g -> ŋ / _ ::m::n

%%%%%%%%%%%%%%%    Diphthongs     %%%%%%%%%%%%%%%

%%%% 4. Detect the diphthongs
% We check from the most restricted to the most global

% ɑ and æ can only be first element of a diphthong
0 -> ͜ / ([^͜]|#)æ::m:: _ [iy]([^͜ː]|#)
0 -> ͜ / ([^͜]|#)æ::m:: _ [iy]([^͜ː]|#)
0 -> ͜ / ([^͜]|#)ɑ::m:: _ [iu]([^͜ː]|#)
0 -> ͜ / ([^͜]|#)ɑ::m:: _ [iu]([^͜ː]|#)

% o can be second element of u diphthong
0 -> ͜ / ([^͜u]|#)o::m:: _ [iu]([^͜ː]|#)
0 -> ͜ / ([^͜u]|#)o::m:: _ [iu]([^͜ː]|#)

% e can be second element of i diphthong
0 -> ͜ / ([^͜i]|#)e::m:: _ [iuy]([^͜ː]|#)
0 -> ͜ / ([^͜i]|#)e::m:: _ [iuy]([^͜ː]|#)

% ø can be second element of y diphthong
0 -> ͜ / ([^͜y]|#)ø::m:: _ [iy]([^͜ː]|#)
0 -> ͜ / ([^͜y]|#)ø::m:: _ [iy]([^͜ː]|#)

% y can be second element of four diphthongs
0 -> ͜ / ([^͜æeiø]|#)y::m:: _ [iø]([^͜ː]|#)
0 -> ͜ / ([^͜æeiø]|#)y::m:: _ [iø]([^͜ː]|#)

% u can be second element of four diphthongs
0 -> ͜ / ([^ɑ͜eoi]|#)u[\[]? _ [io]([^͜ː]|#)
0 -> ͜ / ([^ɑ͜eoi]|#)u[\[]? _ [io]([^͜ː]|#)

% i can be second element of everything
0 -> ͜ / ([^ɑ͜æeoøuy]|#)i[\[]? _ [euy]([^͜ː]|#)
0 -> ͜ / ([^ɑ͜æeoøuy]|#)i[\[]? _ [euy]([^͜ː]|#)
