Source File
iterator.go
Belonging Package
github.com/alecthomas/chroma/v2
package chromaimport// An Iterator across tokens.//// EOF will be returned at the end of the Token stream.//// If an error occurs within an Iterator, it may propagate this in a panic. Formatters should recover.type Iterator func() Token// Tokens consumes all tokens from the iterator and returns them as a slice.func ( Iterator) () []Token {var []Tokenfor := (); != EOF; = () {= append(, )}return}// Concaterator concatenates tokens from a series of iterators.func ( ...Iterator) Iterator {return func() Token {for len() > 0 {:= [0]()if != EOF {return}= [1:]}return EOF}}// Literator converts a sequence of literal Tokens into an Iterator.func ( ...Token) Iterator {return func() Token {if len() == 0 {return EOF}:= [0]= [1:]return}}// SplitTokensIntoLines splits tokens containing newlines in two.func ( []Token) ( [][]Token) {var []Token // nolint: preallocfor , := range {for strings.Contains(.Value, "\n") {:= strings.SplitAfterN(.Value, "\n", 2)// Token becomes the tail..Value = [1]// Append the head to the line and flush the line.:= .Clone().Value = [0]= append(, )= append(, )= nil}= append(, )}if len() > 0 {= append(, )}// Strip empty trailing token line.if len() > 0 {:= [len()-1]if len() == 1 && [0].Value == "" {= [:len()-1]}}return}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |