Exemplo n.º 1
0
func send(out chan processor.Token, major processor.TypeMajor, minor processor.TypeMinor, value string) {
	tok := processor.Token{}
	tok.Major = major
	tok.Minor = minor
	tok.Value = value
	out <- tok
}
Exemplo n.º 2
0
// Highlight is called once for every input file.
func Highlight(data []byte, out chan processor.Token) {
	tok := processor.Token{}
	tok.Major = processor.MAJOR_RAW
	tok.Minor = processor.MINOR_RAW
	tok.Value = string(data)
	out <- tok
	close(out)
}
Exemplo n.º 3
0
func Filter(in chan processor.Token, out chan processor.Token) {
	prev := processor.Token{}

	for {
		select {
		case x, ok := <-in:
			if x.Major == prev.Major && x.Minor == prev.Minor {
				prev.Value = prev.Value + x.Value
			} else {
				out <- prev
				prev = x
			}
			if !ok {
				out <- prev
				close(out)
				return
			}
		}
	}
}