Skip to main content

Module iter

Module iter 

Source
Expand description

Iteration-related Tokel Transformers.

§Available Transformers

TransformerArgument TypeDescription
Reversesyn::parse::NothingReverses the sequence of token trees.
IntersperseTokenTreeInserts a token-tree between each token-tree in the input.
PushLeftTokenStreamPrepends a token stream to the input.
PushRightTokenStreamAppends a token stream to the input.
PopLeftsyn::parse::NothingRemoves the first token tree from the stream.
PopRightsyn::parse::NothingRemoves the last token tree from the stream.
Takesyn::LitIntKeeps only the first N tokens from the stream.
Skipsyn::LitIntDiscards the first N tokens from the stream.
Repeatsyn::LitIntDuplicates the input stream N times.
Countsyn::parse::NothingEmits the number of token trees present in the stream.
SequenceSequenceRangeGenerates a sequence of integers based on a provided range.

§Argument Types

§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).
PushLeft
Pushes the provided token stream to the start (left) of the input token stream.
PushRight
Appends the provided token stream to the end (right) of the input token stream.
Repeat
Duplicates the input stream N times.
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 N tokens from the stream.
Take
Keeps only the first N tokens from the stream.

Enums§

SequenceRange
The range argument of a Sequence pass.

Functions§

register
Inserts all iter-related Transformers into the specified Registry.