# The Skode Skript Language — Reference

Skode Skript is an English-like automation language. One design rule governs
everything: **if you can say it, you can probably write it.**

## 1 · Syntax

The grammar in five lines:

- **Indentation is structure** (like Python — no braces, no `end`). Two spaces
  per level; tabs count as two.
- **One statement per line.** Chain small actions with ` and `.
- **`# comments`** run to the end of the line (never inside a string).
- **Strings** use `"double"` or `'single'` quotes, keep their emoji, and
  interpolate `{field}` names.
- **Case-insensitive keywords**, order-free top level: `when` rules and
  `to` function definitions can appear in any order.

Formal grammar (EBNF-ish):

```
program    = { rule | function | statement } ;
rule       = "when" event-phrase NEWLINE INDENT block DEDENT ;
function   = "to" name-phrase NEWLINE INDENT block DEDENT ;
block      = { statement } ;
statement  = action { "and" action } | if | loop ;
if         = "if" condition ["then"] block ["otherwise" block] ;
loop       = "repeat" NUMBER "times" block
           | ["repeat"] "for each" NAME "in" expr block
           | ["repeat"] "while" condition block ;
action     = built-in-action | name-phrase (* your function *) ;
expr       = sum { "," sum } (* comma makes a list *) ;
sum        = prod { ("+"|"-") prod } ;
prod       = value { ("*"|"/") value } ;
value      = STRING | NUMBER | "true" | "false" | FIELD ;
```

## 2 · Variables

`set` creates or changes a named container. Variables share one namespace
with the event's fields — `name`, `budget`, and your own `counter` all read
the same way.

```
set counter to 0
set counter to counter + 1
increase counter by 5        # or: decrease … by …, add 3 to counter
set greeting to "Hi " + name
```

An unset name is just a word — `set plan to pro` stores the string `"pro"`.

## 3 · Data Types

| Type | Literal | Notes |
| --- | --- | --- |
| number | `42` · `3.5` · `-1` | `+ - * /` with usual precedence (spaces around operators) |
| string | `"hello 👋"` | `+` concatenates; `{field}` interpolates |
| boolean | `true` · `false` | `if vip is true then …` |
| list | `"a", "b", "c"` | commas build a list; `add "d" to mylist` appends |

## 4 · Control Structures

```
if score is hot then          # conditions: is · is not · is above/below N
  assign to "Maya"            #             is at least N · contains "x"
otherwise
  add tag "nurture"

repeat 3 times                # count loop
  send email "ping"

for each ch in channels      # iterate a list, binds `ch`
  send email "via {ch}"

while c is below 5            # condition loop — capped at 1000
  increase c by 1             # iterations, so a typo can't hang Skode

stop                          # halt the whole skript
```

## 5 · Functions

Define a reusable block with `to <name>` at the top level; call it by
writing its name as a plain sentence. Functions see the same variables and
event fields as the rest of the skript, can call each other, and can be
defined before or after their callers.

```
when a new lead arrives
  score it with ai
  if score is hot then
    welcome the lead

to welcome the lead
  reply on whatsapp "Welcome {name}! 👋"
  add tag "welcomed"
```

Recursion deeper than 16 levels is stopped with an error — in an automation
language that's almost always an accident.

## 6 · Built-in actions

`score it with ai` · `assign to "Name"` · `reply on <channel> "…"` ·
`send <channel> [to "addr"] "…"` · `add tag "…"` · `set x to expr` ·
`add expr to x` · `increase/decrease x by expr` · `wait N minutes` ·
`create task "…" [for "Name"]` · `log "…"` · `stop`

Channels: whatsapp · email · sms · instagram · webchat · slack.
Events: `a new lead arrives` · `a form is submitted` · `a message arrives` ·
`an invoice is paid` · `a deal is won` · `when "custom.event"`.

## 7 · Errors

Every error carries the line number and speaks the language back to you:

```
line 2: I don't understand "frobnicate it".
  Things I know: score it with ai · assign to "Name" · …
  Your functions: welcome the lead
```
