language

Keywords

The language keywords and constructs, grouped by what they do.

Marreta keeps a small reserved set, and the rule is one sentence: namespaces are reserved, directives and vocabularies are contextual. Reserved words fall into two layers.

Layer 1, reserved. A reserved word can never be a variable. These are the infrastructure namespaces (db, doc, feature, cache, queue, topic, fs, json, base64, uuid, log, time, math, http_client), the env accessor, the type tokens (string, integer, float, boolean, instant, date, duration, interval), and the structural keywords grouped below.

Layer 2, contextual. A contextual word means something in one position and is free as a name everywhere else: the db: schema directive, the type-names list, decimal, and enum, the pipeline vocabulary (where, fetch, limit, order, and the rest on the control flow page), the scenario DSL (scenario, given, when, then), and the injected bindings (params, auth, payload).

Even a Layer 1 word is free in a name position: after a dot, as a map key, as a schema field name, as a named-argument name, or as a select column. It reads as that name there. It is blocked only as a binder (the left side of an assignment, a parameter, a task or schema name), where it raises a dedicated error.

marreta
# Free as a name
flags = { env: "prod", feature: "beta" }       # map keys
created = payload.date                          # a field after a dot
columns = db.events >> select(date, status) >> fetch   # a column

# Blocked as a binder
doc = 1   # error: 'doc' is a reserved word (the document database namespace); rename the variable.

A schema field named doc, feature, or env is allowed, because those are not directives. A field named db is not, because the db: directive already claims that line.

The structural keywords below are all Layer 1, grouped by what they do. Each links to the guide that teaches it in context.

Routes and responses

KeywordFormSummary
routeroute VERB "/path" [take payload as Schema]Declares an HTTP route.
replyreply STATUS [as Schema], bodyReturns an HTTP response, optionally shaped by a schema.
failfail STATUS, messageEnds the route with a chosen HTTP error.
requirerequire condition else fail ...Guards execution and fails when the condition is false.
allowallow expressionAuthorizes the request, returning 403 when false.
marreta
route POST "/items" take payload as NewItem
    require payload.name else fail 400, "name required"
    reply 201 as ItemView, { name: payload.name }

See Validate a request payload, Shape a response, and Secure your API.

Schemas and tasks

KeywordFormSummary
schemaschema Name (add db: table to persist)Declares a validation, contract, and table shape.
tasktask name(args)Declares a reusable unit of logic.
take ... astake payload as SchemaBinds and validates a request or message body.
exportexport schema / export taskMakes a schema or task available across files.
marreta
export schema NewItem
    name: string

task title_case(name)
    name.upper()

Errors

KeywordFormSummary
raiseraise message [if condition]Raises a runtime error (an uncaught one becomes a 500).
rescueexpr rescue fallbackRecovers from a fallible operation.
nacknack [requeue]Rejects a consumed message, optionally requeuing it.
marreta
data = raw >> json.parse() rescue { ok: false }

See Handle errors.

Messaging and persistence

KeywordFormSummary
on queue / on topicon queue "name" take msg [as Schema]Declares an async consumer or subscriber.
transactiontransaction (block)Runs the enclosed database operations atomically.
marreta
on queue "emails" take msg
    log.info("sending to #{msg.to}")

See Process work asynchronously with a queue and Make it event-driven.

Control flow and operators

Conditionals (if / else, match, while), pipelines (>>, *>>), boolean operators (and / or / not), and collection transforms (map / keep / skip, reduce) have their own page, with snippets: Control flow and operators.