Skip to content

Syntax patterns

Mwexim edited this page Dec 29, 2021 · 8 revisions

The real power of Skript comes from its intuitive design, mainly featuring the feature-rich syntax that feels really close to plain English. To achieve this, skript-parser has a lot of functionalities in place to create 'syntax patterns'. Each pattern can consist of multiple elements that interact with each other. The user will make the final decision on how he will use the different patterns in his code.

This means that the developer can create multiple possibilities, while the user can choose which to use and how to use it. Both parties are happy!

If you want to learn how the patterns are actually matched against each other, together with a briefer explanation of the different pattern elements, refer to 'Pattern matching'.

Creating syntax patterns

Developers can choose between multiple types of elements. These elements together will form the pattern. The user input will be matched, line by line, against the stored elements. Each element has its own strategy when matching. If a match fails, the parser moves on to the next pattern.

Text elements

Text elements consist of a plain text instance. The matched string must contain every character of this text instance, otherwise, the match will fail.

Suppose we have the following inputs with the pattern attacker:

attcker     # fail
attacker    # success

Optional groups

An optional group consists of a simple element, or multiple, that can be omitted if desired by the user. It usually serves as a way to give more variety to the syntax, though it can be used to add optional parameters. It is indicated by square brackets (ex: [optional]) around the optional elements.

Suppose we have the following inputs with the pattern [the] attacker:

the attacker    # success
attacker        # success
the attcker     # fail

As one can see, a popular use is the addition of optional definite and indefinite articles as a cosmetic feature to the code. Users writing an application can opt for the more English-friendly syntax with articles.

Choice groups

Choice groups are indicated by two parentheses, and each choice separated by a pipe | (ex: (choice|option)). When writing an application, either choice can be written. It also usually serves as a way to give more variety to the syntax.

Suppose we have the following inputs with the pattern [the] (attack|strike) damage:

the attack damage    # success
strike damage        # success
Clone this wiki locally