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 |
|---|---|
and | Logical AND (keyword form) |
as | Alias in imports |
async | Mark a function as asynchronous |
await | Wait for an async result |
break | Exit a loop early |
browser | Define a browser block |
catch | Handle errors from a try block |
client | Deprecated alias for browser |
component | Declare a reactive UI component |
computed | Declare a derived reactive value |
continue | Skip to the next loop iteration |
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 |
field | Declare a form field inside a form block |
finally | Code that always runs after try/catch |
fn | Declare a function |
for | Iterate over a collection or range |
form | Declare a reactive form inside a browser/component scope |
from | Specify the module source in an import; receive from a channel in select |
group | Declare a field group inside a form block |
guard | Assert a condition or execute an else block |
if | Conditional branch |
impl | Implement methods or traits for a type |
import | Bring names from another module into scope |
in | Membership test; iteration target in for loops |
interface | Define a structural type contract |
is | Type-checking operator |
let | Reserved (hard error — destructure directly without a keyword) |
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) |
pub | Mark a declaration as public |
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 |
state | Declare a reactive state variable |
steps | Declare wizard steps inside a form block |
store | Declare a reactive store |
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) |
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 |
INFO
Several identifiers that appear keyword-like are actually contextual identifiers -- they are NOT reserved by the lexer and can be used as variable names outside their respective contexts. See Contextual Identifiers and Data Block Identifiers below.
Contextual Keywords (HTTP Methods)
These identifiers are recognized only within server blocks for route declarations. They are parsed as regular identifiers, not as keyword tokens:
| 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 |
Contextual Identifiers (Block Keywords)
The following identifiers are NOT reserved keywords. They are detected contextually by the plugin system at the top level only and can be used as variable names in other contexts:
| Identifier | Description |
|---|---|
test | Define a test block |
bench | Define a benchmark block |
security | Define a security policy block |
cli | Define a CLI tool block |
edge | Define an edge/serverless block |
concurrent | Define a structured concurrency block |
deploy | Define a deployment configuration block |
theme | Define a design token theme block |
data | Define a data block for sources, pipelines, and validation |
Contextual Identifiers (Concurrency)
These identifiers are recognized only within concurrent blocks or as prefix operators in concurrent contexts:
| Identifier | Description |
|---|---|
spawn | Launch a concurrent task inside a concurrent block |
select | Multiplex across channel operations |
Contextual Identifiers (Data Block)
These identifiers are recognized only inside data blocks:
| Identifier | Description |
|---|---|
ai | Declare an AI provider configuration (inside server blocks) |
pipeline | Declare a named transform chain in a data block |
source | Declare a data source in a data block |
validate | Declare validation rules for a type in a data block |
refresh | Set a refresh policy for a data source |
Contextual Identifiers (Styling)
| Identifier | Description |
|---|---|
style | Define a scoped CSS style block (consumed as a STYLE_BLOCK token by the lexer) |
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)
}concurrent
Defines a structured concurrency block. All spawned tasks within the block must complete (or be cancelled) before execution continues past it. Supports mode modifiers: cancel_on_error, first, and timeout(ms).
concurrent {
users = spawn fetch_users()
posts = spawn fetch_posts()
}
// users and posts are Result values
concurrent cancel_on_error {
a = spawn validate(input)
b = spawn check_permissions(user)
}
concurrent timeout(5000) {
data = spawn slow_operation()
}See the Concurrency guide for full details.
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. elif is the idiomatic Tova style. else if is also accepted by the parser.
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 = falsefield
Declares a form field inside a form block. Each field gets reactive value, error, and touched signals with optional validators.
form login {
field email: String = "" {
required("Email is required")
email("Must be valid")
}
}See Form Block for full documentation.
finally
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}")
}form
Declares a reactive form controller inside a browser {} or component scope. Supports fields, groups, arrays, wizard steps, and built-in validators.
form checkout {
field email: String = "" { required("Required") }
group shipping {
field street: String = "" { required("Required") }
}
on submit { server.placeOrder(checkout.values) }
}See Form Block for full documentation.
from
Specifies the module path in an import statement.
import { sqrt, PI } from "math"group
Declares a field group inside a form block. Groups namespace related fields and support conditional visibility with when.
form checkout {
group shipping {
field street: String = "" { required("Required") }
field city: String = "" { required("Required") }
}
group billing {
field sameAsShipping: Bool = true
group address when !sameAsShipping {
field street: String = "" { required("Required") }
}
}
}See Form Block for full documentation.
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 toString(self) -> String
}let
Reserved keyword that produces a compile-time hard error. Tova does not use let — destructure directly without any keyword:
// This will NOT compile:
// let { name, email } = user // Error: 'let' is not valid in Tova. For destructuring, use { name, email } = user directly
// let [first, ...rest] = items // Error: 'let' is not valid in Tova. For destructuring, use [first, ...rest] = items directly
// Destructure directly (no keyword needed):
{ name, email } = user
[first, ...rest] = items
(x, y) = pointWARNING
let is a hard error in Tova with a helpful message directing you to destructure directly. Use x = value for simple bindings, var x = value for mutable variables, and { a, b } = obj / [a, b] = list / (a, b) = pair for destructuring.
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 isEmpty(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 |> groupBy(.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)
}
}select
Multiplexes across multiple channel operations. Waits until one case is ready, then executes its body. Supports receive, send, timeout, and default cases.
select {
msg from ch1 => print("Got: {msg}")
ch2.send(value) => print("Sent")
timeout(5000) => print("Timed out")
_ => print("Nothing ready")
}See the Concurrency guide for full details.
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
}
}spawn
Launches a concurrent task inside a concurrent block. The spawned call returns Result<T, Error> -- success wraps in Ok, exceptions wrap in Err.
concurrent {
result = spawn compute(data)
spawn log_event("started") // fire-and-forget
}See the Concurrency guide for full details.
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}]
}
}steps
Declares wizard steps inside a form block. Each step references fields, groups, or arrays that must be valid before advancing.
form checkout {
field email: String = "" { required("Required") }
group shipping { /* ... */ }
group payment { /* ... */ }
steps {
step "Account" { email }
step "Shipping" { shipping }
step "Payment" { payment }
}
}See Form Block for full documentation.
test
Defines a test block with a description string and body containing assertions. Tests are discovered and run by tova test.
test "addition works" {
assertEq(1 + 1, 2)
}
test "string interpolation" {
name = "world"
assertEq("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 | Accepted, but prefer elif for idiomatic Tova style. |