Skip to content

Commit acc9f96

Browse files
Document parse marks
1 parent 06e9889 commit acc9f96

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/content/docs/api/syntax/writing-syntax.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ Parse tags are then applied to each choice, meaning it is equivalent to writing
119119
Note that there is a group surrounding the parse tag.
120120
For this feature to work, the parse tag must be empty, and surrounding putting the parse tag within a group ensures this is the case.
121121

122+
#### Parse marks
123+
124+
The parse mark is the simpler predecessor to the parse tag.
125+
While less commonly used today, it is still supported.
126+
Essentially, it is a numeric parse tag, as they are written in the same manner:
127+
```text
128+
(1:stop|shutdown) [the] server [in %-timespan%]
129+
```
130+
131+
When a pattern element with a parse mark is used, the parse mark value of the parse is updated.
132+
In the example above, when `stop` is used, the parse mark value will be `1`.
133+
134+
Unlike parse tags, there is only a single parse mark value when an entire pattern is parsed.
135+
So, what happens when multiple parse marks are reached?
136+
Their values are XORed.
137+
Consider the following example:
138+
```text
139+
(1:stop|shutdown) [the] server [2:and display an alert]
140+
```
141+
In this example, if `stop` is not used, but `and display an alert` is, the parse mark value will be `2`.
142+
However, if both are used, since the values are XORed, the parse mark value will be `3`.
143+
144+
In general, parse tags are recommended over parse marks for their superior readability, but parse marks are still supported for situations that warrant their usage.
145+
122146
#### Pattern options summarized
123147
The pattern options summarized are:
124148
- Use square brackets (`[the]`) for optional text
@@ -129,7 +153,7 @@ The pattern options summarized are:
129153
- Prefix with `-` to mark as nullable
130154
- Suffix with `@-1` or `@1` to force the time state
131155
- Use angle brackets (`<expr>`) for regular expressions
132-
- Use colons (`tag:pattern`) for parse tags
156+
- Use colons for parse tags (`tag:pattern`) and parse marks (`number:pattern`)
133157

134158
#### Adding patterns to a syntax info
135159
When creating a syntax info, patterns can be added by using the following methods from the SyntaxInfo.Builder interface:

0 commit comments

Comments
 (0)