Expand description
Iteration-related Tokel Transformers.
§Available Transformers
| Transformer | Argument Type | Description |
|---|---|---|
Reverse | syn::parse::Nothing | Reverses the sequence of token trees. |
Intersperse | TokenTree | Inserts a token-tree between each token-tree in the input. |
PushLeft | TokenStream | Prepends a token stream to the input. |
PushRight | TokenStream | Appends a token stream to the input. |
PopLeft | syn::parse::Nothing | Removes the first token tree from the stream. |
PopRight | syn::parse::Nothing | Removes the last token tree from the stream. |
Take | syn::LitInt | Keeps only the first N tokens from the stream. |
Skip | syn::LitInt | Discards the first N tokens from the stream. |
Repeat | syn::LitInt | Duplicates the input stream N times. |
Count | syn::parse::Nothing | Emits the number of token trees present in the stream. |
Sequence | SequenceRange | Generates a sequence of integers based on a provided range. |
§Argument Types
syn::parse::Nothing: No argument required.TokenTree: A single token tree (e.g., a punctuation, identifier, etc.).TokenStream: A sequence of token trees.syn::LitInt: An integer literal (e.g.,[[ 3 ]]).SequenceRange: A Rust range literal (e.g.,[[ 1..=3 ]]).
§Examples
[< a b c >]:reverse->c b a[< a b c >]:intersperse[[,]]->a , b , c[< b c >]:push_left[[a]]->a b c[< a b c >]:pop_right->a b[< a b c >]:take[[2]]->a b[< a b c >]:skip[[1]]->b c[< a b >]:repeat[[3]]->a b a b a b[< a b c >]:count->3[< >]:sequence[[ 1..=3 ]]->1 2 3
- Transformers can be nested or composed by evaluating other transformers inside arguments:
[< a b c >]:intersperse[[[< x y >]:reverse]]->a y x b y x c[< a b c >]:push_left[[[< x y >]:reverse]]->y x a b c[< a b c >]:push_right[[[< d e >]:take[[1]]]]->a b c d[< 1 2 3 >]:take[[[< 2 1 >]:reverse:take[[1]]]]->1 2[< a b c >]:repeat[[[< 2 1 >]:count]]->a b c a b c[< >]:sequence[[[< 1 4 >]:reverse:take[[1]]..4]]->3 4 5 6
Structs§
- Count
- Emits the number of token trees present in the stream.
- Intersperse
- Inserts the provided token-tree in between each token-tree in the input.
- PopLeft
- Removes the first token tree from the stream.
- PopRight
- Removes the last token tree from the stream (useful for trailing commas or other garbage).
- Push
Left - Pushes the provided token stream to the start (left) of the input token stream.
- Push
Right - Appends the provided token stream to the end (right) of the input token stream.
- Repeat
- Duplicates the input stream
Ntimes. - Reverse
- Reverses the sequence of token trees in the stream.
- Sequence
- Generates a sequence of integers based on a provided range.
- Skip
- Discards the first
Ntokens from the stream. - Take
- Keeps only the first
Ntokens from the stream.
Enums§
- Sequence
Range - The range argument of a
Sequencepass.
Functions§
- register
- Inserts all
iter-relatedTransformers into the specifiedRegistry.