A programming language with exclusive features: regex engine, query system, actors, macros, advanced data structures, type system, and custom operators.
# Global (recommended)
npm i -g nuxscript-lib
# Local
npm install nuxscript-lib
# Usage
nuxscript run <file.nux>
# or
nux run <file.nux>Introspecção de tipos, funções, structs e enums em runtime.
| Function | Description |
|---|---|
reflect(target) |
Get metadata of a function, struct, or enum |
reflect_type(val) |
Get type info of a value |
reflect_fn(fn) |
Get function metadata (name, params, arity) |
reflect_struct(obj) |
Get struct definition with fields |
reflect_enum(variant) |
Get enum variant info |
get_type(val) |
Get type: 'function', 'struct', 'enum', 'object', etc. |
type_of(val) |
Alias for get_type |
is_type(val, expected) |
Check if value is of expected type |
get_meta(fn) |
Get metadata attached to a function |
set_meta(fn, meta) |
Attach metadata to a function |
fn add(a :: Int, b :: Int) -> Int
a + b
end
let info = reflect(add)
print(info.name) # "add"
print(info.arity) # 2
print(info.params) # ["a", "b"]
Converte AST nodes para código nuxScript.
| Function | Description |
|---|---|
generate(node) |
Convert AST node to nuxScript code |
pretty_print(node) |
Format code with indentation |
ast_to_code(ast) |
Convert full AST to code |
let node = ast_node("BinaryExpr", {
op: "+",
left: ast_node("NumberLiteral", {value: 1}),
right: ast_node("NumberLiteral", {value: 2})
})
print(generate(node)) # "1 + 2"
Analisa código JavaScript externo.
| Function | Description |
|---|---|
parse_js(code) |
Parse JavaScript to AST |
tokenize_js(code) |
Tokenize JavaScript |
analyze_js(code) |
Full analysis (functions, classes, etc.) |
let code = "const x = 1; function hello() { return x; }"
let analysis = analyze_js(code)
print(analysis.functions) # ["hello"]
print(analysis.classes) # []
print(analysis.statCount) # 2
Cria nós AST manualmente.
| Function | Description |
|---|---|
ast_node(type, props) |
Create an AST node |
let id = ast_node("Identifier", {name: "foo"})
let num = ast_node("NumberLiteral", {value: 42})
let bin = ast_node("BinaryExpr", {op: "+", left: id, right: num})
# Output
print(...) # Print to console
# Types
type(val) # Get typeof
isOk(val) # Check Result::Ok
isErr(val) # Check Result::Err
isSome(val) # Check Option::Some
isNone(val) # Check Option::None
# Collections
len(a) # Length of array/string
push(arr, val) # Push to array
pop(arr) # Pop from array
range(n) # Create 0..n-1 range
# Option/Result
Ok(val) # Create Result::Ok
Err(val) # Create Result::Err
Some(val) # Create Option::Some
None() # Create Option::None
# Math (via math namespace)
math.abs(n)
math.floor(n)
math.ceil(n)
math.round(n)
math.sqrt(n)
math.min(...args)
math.max(...args)
math.pow(base, exp)
math.random()
math.sin(n)
math.cos(n)
math.log(n)
math.exp(n)
# List operations (via list namespace)
list.length(l)
list.isEmpty(l)
list.contains(l, x)
list.indexOf(l, x)
list.push(l, x)
list.pop(l)
list.slice(l, start, end)
list.reverse(l)
list.join(l, sep)
list.sum(l)
list.product(l)
list.sort(l)
list.map(fn)
list.filter(fn)
list.reduce(init, fn)
list.find(l, fn)
list.some(l, fn)
list.every(l, fn)
# String operations (via string namespace)
string.length(s)
string.upper(s)
string.lower(s)
string.trim(s)
string.includes(s, sub)
string.startsWith(s, prefix)
string.endsWith(s, suffix)
string.slice(s, start, end)
string.split(s, sep)
string.replace(s, old, new)
string.concat(...args)
# Map operations (via map namespace)
map.keys(m)
map.values(m)
map.entries(m)
map.hasKey(m, k)
map.merge(a, b)
map.size(m)
# IO
readFile(path)
writeFile(path, content)
# Fiber support
fiber_create(fn, constants)
resume(fiberRef)
fibers
# Package Loader (Package Manager)
pkg_install(name, version) # Install a package (version defaults to "latest")
pkg_list() # List installed packages
pkg_remove(name) # Remove a package
let x = 10 # immutable
let! x = 10 # mutable
var x = 10 # mutable (alias for let!)
const MAX = 100 # compile-time constant
::Int # type annotation
::String
::?String # Option[String]
::Result[Int, Err] # Result type
::List[::Int] # generic container
fn add(a :: Int, b :: Int) -> Int
a + b
end
# Anonymous function
let add = fn(a, b) -> a + b
struct Point
x :: Int
y :: Int
end
enum Shape
Circle(radius :: Int)
Rectangle(width :: Int, height :: Int)
Empty
end
match shape
Circle(r) -> "circle with r={r}"
Rectangle(w, h) -> "rect {w}x{h}"
Empty -> "nothing"
end
users
|> filter(.active == true)
|> map(.name)
|> join(", ")
if x > 10
"big"
else if x > 5
"medium"
else
"small"
end
for item in list
print(item)
end
while running
tick()
end
let gen = fiber {
yield 1
yield 2
yield 3
}
match resume(gen)
{status: "running", value: v} -> print("yielded: {v}")
{status: "finished", value: v} -> print("done: {v}")
end
nux run <file> # Run program
nux typecheck <file> # Check types without running
nux check <file> # Type check + run
nux ast <file> # Print AST
nux tokens <file> # Print tokens
nux pkg <action> # Package manager (install, list, remove)
nux init <name> # Initialize a new nuxScript projectnuxScript uses a nuxpackage.json file (similar to Node.js' package.json) to define project metadata, dependencies, and scripts.
Example nuxpackage.json:
{
"name": "my-project",
"version": "0.1.0",
"main": "main.nux",
"dependencies": {}
}See SPEC.md for full language specification.
- npm: https://npmjs.com/package/nuxscript-lib
- GitHub: https://github.com/NyxMindCorp/nuxScript
- Documentation: https://nux-script-docs.vercel.app/
MIT