Romenagri Transliteration System

A formal specification of the Unicode Devanagari ↔ ACII ↔ Romenagri pipeline, with Sanskrit and Vedic extensions and the nukta layer.

Explainer

How a text gets from Unicode to Romenagri and back, and what the nukta layer adds. This page summarises Romenagri/TRANSLITERATION.md, which has the full definition, the grammar of the parser and the measurements. A table or an output on this page was read from the headers, or written by the compiled programs, when the site was built.

The three layers

Unicode text (UTF-8 in files)
     |  iconv -f utf8 -t utf16
     v
UTF-16LE
     |  uni2acii                 table: unicode.h, nukta.h
     v
ACII bytes
     |  acii2rmn                 table: acii.h   (the decoder)
     v
Romenagri: ASCII letters, digits, punctuation
     |  rmn2acii                 table: acii.h   (the parser)
     v
ACII bytes
     |  acii2uni                 table: unicode.h, nukta.h
     v
UTF-16LE with a byte-order mark  ->  iconv -f utf16 -t utf8
ProgramReads, writesTable
uni2aciiUTF-16LE, ACII bytesunicode.h, nukta.h
acii2uniACII bytes, UTF-16LE with a byte-order mark (a line feed becomes CR LF)unicode.h, nukta.h
acii2rmnACII, Romenagri (a filter: Latin words are wrapped as "e_word")acii.h
rmn2aciiRomenagri, ACII (a filter: it unwraps those and hands every run of [A-Za-z_] to the parser)acii.h
acii2hinACII, “saral” Latin: one way and lossy by designaciihin.h
fixuninumUTF-8, UTF-8 with the digits of the ten Indic scripts rewritten to ASCII digitsnone

acii2cf and acii2pcf are the filters for program text: Latin words and string and character literals are left as they are. Hindawi's own h2c and c2h, which sit in such pipelines, are not part of Romenagri.

The tables

The layout of the upper half of ACII:

BytesWhat
80U+0979 (ZHA), an earlier extension of this project
81 to 8Cthe twelve Sanskrit and Vedic additions (Characters)
A1 to A3candrabindu, anusvara, visarga
A4 to B2the independent vowels
B3 to D8the consonants KA to HA
DA to E7the dependent vowel signs
E8, E9halant, nukta
EA, EBdanda; avagraha
EFISCII's attribute code (row 0 of acii.h: the decoder drops the byte that follows it)

ACII to Romenagri: the decoder

acii2rmn is a stack machine. Its state is a stack of characters, and for each input byte b it does this:

r := the first row (table order) whose first byte is b
if there is no such row:
    unless b follows the byte EF (attribute code): push the character b
otherwise, if r.key starts with '^' and the stack is not empty:   -- a dependent sign, or the halant
    pop one character                                             -- the 'a' of the consonant before
    if r.key starts with "^z":                                    -- the nukta
        t1 := pop one character
        if t1 = 'h':   t2 := pop one character
                       if t2 = 'd': push "_rdha"   else: push t2, "hza"
        elif t1 = 'd': push "_rda"
        else:          push t1, "za"
    else: push r.key without its '^'
otherwise: push r.key
output the stack

Romenagri to ACII: the parser

rmn2acii reads a string once, from the left, with no backtracking. In the C code it is five mutually recursive functions, level1, level2a, level2b, level2c and matra; every call is the last thing its branch does, so it is really a loop over five states, and the specification writes it down as a grammar of decision lists that a test program reads and runs.

The decision of the nukta layer, which the specification records as the one for cases C1 and C6, rests on this split: a consonant is recognised and its sound mapped at level 1, before level 2 binds a halant, an adjunct consonant or a vowel sign to it, so a letter with a nukta has to be a consonant and a nukta before level 2 sees it.

The round-trip contract

For every text in the set W of well-formed ACII, acii2rmn followed by rmn2acii returns the same bytes (with the filters' reading: the parser sees each run of [A-Za-z_] separately). At the Unicode end, every code point that unicode.h maps survives uni2acii and acii2uni. W is a text of syllables and spaces:

text      = { syllable | SPACE } ;
syllable  = body [ modifier ] ;
body      = vowel [ accent ]
          | AVAGRAHA | DOUBLE-DANDA | OM
          | cluster ( HALANT | [ accent ] [ sign ] [ accent ] ) ;
cluster   = consonant [ nukta ] { HALANT consonant [ nukta ] } ;

A syllable that ends in a halant is followed by a space or by the end of the text, and a nukta follows only one of the eleven consonants KA KHA GA JA DDA DDHA PHA YA NA RA LLA. Outside W things may work, and nothing is promised. The cases that are easy to meet:

The nukta layer

ACII writes a letter with a nukta as the byte of the consonant and E9, which is U+093C. Unicode has eleven letters that are such a pair in one code point. The nukta layer is a third patch, to the two Unicode converters only: uni2acii and acii2uni. It has three parts.

What each form writes, from runs of the compiled converters:

ProgramInasis (default)nfcnfd
acii2uniC7ऩ U+0929ऩ U+0929ऩ U+0928 U+093C
acii2uniD0ऱ U+0931ऱ U+0931ऱ U+0930 U+093C
acii2uniC6 E9ऩ U+0928 U+093Cऩ U+0929ऩ U+0928 U+093C
acii2uniCF E9ऱ U+0930 U+093Cऱ U+0931ऱ U+0930 U+093C
acii2uniD2 E9ऴ U+0933 U+093Cऴ U+0934ऴ U+0933 U+093C
acii2uniBF E9ड़ U+0921 U+093Cड़ U+0921 U+093Cड़ U+0921 U+093C
uni2aciiऩ U+0929C7C7C6 E9
uni2aciiऱ U+0931D0D0CF E9
uni2aciiन and a nukta U+0928 U+093CC6 E9C7C6 E9
uni2aciiर and a nukta U+0930 U+093CCF E9D0CF E9
uni2aciiऴ U+0934D2 E9D2 E9D2 E9
uni2aciiड़ U+095CBF E9BF E9BF E9
uni2aciiड and a nukta U+0921 U+093CBF E9BF E9BF E9

No form writes the eight letters of U+0958 to U+095F as single code points, because any normaliser would split them again. Unicode calls them composition exclusions. Only U+0929, U+0931 and U+0934 are composed by NFC.

Choosing the form

The form can be chosen at four levels. Where more than one is given, the later row wins.

LevelHowExample
the buildthe macro NUKTA_FORM, given when a converter is compiled-DNUKTA_FORM=NUKTA_NFC
the environmentthe variable ROMENAGRI_NUKTA_FORMROMENAGRI_NUKTA_FORM=nfc uni2acii
the command line-f FORM or --form=FORM, on both convertersacii2uni -f nfd in.acii out.utf16
a function calla program that includes nukta.h calls nukta_set_form ("nfc"), or sets nukta_formif (nukta_set_form (argv[1]) < 0) ...

A name that is not a form is an error: a message on stderr, exit status 1, and nothing is converted. The two converters should be given the same form, or a letter changes spelling on its way through.

A worked example

The cluster ड़्व typed with the single code point (U+095C DEVANAGARI LETTER DDDHA, U+094D VIRAMA, U+0935 VA):

  1. uni2acii writes BF E9 E8 D4. U+095C has no row in unicode.h, so the rule writes the consonant, BF, and the nukta, E9.
  2. acii2rmn reads those bytes with its stack (the table shows the stack after each byte) and writes _rdwa.
  3. rmn2acii parses _rdwa and writes BF E9 E8 D4, the same bytes.
  4. acii2uni writes, in each form:
    • form asis: ड़्व U+0921 U+093C U+094D U+0935
    • form nfc: ड़्व U+0921 U+093C U+094D U+0935
    • form nfd: ड़्व U+0921 U+093C U+094D U+0935
ByteRow of acii.hStack after it
BFdada
E9^za_rda
E8^_rd
D4wa_rdwa

Where the layer stops