You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/api/syntax/writing-syntax.md
+47-45Lines changed: 47 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,23 @@ sidebar:
4
4
order: 5
5
5
---
6
6
7
-
## SyntaxInfos
8
-
9
-
In Skript, every syntax is defined by a [SyntaxInfo](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/registration/SyntaxInfo.java)
10
-
that describes the properties of that syntax.
11
-
12
-
### Creating SyntaxInfos
13
-
Skript provides a standard implementation and builder for SyntaxInfos.
14
-
A new builder can be created by using the `builder(Class)` method on SyntaxInfo.
15
-
It takes one parameter: the class implementing the syntax.
16
-
As an example, let's start by creating a new builder for a SyntaxInfo:
7
+
## Syntax infos
8
+
In Skript, every syntax is defined by a syntax info that describes the properties of that syntax.
9
+
A syntax info is described by the [SyntaxInfo](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/registration/SyntaxInfo.java) interface.
10
+
11
+
### Creating syntax infos
12
+
Skript provides a standard implementation and builder for creating syntax infos.
13
+
A new builder can be created by using the `builder(Class)` method from the SyntaxInfo interface.
14
+
It takes one parameter: the Class implementing the syntax.
15
+
As an example, let's start by creating a new builder for a syntax info:
17
16
```java
18
17
var builder =SyntaxInfo.builder(MySyntax.class);
19
18
```
20
-
We recommend using `var` for SyntaxInfo builders to simplify generics handling.
19
+
We recommend using `var` for syntax info builders to simplify generics handling.
21
20
22
21
### Patterns
23
22
Every syntax is made up of patterns that must be matched for your syntax implementation to be used.
24
-
They can be accessed by calling the `patterns` method on a SyntaxInfo.
23
+
They can be accessed by calling the `patterns` method on a syntax info.
25
24
26
25
The simplest pattern is made up of literal characters:
27
26
```text
@@ -129,8 +128,8 @@ The pattern options summarized are:
129
128
- Use angle brackets (`<expr>`) for regular expressions
130
129
- Use colons (`tag:pattern`) for parse tags
131
130
132
-
#### Adding patterns to a SyntaxInfo
133
-
We can add patterns to a SyntaxInfo builder by using any of the following methods:
131
+
#### Adding patterns to a syntax info
132
+
When creating a syntax info, patterns can be added by using the following methods from the SyntaxInfo.Builder interface:
134
133
-`addPattern(String)`
135
134
-`addPatterns(String[])`
136
135
-`addPatterns(Collection)`
@@ -144,12 +143,12 @@ builder.addPattern("(stop|shutdown) [the] server [in %-timespan%]");
144
143
```
145
144
146
145
### Type
147
-
Every SyntaxInfo has a class that provides the implementation of the syntax it describes.
148
-
It can be obtained by calling the `type` method on a SyntaxInfo.
146
+
Every syntax info has a class that provides the implementation of the syntax it describes.
147
+
It can be obtained by calling the `type` method of a SyntaxInfo.
149
148
150
149
#### Creating new instances
151
-
When Skript matches a SyntaxInfo during the parsing process, it needs to instantiate the class providing the implementation of the syntax.
152
-
Skript uses the `instance` method of a SyntaxInfo for this instantiation.
150
+
When Skript matches a syntax info during the parsing process, it needs to instantiate the class providing the implementation of the syntax.
151
+
Skript invokes the `instance` method of a SyntaxInfo for this instantiation.
153
152
154
153
By default, Skript uses reflection to instantiate new instances.
155
154
This requires that the class have a nullary (zero argument) constructor.
@@ -161,41 +160,41 @@ builder.supplier(MySyntax::new); // equivalent to: () -> new MySyntax()
161
160
```
162
161
163
162
### Priority
164
-
The priority of a SyntaxInfo dictates its position for matching during parsing.
165
-
That is, a collection of SyntaxInfoswill be sorted by their priority, and Skript will attempt to match each SyntaxInfo through order-based traversal.
163
+
The priority of a syntax info dictates its position for matching during parsing.
164
+
That is, a collection of syntax infos will be sorted by their priority, and Skript will attempt to match each syntax info through order-based traversal.
166
165
It can be obtained by calling the `priority` method on a SyntaxInfo.
167
166
168
-
There are three standard priorities used by Skript, available as constants on SyntaxInfo:
169
-
- `SIMPLE` -ForSyntaxInfos with patterns that only match simple text. That is, they do not contain any other expressions.
170
-
- `COMBINED` ForSyntaxInfos with patterns that contain other expressions.
171
-
- `PATTERN_MATCHES_EVERYTHING` ForSyntaxInfos with patterns that contain adjacent expressions.
167
+
There are three standard priorities used by Skript, available as constants on the SyntaxInfo interface:
168
+
- `SIMPLE` -Forsyntax infos with patterns that only match simple text. That is, they do not contain any other expressions.
169
+
- `COMBINED` Forsyntax infos with patterns that contain other expressions.
170
+
- `PATTERN_MATCHES_EVERYTHING` Forsyntax infos with patterns that contain adjacent expressions.
172
171
173
172
`SIMPLE` is the earliest priority, with `COMBINED` coming directly after, followed by `PATTERN_MATCHES_EVERYTHING`.
174
173
175
-
ThedefaultSyntaxInfobuilders will automatically assign a priority based on these criteria.
174
+
Thedefault builders will automatically assign a priority based on these criteria.
176
175
Thus, it is generally unnecessary to specify a priority.
177
-
However, if there is a need to override the automatic assignment, a priority can be specified by calling the `priority` method on a SyntaxInfobuilder, for example:
176
+
However, if there is a need to override the automatic assignment, a priority can be specified by calling the `priority` method on a builder, for example:
The [SyntaxRegistry](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/registration/SyntaxRegistry.java) is the central store of all registered SyntaxInfos.
194
+
## TheSyntaxRegistry
195
+
TheSyntaxRegistry, described by the [SyntaxRegistry](https://github.com/SkriptLang/Skript/blob/master/src/main/java/org/skriptlang/skript/registration/SyntaxRegistry.java) interface, is the central store of all registered syntax infos.
197
196
198
-
It can be accessed by calling the `syntaxRegistry` method on SkriptAddon.
197
+
It can be accessed by calling the `syntaxRegistry` method on a SkriptAddon.
0 commit comments