Last active
May 27, 2017 11:26
-
-
Save santhoshtr/09fd4fa3eac1c30059b70e6ec9e70bd7 to your computer and use it in GitHub Desktop.
Malayalam Syllable Model using PEG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Word = Syllable+ | |
Syllable = s:( Vowel | |
/ Chillu | |
/ ( Conjunct / Consonant ) Signs | |
/ ZWNJ | |
) { | |
if ( Array.isArray( s ) ) { | |
return s.join( '' ) | |
} | |
return s | |
} | |
Vowel = [അആഇഈഉഊഋഎഏഐഒഓഔഔഅം] | |
VowelSign = [ാിീുൃെേൊോൗൂൈ] | |
Consonant = [കഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരലവശഷസഹളഴറ] | |
Virama = [്] | |
Visarga = [ഃ] | |
Anuswara = [ം] | |
DotReph= [ൎ] | |
Chillu = [ൻർൽൾൿൺൔൕൖ] / (Consonant Virama ZWJ) | |
ZWNJ = [\u200C] | |
ZWJ = [\u200D] | |
HalfConsonant = (c1:Consonant x:Virama) { return [c1, x].join( '' ); } | |
/ DotReph | |
Conjunct = c1x:HalfConsonant c2:( Conjunct / Consonant ) { | |
return [c1x, c2].join( '' ); | |
} | |
Signs = v:VowelSign? h:Visarga? a:Anuswara? x:Virama? & { | |
if ( x && a ) { | |
// Anuswara cant be with a virama | |
return false; | |
} | |
if ( v && x ) { | |
// Samvruthokaram, v must be u sign | |
return v === 'ു'; | |
} | |
if ( h && (a || x) ) { | |
// Nothing comes with Visarga | |
return false; | |
} | |
if ( x && location().start.offset === input.length ) { | |
return true; | |
} | |
return true; | |
} { | |
return [v, h, a, x].join( '' ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment