> For the complete documentation index, see [llms.txt](https://syntakts.wingio.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://syntakts.wingio.xyz/using/defining-rules.md).

# Defining rules

The `syntakts` block is where you can define any custom or predefined rules.

### Declaring a rule

The simplest way to create a rule is with the `rule` function

<table><thead><tr><th width="94">Name</th><th width="495">Arguments</th><th>Returns</th></tr></thead><tbody><tr><td>rule</td><td><ul><li>regex: String</li><li>render: StyledTextBuilder.(MatchResult, Context: Any) </li></ul><p></p></td><td>Syntakts.Builder</td></tr><tr><td>rule</td><td><ul><li>regex: Regex</li><li>render: StyledTextBuilder.(MatchResult, Context: Any) </li></ul></td><td>Syntakts.Builder</td></tr></tbody></table>

{% code title="Ex." %}

```kotlin
rule("@([A-z]+)") { result, context ->
    append(result.value)
}
```

{% endcode %}

### More advanced rules

You can use `addRule` to add more advanced rules

| Name    | Arguments                                                | Returns          |
| ------- | -------------------------------------------------------- | ---------------- |
| addRule | <ul><li>rule: Rule</li></ul>                             | Syntakts.Builder |
| addRule | <ul><li>regex: String</li><li>parse: ParseRule</li></ul> | Syntakts.Builder |
| addRule | <ul><li>regex: Regex</li><li>parse: ParseRule</li></ul>  | Syntakts.Builder |

<pre class="language-kotlin"><code class="lang-kotlin">addRule(
    rule = Rule("@([A-z]+)") { result ->
        node { context ->
            append(result.value)
        }
    }
<strong>)
</strong></code></pre>

```kotlin
addRule("@([A-z]+)") { result ->
    node { context ->
        append(result.value)
    }
}
```
