The Singlish engine is built on a layered architecture designed to separate the stateless phonetic conversion logic from the stateful input method editor (IME) behavior required for real-time typing.Documentation Index
Fetch the complete documentation index at: https://developers.remeinium.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
High-Level Overview
Core Components
1. Prefix Trie (ime-engine module)
The heart of the real-time engine is a Prefix Trie. This data structure stores all valid Singlish sequences (e.g., k, ka, kru, zdha).
- Why a Trie?
When a user types
k, we don’t know if they intend to typeka(ක),kra(ක්ර), or justk(ක්). The Trie allows us to:- Validate prefixes: “Is
zqaa valid start of a character?” - Lookahead: Determine if we should wait for more input or commit the current buffer.
- Validate prefixes: “Is
2. Greedy Tokenizer (converter module)
For converting full strings (e.g., pasting text), we use a Greedy Tokenizer. It scans the input string and attempts to match the longest possible Singlish pattern at each position.
- Algorithm:
- Iterate through the input string.
- At each index, check patterns in descending order of length (4 chars down to 1 char).
- If a match is found, consume those characters and map to the corresponding phoneme.
- Advance the index.
3. Context-Aware Phoneme Mapper
Converting Singlish tokens to Sinhala isn’t a 1-to-1 mapping. It depends on context:- Inherent Vowels: Consonants like
kimply an inherentasound unless followed by a vowel or a hal (virama). - Modifier Placement: Vowel signs (pili) must be attached to the preceding consonant.
- Conjuncts: Special sequences like
yafter a consonant trigger Yansaya (e.g.,kya->ක්ය), andrtriggers Rakaransaya (e.g.,kra->ක්ර).
State Management
TheSinglishIME class maintains:
- Committed Text: Text that has been fully resolved and cannot change.
- Pending Buffer: The current sequence of keystrokes being processed (e.g.,
k,ka,kar).

