====== 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 '''' and finish with ''''. All NXML nodes inside are Neko expressions. An NXML block is like a Neko block. For example '''' is the equivalent of the empty Neko block ''{ }''.
Other nodes are the following :
* '''' the literal integer 3
* '''' the literal float 1.5
* '''' the literal string ''a string''
* '''' the identifier ''id'' (includes special identifiers such as null, true, false and this)
* ''e1 e2 e3...'' a block having several subexpressions
* ''
e
'' parenthis around a subexpression
* ''e'' field access of a subexpression ''(e).field''
* ''e0 e1 e2 e3...'' call of ''e0(e1,e2,e3...)''
* ''e1 e2'' array access ''e1[e2]''
* ''e'' local variable declaration, equivalent of ''var x = e, y''
* ''e1 e2'' while loop : ''while e1 e2''
* ''e1 e2'' do...while loop : ''do e1 while e2''
* ''e0 e1'' equivalent of ''if e0 e1''
* ''e0 e1 e2'' equivalent of ''if e0 e1 else e2''
* ''e1 e2'' a binary operation such as ''e1 * e2''
* ''e1 e2'' a try..catch block ''try e1 catch exc e2''
* ''e'' a function declaration such as ''function(x,y,z) e''
* '''' the return statement without expression
* ''e'' return of an expression value
* '''' the break statement without expression
* ''e'' break with an expression value
* '''' the continue statement
* ''e1 e2'' a way to tie two expressions together (such as ''e1;e2'')
* '''' the goto label ''here:''
* ''e0 e1 e2e1 e2edef'' a switch with several cases and an optional default
* '''' an object literal, equivalent to the neko code ''{ f0 => 42, f1 => "foo" }''
* ''....'' some neko source, can be embedded into a ''%%'' section.
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)
}
====== 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 '''' 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 '''' 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 '''' 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.