Table of Contents

NXML

Neko sources syntax is easy to read but can sometimes be difficult to generate. Also, it does not permit embedding file and line numbers informations. For example if your generate from a file in your language MyFile.mylang to myfile.neko you would like to get errors traces in terms of position in the original MyFile.mylang file.

For these reasons, an extension of the neko syntax is allowed which is called NXML. This is not a different format in sense that you easily mix NXML and Neko sources together. You can put some NXML expressions in Neko sources and some Neko sources into an NXML document. NXML is based on XML and is representing a Neko Abstract Syntax Tree (AST).

NXML Nodes

NXML is not a different Neko syntax but a syntax extension. It means that you can put some NXML expressions inside a Neko program and some Neko program inside NXML as well.

In order to use the NXML syntax you need to start with <nxml> and finish with </nxml>. All NXML nodes inside are Neko expressions. An NXML block is like a Neko block. For example <nxml></nxml> is the equivalent of the empty Neko block { }.

Other nodes are the following :

For example, if we want to represent the fibonnaci function in NXML :

fib = function(n) {
    if( n <= 1 ) 1 else fib(n-1)+fib(n-2)
}
<o v="=">
    <v v="fib"/>
    <function v="n">
        <if>
             <o v="<="><v v="n"/><i v="1"/></o>
             <i v="1"/>
             <o v="+">
                 <c><v v="fib"/><o v="-"><v v="n"/><i v="1"/></o></c>
                 <c><v v="fib"/><o v="-"><v v="n"/><i v="2"/></o></c>
             </o>
        </if>
    </function>
</o>

File Position

The additional attribute p can be placed on every NXML node in order to specify from which original file and line the expression is generated. For example <i v=”33” p=”myfile.l:478”/> is the integer 33 referenced in myfile.l at line 478.

When encountered, such position is stored and remains valid for all NXML nodes. For example <nxml><i v=”33” p=”myfile.l:478”/><i v=”34”/></nxml> is listing two integers from myfile.l, both at line 478.

If you don’t specify the filename in the p attribute, it’s considered to be a number of lines skipped since the last p information. For example <nxml><i v=”33” p=”myfile.l:478”/><i v=”34” p=”2”/></nxml> is listing two integers from myfile.l, the first 33 at line 478 and the second 34 at line 480 (478 + 2).

NXML to Neko

There is a NXML to Neko generator which is available using the nekoc compiler. Simply run nekoc myfile.neko containing Neko/NXML syntax, it will create a myfile2.neko that will only contain Neko source code.

There is not a Neko to NXML generator right now, although it should be possible to write one very easily.