Keywords
This page lists every reserved keyword in the Tova language in alphabetical order. Each entry includes a brief description and a minimal code example.
Reserved Keywords
| Keyword | Description |
|---|---|
ai | Declare an AI provider configuration |
and | Logical AND (keyword form) |
as | Alias in imports |
async | Mark a function as asynchronous |
await | Wait for an async result |
bench | Define a benchmark block |
break | Exit a loop early |
catch | Handle errors from a try block |
browser | Define a browser block |
component | Declare a reactive UI component |
computed | Declare a derived reactive value |
continue | Skip to the next loop iteration |
data | Define a data block for sources, pipelines, and validation |
defer | Schedule code to run at scope exit |
derive | Auto-derive trait implementations for a type |
effect | Declare a reactive side effect |
elif | Chained conditional branch |
else | Fallback conditional branch |
export | Reserved keyword (use pub instead) |
extern | Declare an external (foreign) binding |
false | Boolean false literal |
finally | Code that always runs after try/catch |
fn | Declare a function |
for | Iterate over a collection or range |
from | Specify the module source in an import |
guard | Assert a condition or execute an else block |
if | Conditional branch |
impl | Implement methods or traits for a type |
is | Type-checking operator |
import | Bring names from another module into scope |
in | Membership test; iteration target in for loops |
interface | Define a structural type contract |
let | Destructuring binding |
loop | Infinite loop |
match | Pattern matching expression |
mut | Reserved (use var instead) |
nil | The absence-of-value literal |
not | Logical NOT (keyword form) |
or | Logical OR (keyword form) |
pipeline | Declare a named transform chain in a data block |
pub | Mark a declaration as public |
refresh | Set a refresh policy for a data source |
return | Explicit early return from a function |
route | Define an HTTP route in a server block |
server | Define a server-side block |
shared | Define a block shared between server and browser |
source | Declare a data source in a data block |
state | Declare a reactive state variable |
store | Declare a reactive store |
test | Define a test block |
trait | Define a named set of behaviors |
true | Boolean true literal |
try | Begin an error-handling block |
type | Declare a custom type (struct or ADT) |
validate | Declare validation rules for a type in a data block |
var | Declare a mutable variable |
when | Guard condition in for loops |
while | Loop while a condition is true |
with | Resource management with cleanup |
yield | Yield a value from a generator |
Contextual Keywords (HTTP Methods)
These identifiers are reserved only within server blocks for route declarations:
| Keyword | Description |
|---|---|
GET | HTTP GET method |
POST | HTTP POST method |
PUT | HTTP PUT method |
DELETE | HTTP DELETE method |
PATCH | HTTP PATCH method |
HEAD | HTTP HEAD method |
OPTIONS | HTTP OPTIONS method |
Keyword Details
ai
Declares an AI provider configuration inside a server block. Can be unnamed (default) or named for multiple providers.
server {
ai {
provider: "anthropic"
model: "claude-sonnet-4-20250514"
api_key: env("ANTHROPIC_API_KEY")
}
ai "gpt" {
provider: "openai"
model: "gpt-4o"
api_key: env("OPENAI_API_KEY")
}
answer = ai.ask("Hello")
other = gpt.ask("Hello")
}and
Logical AND operator. Short-circuits: the right operand is not evaluated if the left is falsy.
if is_valid and is_active {
process()
}as
Renames an import to a local alias.
import { readFile as read } from "fs"async
Marks a function as asynchronous. An async function returns a Promise.
async fn fetch_data(url) {
response = await fetch(url)
await response.json()
}await
Suspends execution until an asynchronous value resolves.
data = await fetch_data("/api/users")bench
Defines a benchmark block inside a test file. Used to measure execution time of a code snippet.
bench "array sorting" {
data = range(1000) |> shuffle()
sorted(data)
}break
Exits the nearest enclosing for or while loop immediately.
for item in items {
if item == target {
break
}
}catch
Handles errors thrown in a try block. The caught error is bound to an optional variable.
try {
data = parse(input)
} catch err {
log("Parse error: {err}")
}browser
Opens a browser block. Code inside is compiled only for the browser.
browser {
state count = 0
component Counter() {
<button on:click={fn() count += 1}>{count}</button>
}
}component
Declares a reactive UI component that renders JSX.
component Greeting(name) {
<h1>"Hello, {name}!"</h1>
}computed
Declares a derived value that automatically updates when its dependencies change.
state items = []
computed total = len(items)continue
Skips the remainder of the current loop iteration and proceeds to the next.
for i in 0..100 {
if i % 2 == 0 {
continue
}
print(i)
}data
Opens a data block for declaring sources, pipelines, validation rules, and refresh policies. The data {} block is a top-level block alongside shared, server, and browser.
data {
source users = read("users.csv")
pipeline active = users |> where(.active)
validate User { .email |> contains("@") }
refresh users every 15.minutes
}defer
Schedules an expression to run when the enclosing scope exits, regardless of how it exits.
fn process_file(path) {
file = open(path)
defer close(file)
read(file)
}derive
Automatically generates trait implementations for a type.
type Point {
x: Float
y: Float
} derive [Eq, Show, JSON]effect
Declares a reactive side effect that re-runs when its dependencies change.
state query = ""
effect {
results = search(query)
render(results)
}elif
A chained conditional branch. Tova uses elif, not else if.
if score >= 90 {
"A"
} elif score >= 80 {
"B"
} elif score >= 70 {
"C"
} else {
"F"
}else
The fallback branch of an if/elif chain or a for loop.
if condition {
handle_true()
} else {
handle_false()
}export
Reserved keyword. Use pub to make declarations accessible to other modules.
extern
Declares an external binding provided by the host environment.
extern fn console_log(msg)false
The boolean false literal.
is_done = falsefinally
Specifies a block that always executes after try/catch, whether or not an error occurred.
try {
data = load()
} catch err {
log(err)
} finally {
cleanup()
}fn
Declares a named function or an anonymous lambda.
fn add(a, b) {
a + b
}
double = fn(x) x * 2for
Iterates over a range or collection. Supports an optional second variable for key/index.
for item in items {
print(item)
}
for i, val in items {
print("{i}: {val}")
}from
Specifies the module path in an import statement.
import { sqrt, PI } from "math"guard
Asserts a condition. If the condition is false, the else block executes (typically returning or breaking).
fn process(input) {
guard input != nil else {
return Err("input is nil")
}
// continue with valid input
Ok(transform(input))
}if
Conditional branching. Can be used as a statement or an expression.
// As statement
if ready {
start()
}
// As expression
label = if count == 1 { "item" } else { "items" }is
Type-checking operator. Tests whether a value is of a given type or ADT variant at runtime. Can be negated with is not.
value = "hello"
value is String // true
value is Int // false
value is not Nil // true
// Works with ADT variants
result = Ok(42)
result is Ok // true
result is Err // falseimpl
Implements methods or trait conformance for a type.
impl Point {
fn distance(self, other) {
sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)
}
}import
Brings named exports from another module into the current scope.
import { map, filter, reduce } from "stdlib/collections"in
Tests membership or specifies the iteration target in a for loop.
if "admin" in roles { grant_access() }
for x in 0..10 { print(x) }interface
Defines a structural contract that types can implement.
interface Printable {
fn to_string(self) -> String
}let
Performs destructuring binding from a value.
let { name, email } = user
let [first, ...rest] = itemsWARNING
let is NOT used for simple variable declarations. Use x = value for simple bindings and var x = value for mutable variables.
loop
Creates an infinite loop that runs until explicitly terminated with break. Useful for polling, event loops, and retry patterns.
var attempts = 0
loop {
result = try_connect()
if result.isOk() {
break
}
attempts += 1
if attempts > 5 {
break
}
}Labels work with loop for nested loop control:
outer: loop {
inner: loop {
if done {
break outer
}
}
}match
Pattern matching expression. Exhaustive by design.
match result {
Ok(value) => print(value)
Err(msg) => print("Error: {msg}")
}mut
Reserved keyword that produces a compile-time error. Tova uses var for mutable variables instead.
// This will NOT compile:
// mut x = 10 // Error: 'mut' is not supported in Tova. Use 'var' for mutable variables
// Use 'var' instead:
var x = 10
x = 20 // OKnil
The absence-of-value literal, equivalent to JavaScript's null.
result = nilnot
Logical NOT operator (keyword form).
if not is_empty(list) {
process(list)
}or
Logical OR operator. Short-circuits: the right operand is not evaluated if the left is truthy.
name = input or "default"pipeline
Declares a named transform chain inside a data {} block. Pipelines can reference sources and other pipelines.
data {
source users = read("users.csv")
pipeline active = users |> where(.active)
pipeline summary = active |> group_by(.role) |> agg(count: count())
}pub
Marks a declaration as publicly visible.
pub fn api_handler(req) {
respond(200, "ok")
}refresh
Sets a refresh policy for a data source inside a data {} block. Supports interval-based or on-demand refresh.
data {
source rates = read("https://api.example.com/rates")
refresh rates every 1.hour
source orders = read("orders.csv")
refresh orders on_demand
}return
Explicitly returns a value from a function. Optional when the last expression is the return value.
fn find(items, target) {
for item in items {
if item == target {
return item
}
}
nil
}route
Defines an HTTP route handler inside a server block.
server {
route GET "/api/users" => {
users = db.query("SELECT * FROM users")
json(users)
}
}server
Opens a server-side block. Code inside is compiled only for the server.
server {
db { url: "postgres://localhost/mydb" }
route GET "/health" => "ok"
}shared
Opens a block whose code is available on both server and client.
shared {
type User {
name: String
email: String
}
}source
Declares a named data source inside a data {} block. Sources are lazily loaded and cached.
data {
source users = read("users.csv")
source config = read("config.json")
source users: Table<User> = read("users.csv") // with type annotation
}state
Declares a reactive state variable in a browser block or component.
state count = 0
state name = "world"store
Groups related reactive state, computed values, and methods.
store TodoStore {
state items = []
computed count = len(items)
fn add(text) {
items = [...items, {text: text, done: false}]
}
}test
Defines a test block with a description string and body containing assertions. Tests are discovered and run by tova test.
test "addition works" {
assert_eq(1 + 1, 2)
}
test "string interpolation" {
name = "world"
assert_eq("Hello, {name}!", "Hello, world!")
}trait
Defines a named set of behavior (similar to a typeclass or protocol).
trait Comparable {
fn compare(self, other) -> Int
}true
The boolean true literal.
is_ready = truetry
Begins an error-handling block. Must be followed by catch and optionally finally.
try {
data = parse(raw_input)
} catch err {
data = default_value
}type
Declares a custom type -- either a struct (product type) or an algebraic data type (sum type).
// Struct
type Point {
x: Float
y: Float
}
// ADT (sum type)
type Shape {
Circle(radius: Float)
Rectangle(width: Float, height: Float)
}validate
Declares validation rules for a type inside a data {} block. Each rule is a column predicate.
data {
validate User {
.email |> contains("@"),
.name |> len() > 0,
.age >= 0
}
}var
Declares a mutable variable with an initial value.
var counter = 0
counter += 1when
Guard condition in for loops. Filters elements before the loop body executes, acting as an inline filter.
for item in items when item.active {
process(item)
}
// Equivalent to:
for item in items {
if item.active {
process(item)
}
}while
Loops while a condition is true.
var i = 0
while i < 10 {
print(i)
i += 1
}with
Resource management statement. Opens a resource and guarantees cleanup when the block exits, similar to a try/finally pattern.
with open("data.txt") as file {
content = file.read()
process(content)
}
// file is automatically cleaned up hereyield
Yields a value from a generator function.
fn fibonacci() {
var a = 0
var b = 1
while true {
yield a
a, b = b, a + b
}
}Non-Keywords
The following are not keywords in Tova, even though they might be expected from other languages:
| Word | Status in Tova |
|---|---|
throw | Not a keyword. Tova uses Result/Option for error handling. |
class | Not a keyword. Use type for data types and impl for methods. |
this | Not a keyword. Use self in impl blocks (passed explicitly). |
else if | Not valid syntax. Use elif instead. |