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

Name
Arguments
Returns

rule

  • regex: String

  • render: StyledTextBuilder.(MatchResult, Context: Any)

Syntakts.Builder

rule

  • regex: Regex

  • render: StyledTextBuilder.(MatchResult, Context: Any)

Syntakts.Builder

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

More advanced rules

You can use addRule to add more advanced rules

Name
Arguments
Returns

addRule

  • rule: Rule

Syntakts.Builder

addRule

  • regex: String

  • parse: ParseRule

Syntakts.Builder

addRule

  • regex: Regex

  • parse: ParseRule

Syntakts.Builder

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

Last updated