Minimal examples of every construct. Use this as a quick reference cheat sheet.
snippet id="math.add" kind="fn"
signature
fn name="add"
param name="a" type="Int"
param name="b" type="Int"
returns type="Int"
end
end
body
step id="s1" kind="compute"
op=add
input var="a"
input var="b"
as="result"
end
step id="s2" kind="return"
from="result"
as="_"
end
end
end
snippet id="types.Point" kind="struct"
signature
struct name="Point"
field name="x" type="Int"
field name="y" type="Int"
end
end
end
snippet id="types.Status" kind="enum"
signature
enum name="Status"
variant name="Pending"
variant name="Active"
variant name="Completed"
end
end
end
snippet id="types.Result" kind="enum"
signature
enum name="Result"
variant name="Ok"
field name="value" type="Int"
end
variant name="Err"
field name="message" type="String"
end
end
end
end
snippet id="db.main" kind="database"
metadata
dialect="postgres"
connection="env:DATABASE_URL"
end
schema
table name="users"
field name="id" type="Int" primary_key=true
field name="email" type="String"
end
end
end
snippet id="http.get" kind="extern"
effects
effect network
end
signature
fn name="get"
param name="url" type="String"
returns union
type="Response"
type="HttpError"
end
end
end
metadata
contract="axios.get@1"
end
end
snippet id="docs.intro" kind="data"
content
"""
Introduction to the system.
"""
end
relations
rel to="auth.login" type=describes
end
end
effects
effect database
effect network
effect console
end
effects
effect filesystem(path="/data")
effect network(host="api.example.com")
end
requires
req id="R-001"
text "Must validate input"
priority high
status approved
end
end
signature
fn name="process"
param name="input" type="String"
param name="options" type="Options" optional
returns type="Result"
end
end
signature
fn name="find"
param name="id" type="Int"
returns union
type="User"
type="NotFoundError"
type="DbError"
end
end
end
signature
fn name="list_all"
returns collection of="User"
end
end
tests
test id="T-001" kind="unit" covers="R-001"
step id="t1" kind="call"
fn="validate"
arg name="input" lit="test"
as="result"
end
step id="t2" kind="call"
fn="assert_true"
arg name="value" from="result"
as="_"
end
end
end
metadata
author="system"
created="2024-01-15"
confidence=0.95
cost_hint=moderate
latency_hint=fast
tags=["auth", "core"]
end
relations
rel to="docs.overview" type=describes
rel from="auth.login" type=implemented_by
rel to="types.User" type=depends_on
end
step id="s1" kind="compute"
op=add
input var="x"
input var="y"
as="sum"
end
step id="s1" kind="compute"
op=not
input var="flag"
as="negated"
end
step id="s1" kind="call"
fn="validate"
arg name="input" from="data"
as="is_valid"
end
step id="s1" kind="call"
tool="http_client"
arg name="url" from="endpoint"
as="response"
end
step id="s1" kind="call"
fn="parse"
arg name="s" from="input"
as="parsed"
handle
case type="ParseError"
step id="s1a" kind="bind"
lit=0
as="parsed"
end
end
end
end
step id="s1" kind="bind"
from="source"
as="alias"
end
step id="s1" kind="bind"
lit=42
as="constant"
end
step id="s1" kind="bind"
mut
lit=0
as="counter"
end
step id="s1" kind="return"
from="result"
as="_"
end
step id="s1" kind="return"
lit="success"
as="_"
end
step id="s1" kind="return"
struct type="Point"
field name="x" from="x_val"
field name="y" lit=0
end
as="_"
end
step id="s1" kind="return"
variant type="Result::Err"
field name="message" lit="failed"
end
as="_"
end
step id="s1" kind="if"
condition="is_valid"
then
step id="s1a" kind="return"
lit="valid"
as="_"
end
end
as="_"
end
step id="s1" kind="if"
condition="flag"
then
step id="s1a" kind="bind"
lit="yes"
as="result"
end
end
else
step id="s1b" kind="bind"
lit="no"
as="result"
end
end
as="_"
end
step id="s1" kind="match"
on="option"
case variant type="Some" bindings=("value")
step id="s1a" kind="return"
from="value"
as="_"
end
end
case variant type="None"
step id="s1b" kind="return"
lit=0
as="_"
end
end
as="_"
end
step id="s1" kind="match"
on="code"
case literal=200
step id="s1a" kind="bind"
lit="ok"
as="status"
end
end
case literal=404
step id="s1b" kind="bind"
lit="not found"
as="status"
end
end
case wildcard
step id="s1c" kind="bind"
lit="error"
as="status"
end
end
as="_"
end
step id="s1" kind="for"
var="item" in="items"
step id="s1a" kind="call"
fn="process"
arg name="x" from="item"
as="processed"
end
as="results"
end
step id="s1" kind="query"
target="project"
select all
from="functions"
where
equals field="module" lit="auth"
end
as="auth_fns"
end
step id="s1" kind="query"
dialect="postgres"
target="app_db"
body
SELECT * FROM users WHERE id = :id
end
params
param name="id" from="user_id"
end
returns type="User"
as="user"
end
step id="s1" kind="insert"
into="project.nodes"
set field="name" from="name"
set field="value" lit=0
as="new_node"
end
step id="s1" kind="update"
target="project.nodes"
set field="value" from="new_value"
where
equals field="id" var="node_id"
end
as="updated"
end
step id="s1" kind="delete"
from="project.nodes"
where
equals field="id" var="node_id"
end
as="_"
end
step id="s1" kind="transaction"
isolation=serializable
step id="s1a" kind="insert"
into="orders"
set field="total" from="total"
as="order"
end
step id="s1b" kind="update"
target="inventory"
set field="quantity" from="new_qty"
where
equals field="product_id" var="pid"
end
as="_"
end
as="tx_result"
end
step id="s1" kind="traverse"
target="project"
from="docs.root"
follow type=contains
depth=unbounded
direction=outgoing
as="all_children"
end
op=add input var="a" input var="b" // a + b
op=sub input var="a" input var="b" // a - b
op=mul input var="a" input var="b" // a * b
op=div input var="a" input var="b" // a / b
op=mod input var="a" input var="b" // a % b
op=equals input var="a" input var="b" // a == b
op=not_equals input var="a" input var="b" // a != b
op=less input var="a" input var="b" // a < b
op=greater input var="a" input var="b" // a > b
op=less_eq input var="a" input var="b" // a <= b
op=greater_eq input var="a" input var="b" // a >= b
op=and input var="a" input var="b" // a && b
op=or input var="a" input var="b" // a || b
op=not input var="a" // !a
op=concat input var="a" input var="b" // a + b (string)
op=contains input var="s" input var="sub" // s.contains(sub)
op=neg input var="x" // -x
input var="x"
input lit=42
input lit="hello"
input lit=true
input lit=none
input field="name" of="user"
arg name="id" from="user_id"
arg name="limit" lit=10
where
equals field="status" lit="active"
end
where
equals field="id" var="target_id"
end
where
and
equals field="active" lit=true
greater field="age" lit=18
end
end
where
or
equals field="role" lit="admin"
equals field="role" lit="moderator"
end
end
where
not equals field="deleted" lit=true
end
where
equals field="deleted_at" lit=none
end
type="Int"
type="String"
type="Bool"
type="User" optional
type="Int?"
collection of="User"
type="Int[]"
type="List<User>"
type="Map<String, Int>"
type="module::TypeName"
lit=42
lit=-1
lit=3.14
lit="hello"
lit="with \"escapes\""
lit=true
lit=false
lit=none
lit=[1, 2, 3]
lit=["a", "b", "c"]
lit={"key": "value", "count": 42}