# 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)
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://syntakts.wingio.xyz/using/defining-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
