NAIDE-X (.nx) Syntax
NAIDE-X is an ultra-compact syntax optimized for AI token efficiency. Files use the .nx extension and compile through a preprocessor into standard NAIDE before transpilation.
When to use NX? Use .nx when you're generating code with AI and want minimal tokens. Use .naide for human-readable code.
Variables
| NAIDE | NX |
str name = "World" | s:name="World" |
int count = 42 | i:count=42 |
num price = 9.99 | n:price=9.99 |
bool active = true | b:active=true |
any data = null | a:data=null |
list items = [] | l:items=[] |
map config = {} | m:config={} |
Functions
| NAIDE | NX |
fn greet(name): | f greet(name) |
fn.async fetch(): | ~f fetch() |
ret value | >value |
pub fn add(a, b): | +f add(a,b) |
Return Type Annotations
f greet(s:who)s # fn greet(who) -> str
>"Hello, {who}!"
~f load(s:url)a # async fn load(url) -> any
a:res=~fetch(url)
>~res.json()
Server & Routes
| NAIDE | NX |
server app port 3000: | $app:3000 |
get "/": | G"/" |
post "/api": | P"/api" |
put "/api/:id": | U"/api/:id" |
del "/api/:id": | D"/api/:id" |
patch "/api/:id": | X"/api/:id" |
Response Shorthands
| NAIDE | NX |
ret.html "..." | >.h "..." |
ret.redirect "/new" | >.r "/new" |
ret.text "..." | >.t "..." |
ret.file "path" | >.f "path" |
ret.render "view" {} | >.v "view" {} |
ret.download "path" | >.d "path" |
Control Flow
| NAIDE | NX |
if condition: | ?condition |
elif condition: | ??condition |
else: | ?? |
each item in list: | @item in list |
for i in 0..10: | #i 0..10 |
while cond: | &cond |
Error Handling
! # try:
risky()
!!e # fail e:
log e.message
!!! # ensure:
cleanup()
Logging
| NAIDE | NX |
log "msg" | log"msg" |
log.warn "msg" | log.w"msg" |
log.error "msg" | log.e"msg" |
log.info "msg" | log.i"msg" |
log.debug "msg" | log.d"msg" |
Complete Example
# NX: Todo API in minimal tokens
$app:3000
G"/"
>{msg:"Todo API"}
G"/api/todos"
l:todos=[{id:1,title:"Learn NAIDE",done:false}]
>todos
P"/api/todos"(req,res)
a:todo=req.body
>{created:true}
Converting NAIDE to NX
$ naide convert app.naide # outputs app.nx