XanaScript Playground

Write code in Portuguese. Run it instantly in your browser.

app.xs
Output
Ready to run XanaScript code...

Installation

Install via npm — the easiest way to get started.

npm (Cross-platform)

Requires Node.js. Works on Windows, Linux, and macOS.

Bash
npm install -g xanascript
xs run app.xs

VS Code Extension

Syntax highlight, snippets, integrated LSP. See on GitHub.

Bash
git clone https://github.com/xanascr/xs-vscode.git
cd xs-vscode
npm install -g vsce
vsce package
code --install-extension xanascript-*.vsix

Examples

Sample code in xs-examples.

Bash
git clone https://github.com/xanascr/xs-examples.git
cd xs-examples
xs run hello.xs
xs run server.xs

Commands

xs run app.xsRun
xs check app.xsCheck syntax
xs build app.xsBuild JS
xs build --optOptimized JS
xs build --wasmWebAssembly
xs build --standaloneSingle JS + runtime
xs test .Run tests
xs dev app.xsHot reload
xs replInteractive
xs lspLanguage Server
xs fmt app.xsFormat
xs docs src/ docs/Docs HTML
xs init my-appNew project
xs install pkgInstall package
xs publishPublish
xs benchBenchmark

Complete Syntax

Every keyword is clear Portuguese. The code explains itself.

Variables and Types

XS
CRIA x = 10                       // mutable
CRIA name: TEXTO = "John"      // type hint
CRIA active: BOOLEANO = VERDADEIRO
x += 5                              // += -= *= /= %=
TypeExample
NUMERO42, 3.14
TEXTO"hello"
BOOLEANOVERDADEIRO/FALSO
NULONULO
[ ][1, 2, 3]
{ }{ name: "John" }

Functions

XS
CHAMA ESSE CARA sum(a, b) {
  VOLTA a + b
}

CRIA square = (x) => x * x

CRIA fetch = ASSINCRONO (url) => {
  VOLTA AGORA VAI(url)
}

CRIA r = sum(3, 4)  // r = 7

CHAMA ESSE CARA declares functions. VOLTA returns. Arrow functions with =>. ASSINCRONO for async.

EXPORTA makes functions available to other modules via IMPORTA.

Control Flow

XS
SE LIGA SO (age >= 18) {
  SOLTA O GRITO("Adult")
} SENAO SE LIGA SO (age >= 12) {
  SOLTA O GRITO("Teen")
} SENAO {
  SOLTA O GRITO("Child")
}

REPETE NA MORAL (CRIA i = 0; i < 5; i++) {
  SOLTA O GRITO(i)
}

REPETE AI (condition) { ... }

VOA()       // break
CONTINUA()  // continue

SE LIGA SO / SENAO SE LIGA SO / SENAO for conditionals.

REPETE NA MORAL = for. REPETE AI = while.

VOA() = break. CONTINUA() = continue.

Classes and OOP

XS
CLASSE Animal {
  CONSTRUTOR(name) {
    CRIA ISTO.name = name
  }
  METODO speak() {
    SOLTA O GRITO(ISTO.name + " makes noise")
  }
}

CLASSE Dog HERDA Animal {
  METODO speak() {
    SOLTA O GRITO(ISTO.name + " says: Woof!")
  }
}

CRIA rex = NOVA Dog("Rex")
rex.speak()

CLASSE, HERDA, CONSTRUTOR, METODO, ISTO (this), NOVA (new).

Simple inheritance with HERDA. Methods declared with METODO.

Switch / Pattern Matching

XS
ESCOLHE (day) {
  CASO 1:
    SOLTA O GRITO("Sunday")
  CASO 2:
  CASO 3:
    SOLTA O GRITO("Week start")
  PADRAO:
    SOLTA O GRITO("Other")
}

CRIA res = COMBINA (value) {
  CASO 0 => "zero"
  CASO [a, b] => "array of 2"
  CASO { name } => name
  CASO _ => "other"
}

ESCOLHE/CASO/PADRAO — traditional switch with fallthrough.

COMBINA — Rust-style pattern matching. Destructures arrays, objects. _ is wildcard.

More Features

Template Strings

XS
CRIA name = "XanaScript"
SOLTA O GRITO(`Welcome to ${name}!`)

Try / Catch

XS
TENTA {
  CRIA r = PARSEIA("json")
} PEGA (err) {
  SOLTA O GRITO("Error:", err)
}

Destructuring + Spread

XS
CRIA [a, b] = [1, 2]
CRIA clone = [...list, 6]
CRIA r = person?.address ?? "N/A"

Modules

XS
// math.xs
EXPORTA sum
CHAMA ESSE CARA sum(a, b) { VOLTA a + b }

// main.xs
IMPORTA "./math.xs"
SOLTA O GRITO(sum(2, 3))

IMPORTA "./math.xs" as m
SOLTA O GRITO(m.sum(2, 3))

Operators

XS
a + b   a - b   a * b   a / b   a % b
a == b  a != b  a > b   a < b   a >= b  a <= b
a && b  a || b  !a
a ? b : c                              // ternary
"hello" ~= "^h.*o$"                // regex
x += 1   x -= 1   x *= 2

Built-ins

XS
SOLTA O GRITO("log")       // console.log
AGORA VAI(url)              // HTTP GET
ESPERA AI(1000)              // sleep
SORTEIA(1, 10)                // random
PARSEIA(json)               // JSON.parse
TAMANHO(array)              // length
CRIA SERVIDOR(3000, handler) // HTTP server

Why XanaScript?

A language that is not afraid to be different — and extremely capable.

Portuguese Syntax

CRIA, SE LIGA SO, REPETE NA MORAL — code any Brazilian understands at first glance.

Ultra-Optimized JS

Automatic TypedArrays, integer hints, loop unrolling, constant folding. Generates JS faster than hand-written code.

Native WebAssembly

Compiles directly to .wasm — no Emscripten, no wabt.js. Own binary emitter.

Built-in ORM

TABELA User { name: TEXTO } → automatic CRUD. Zero config, zero dependencies.

Compile-Time Macros

MACRO square(x) { x * x } — expanded at compile time. Zero runtime cost.

Native Test Runner

TESTE "desc" { AFIRMA(x == 5) }. Automatic discovery, colored output, CI-ready exit codes.

Full LSP

Autocomplete, real-time errors, hover, go-to-definition. VS Code, Neovim, any LSP editor.

Package Manager

xs install, xs publish. Packages via GitHub with npm fallback.

Rust-Style Errors

Errors with highlighted source code, arrow to exact location, hints and suggestions.

VS Code Extension

Syntax highlight, 18 snippets, integrated LSP, Run (Ctrl+Alt+X), Build, Test, Format.

Complete CLI

REPL, formatter, watcher with hot reload, bytecode VM, benchmark, docs generator. 20+ commands.

Task Runner

TAREFA build { } in tarefas.xs. Run with xs build. No Makefile needed.

Native WebAssembly

XanaScript is the only language that compiles directly to .wasm with no external dependencies.

XS
CHAMA ESSE CARA sum(a, b) {
  VOLTA a + b
}
CHAMA ESSE CARA main() {
  VOLTA sum(10, 20)
}
$ xs build --wasm math.xs

The src/wasm_binary.js module contains a proprietary Wasm binary emitter that:

  1. Takes the optimized AST
  2. Emits the Wasm binary format directly (magic + version + sections)
  3. Uses proper LEB128 encoding
  4. Generates i32 opcodes: constants, arithmetic, if/else, loops, functions

Zero dependencies. No Emscripten, no wabt.js, no AssemblyScript.

i3232-bit integers
+ - * / %Arithmetic
if/elseConditionals
loopsFor / While
callFunction calls

Built-in ORM

Declare a table, get automatic CRUD with local JSON storage.

XS
TABELA Product {
  name: TEXTO,
  price: NUMERO,
  stock: NUMERO
}

CRIA repo = Product
repo.create({ name: "Keyboard", price: 250, stock: 10 })
repo.create({ name: "Mouse", price: 120, stock: 25 })

SOLTA O GRITO(repo.list())          // all
SOLTA O GRITO(repo.find(1))        // by ID
CRIA expensive = repo.findWhere({ price: 250 })
repo.update(1, { name: "RGB Keyboard" })
repo.delete(2)
TypeDescription
TEXTOstring
NUMEROnumber
BOOLEANOboolean
DATAISO string
QUALQUERany
.create(data)CREATE
.list()READ ALL
.find(id)READ BY ID
.update(id, data)UPDATE
.delete(id)DELETE
.findWhere(filter)FILTER
.count()COUNT

Each table becomes a JSON file. Auto-incrementing IDs with automatic timestamps.

Compile-Time Macros

Code that generates code — expanded during compilation, zero runtime cost.

XS
MACRO square(x) { x * x }
MACRO cube(x) { x * square(x) }
MACRO max(a, b) {
  SE LIGA SO (a > b) { a } SENAO { b }
}
CRIA r1 = square(5)      // -> 5*5 = 25
CRIA r2 = cube(3)          // -> 27
CRIA r3 = max(10, 20)     // -> 20
CRIA r4 = max(square(4), cube(2))

Macros work like C #define, but with XanaScript syntax:

  1. The optimizer collects all MACRO declarations
  2. Each call is replaced with the body and substituted parameters
  3. Nested macros are expanded recursively
  4. After expansion, MACRO declarations disappear from the AST

The result is literal code — no call overhead, no closure.

Test Runner

Integrated test framework — no Jest, no Mocha, zero dependencies.

XS
TESTE "sum of two numbers" {
  CRIA r = 2 + 3
  AFIRMA(r == 5)
  ASSUNTO(r, 5)
}
TESTE "multiplication" {
  CRIA r = 3 * 4
  ASSUNTO(r, 12)
}
$ xs test .

Files with test in the name are discovered recursively. AFIRMA for truthy assert, ASSUNTO for equality.

Colored output with pass/fail, execution time, exit code 1 on failure (CI/CD ready).

Output
  PASS sum of two numbers
  PASS multiplication
  FAIL division by zero

  2 passed  1 failed  0.01s

LSP — Language Server Protocol

Autocomplete, real-time errors, hover and go-to-definition for any compatible editor.

Start the server with xs lsp and connect your editor. Communication via stdin/stdout using JSON-RPC.

Bash
xs lsp

Neovim

Lua
vim.api.nvim_create_autocmd("FileType", {
  pattern = "xs",
  callback = function()
    vim.lsp.start({
      name = "xanascript",
      cmd = { "xs", "lsp" },
    })
  end,
})
Real-time diagnostics
Autocomplete for keywords + built-ins
Hover with documentation
Go-to-definition

VS Code

The vscode-xs/ extension already integrates LSP automatically when opening a .xs file.

Ctrl+Alt+XRun
Ctrl+Alt+BBuild
Ctrl+Shift+FFormat

Rust-Style Errors

Highlighted source code, arrow to exact location, hint and help with fix suggestions.

XS
CRIA x = 10
CRIA y = z    // z was not defined
Error
ERROR: Variable `z` was not defined
Code: E002

 --> input.xs:2:11

   1 | CRIA x = 10
 > 2 | CRIA y = z
     |          ^

Hint: Forgot to declare "z" with CRIA?
Help: Add `CRIA z = value` before using it
CodeMeaning
E001Unexpected token
E002Variable not defined
E003Not a function
E004Incompatible type
E005Invalid syntax
E100HTTP failure
E999Internal error

XanaScript vs JavaScript / TypeScript

A language that delivers what JS/TS promise — and much more.

FeatureXanaScriptJavaScriptTypeScript
PT-BR SyntaxYesNoNo
Direct Wasm compilationYesEmscriptenAssemblyScript
Built-in ORMYesNoNo
Compile-time MacrosYesNoNo
Pattern MatchingYesNoNo
Loop UnrollingYesNoNo
Auto TypedArraysYesNoNo
Integer Math HintsYesNoNo
Constant FoldingYesNoNo
Rust-Style ErrorsYesNoNo
LSPYesNoYes
Native Test RunnerYesNoNo
Native Task RunnerYesNoNo
Classes/OOPYesYesYes
Template StringsYesYesYes
Complete CLI20+ cmdNode.jstsc
Hot ReloadYesnodemonts-node
Standalone BinaryYespkg/bunpkg/bun
Bytecode VMYesNoNo
Native Built-insYesNoNo

Architecture

How Portuguese code becomes high-performance executables.

.xs Code
Lexer
lexer.js
Parser
parser.js
Optimizer
opt.js
↙ ↘
Runtime (interpreter)
and
Codegen
codegen.js (JS)
codegen_opt.js (JS++)
codegen_wasm.js (WAT)
wasm_binary.js (.wasm)

Roadmap

What we have implemented and what is coming next.

Implemented

Lexer + Parser + AST (loc tracking)
Rust-style errors (code + arrow + hint)
Compile-time macros (MACRO)
Built-in ORM (TABELA -> CRUD)
LSP (autocomplete, hover, go-to-def)
Test runner (TESTE, AFIRMA, ASSUNTO)
Task runner (TAREFA)
Docs generator (xs docs)
Direct Wasm binary emitter
VS Code Extension with LSP
Standalone native CLI (bun --compile)
Classes/OOP (CLASSE, HERDA, ISTO)
Pattern Matching (COMBINA)
Template Strings + Try/Catch
Modules (IMPORTA, EXPORTA)
Built-in HTTP server
Bytecode VM (26 opcodes)
Package manager

Coming Soon

Complete source maps (VLQ)
Classes with super()
Pattern matching with guards
Hygienic macros
Publish VS Code Extension on Marketplace
Debugger (step, breakpoints)