The language uses a dynamic, C-style syntax with modern features, including function declarations with fn, getter properties with property, pipeline decorators and data chaining with |>, class-based OOP with multiple inheritance using < (inheriting implicitly from Object), structured exception handling with try/catch/throw, compound assignments, ternary expressions, Python-like bracket slicing, and list comprehensions.
Declarations
Variables & Multi-Assignment
Variables are declared with the var keyword and are dynamically typed. Kyro supports sequence destructuring, multi-variable declarations, and atomic variable swapping (a, b = b, a):
var x = 10.0;
var uninitialized; // Defaults to nil implicitly
// Multi-variable assignment and atomic swapping
var a, b = 1, 2;
a, b = b, a; // Swaps values! a is 2, b is 1
// List and Dictionary destructuring
var [first, second] = ["apple", "banana"];
var { name, role } = { "name": "bob", "role": "dev" };
Functions, Properties, and Pipeline Decorators
Functions are defined using the fn keyword, followed by a name, parameter list in parentheses, and a body block. Parameters can optionally define default fallback values or be passed using keyword arguments.
fn multiply(x, y = 2.0) {
return x * y;
}
// Call using positional arguments
multiply(2.0, 3.0); // 6
// Call relying on default parameter value for y
multiply(5.0); // 10
// Call using keyword arguments out of order
multiply(y = 4.0, x = 3.0); // 12
Functions can also be declared anonymously as closures (lambdas):
var double = fn(x) {
return x * 2.0;
};
echo double(5.0); // 10
Properties (Getters)
Properties are defined using the property keyword. They behave like functions but auto-evaluate on access without parentheses:
property version() {
return "1.0.0";
}
echo version; // Auto-executes getter! Output: 1.0.0
Pipeline Decorators & Data Piping (|>)
The pipeline operator |> passes the left-hand value as the first argument to the function on the right. It can be used for function decorators or data pipelines:
fn logger(func) {
return fn(x) {
echo "Executing function: " + func.__name__;
return func(x);
};
}
fn square(n) {
return n * n;
} |> logger;
echo square(5); // Logs "Executing function: square", outputs 25
// Data Pipeline Chaining
var result = 5 |> fn(x) { return x + 10; } |> fn(x) { return x * 2; };
echo result; // 30
Classes & Multiple Inheritance
Classes are declared with the class keyword and can inherit from one or multiple parent classes using < Parent1, Parent2 (defaulting to Object if omitted). Instances can dynamically attach fields at runtime, be made callable using __call__, or overload standard operators using magic methods (__add__, __getattribute__, __getitem__, etc.).
class Flyer {
fn fly(self) { return "flying high"; }
}
class Swimmer {
fn swim(self) { return "swimming fast"; }
}
// Multiple Inheritance
class Duck < Flyer, Swimmer {
fn __init__(self, name) {
self.name = name;
}
property sound(self) {
return "${self.name} says quack!";
}
}
fn main() {
var d = Duck("donald");
echo d.sound; // Accesses property without ()
echo d.fly(); // Inherited from Flyer
echo d.swim(); // Inherited from Swimmer
}
Statements & Expressions
Control Flow & Ternary Operator
Kyro supports standard control flow structures as well as inline ternary expressions (cond ? a : b):
// Ternary operator
var age = 20;
var status = age >= 18 ? "adult" : "minor";
echo status; // "adult"
// if/else
if (x > 10.0) {
echo "greater";
} else {
echo "less or equal";
}
// while loop
while (x > 0.0) {
x -= 1; // Compound subtraction
}
// standard for loop
for (var i = 0; i < 5.0; i += 1) {
echo i;
}
// for-in loop (supports Lists, Dicts, and Custom Iterators via __next__)
var fruits = ["apple", "banana"];
for (var fruit in fruits) {
echo fruit;
}
Compound Assignment Operators
Kyro supports in-place arithmetic modifications (+=, -=, *=, /=, %=):
var count = 10;
count += 5; // 15
count *= 2; // 30
Bracket Slicing & List Comprehensions
Kyro features Python-style list/string slicing ([start:end:step]) and list comprehensions:
// Python-like Bracket Slicing
var nums = [10, 20, 30, 40, 50];
echo nums[1:4]; // [20, 30, 40]
echo nums[::-1]; // [50, 40, 30, 20, 10] (Reversed!)
var text = "Hello World";
echo text[0:5]; // "Hello"
// List Comprehensions with optional conditional guards
var doubled_evens = [x * 2 for var x in range(0, 10) if x % 2 == 0];
echo doubled_evens; // [0, 4, 8, 12, 16]
Triple-Quote Multi-line Raw Strings
Multi-line raw string literals are written using triple quotes (""" ... """):
var query = """
SELECT id, username, email
FROM users
WHERE status = 'active';
""";
echo query;
Exception Handling
Exceptions are handled with try/catch blocks, and can be thrown with instantiated exception objects (ValueError, TypeError, AttributeError, IndexError) or strings:
try {
var value = list[10.0];
} catch (err) {
echo "failed: " + err.message;
}
throw ValueError("something went wrong");
For a quick overview of supported keywords, here is the updated TokenType enum.
#[rustfmt::skip]
#[derive(Debug, Clone, PartialEq)]
pub enum TokenType {
LeftParen, RightParen, LeftBrace, RightBrace,
LeftBracket, RightBracket, Colon, Question,
Comma, Dot, Minus, Plus, Semicolon, Slash, Star, Percent,
Bang, BangEqual, Equal, EqualEqual,
PlusEqual, MinusEqual, StarEqual, SlashEqual, PercentEqual,
Greater, GreaterEqual, Less, LessEqual,
Identifier, String, Number,
And, Class, Else, False, Fn, Property, For, If, Nil, Or,
Echo, Return, Super, This, True, Var, While,
Try, Catch, Throw,
Break, Continue,
In,
Ampersand, Pipe, PipeGreater, Caret, Tilde, LessLess, GreaterGreater,
Arrow,
Eof,
}