func lexEscapedOpenMustache(l *Lexer) lexFunc {
	l.next()
	l.ignore()
	for l.peek() == '{' {
		l.next()
	}
	return lexContent
}
lexEscapedOpenMustache scans \{{
package lexer
import (
	"fmt"
	"regexp"
	"strings"
	"unicode"
	"unicode/utf8"
)
const (
	escapedEscapedOpenMustache  = "\\\\{{"
	escapedOpenMustache         = "\\{{"
	openMustache                = "{{"
	closeMustache               = "}}"
	closeStripMustache          = "~}}"
	closeUnescapedStripMustache = "}~}}"
)
const eof = -1
type lexFunc func(*Lexer) lexFunc
type Lexer struct {
	input    string      
	name     string      
	tokens   chan Token  
	nextFunc lexFunc     
	pos   int  
	line  int  
	width int  
	start int  
	closeComment *regexp.Regexp  
	rawBlock     bool            
}
var (
	lookheadChars        = `[\s` + regexp.QuoteMeta("=~}/)|") + `]`
	literalLookheadChars = `[\s` + regexp.QuoteMeta("~})") + `]`
	unallowedIDChars = " \n\t!\"#%&'()*+,./;<=>@[\\]^`{|}~"
	rID                  = regexp.MustCompile(`^[^` + regexp.QuoteMeta(unallowedIDChars) + `]+`)
	rDotID               = regexp.MustCompile(`^\.` + lookheadChars)
	rTrue                = regexp.MustCompile(`^true` + literalLookheadChars)
	rFalse               = regexp.MustCompile(`^false` + literalLookheadChars)
	rOpenRaw             = regexp.MustCompile(`^\{\{\{\{`)
	rCloseRaw            = regexp.MustCompile(`^\}\}\}\}`)
	rOpenEndRaw          = regexp.MustCompile(`^\{\{\{\{/`)
	rOpenEndRawLookAhead = regexp.MustCompile(`\{\{\{\{/`)
	rOpenUnescaped       = regexp.MustCompile(`^\{\{~?\{`)
	rCloseUnescaped      = regexp.MustCompile(`^\}~?\}\}`)
	rOpenBlock           = regexp.MustCompile(`^\{\{~?#`)
	rOpenEndBlock        = regexp.MustCompile(`^\{\{~?/`)
	rOpenPartial         = regexp.MustCompile(`^\{\{~?>`)
	rInverse          = regexp.MustCompile(`^(\{\{~?\^\s*~?\}\}|\{\{~?\s*else\s*~?\}\})`)
	rOpenInverse      = regexp.MustCompile(`^\{\{~?\^`)
	rOpenInverseChain = regexp.MustCompile(`^\{\{~?\s*else`)
	rOpen            = regexp.MustCompile(`^\{\{~?&?`)
	rClose           = regexp.MustCompile(`^~?\}\}`)
	rOpenBlockParams = regexp.MustCompile(`^as\s+\|`)
	rOpenCommentDash  = regexp.MustCompile(`^\{\{~?!--\s*`)
	rCloseCommentDash = regexp.MustCompile(`^\s*--~?\}\}`)
	rOpenComment  = regexp.MustCompile(`^\{\{~?!\s*`)
	rCloseComment = regexp.MustCompile(`^\s*~?\}\}`)
)
func Scan(input string) *Lexer {
	return scanWithName(input, "")
}
func scanWithName(input string, name string) *Lexer {
	result := &Lexer{
		input:  input,
		name:   name,
		tokens: make(chan Token),
		line:   1,
	}
	go result.run()
	return result
}
func Collect(input string) []Token {
	var result []Token
	l := Scan(input)
	for {
		token := l.NextToken()
		result = append(result, token)
		if token.Kind == TokenEOF || token.Kind == TokenError {
			break
		}
	}
	return result
}
func (l *Lexer) NextToken() Token {
	result := <-l.tokens
	return result
}
func (l *Lexer) run() {
	for l.nextFunc = lexContent; l.nextFunc != nil; {
		l.nextFunc = l.nextFunc(l)
	}
}
func (l *Lexer) next() rune {
	if l.pos >= len(l.input) {
		l.width = 0
		return eof
	}
	r, w := utf8.DecodeRuneInString(l.input[l.pos:])
	l.width = w
	l.pos += l.width
	return r
}
func (l *Lexer) produce(kind TokenKind, val string) {
	l.tokens <- Token{kind, val, l.start, l.line}
	l.start = l.pos
	l.line += strings.Count(val, "\n")
}
func (l *Lexer) emit(kind TokenKind) {
	l.produce(kind, l.input[l.start:l.pos])
}
func (l *Lexer) emitContent() {
	if l.pos > l.start {
		l.emit(TokenContent)
	}
}
func (l *Lexer) emitString(delimiter rune) {
	str := l.input[l.start:l.pos]
	str = strings.Replace(str, "\\"+string(delimiter), string(delimiter), -1)
	l.produce(TokenString, str)
}
func (l *Lexer) peek() rune {
	r := l.next()
	l.backup()
	return r
}
func (l *Lexer) backup() {
	l.pos -= l.width
}
func (l *Lexer) ignore() {
	l.start = l.pos
}
func (l *Lexer) accept(valid string) bool {
	if strings.IndexRune(valid, l.next()) >= 0 {
		return true
	}
	l.backup()
	return false
}
func (l *Lexer) acceptRun(valid string) {
	for strings.IndexRune(valid, l.next()) >= 0 {
	}
	l.backup()
}
func (l *Lexer) errorf(format string, args ...interface{}) lexFunc {
	l.tokens <- Token{TokenError, fmt.Sprintf(format, args...), l.start, l.line}
	return nil
}
func (l *Lexer) isString(str string) bool {
	return strings.HasPrefix(l.input[l.pos:], str)
}
func (l *Lexer) findRegexp(r *regexp.Regexp) string {
	return r.FindString(l.input[l.pos:])
}
func (l *Lexer) indexRegexp(r *regexp.Regexp) int {
	loc := r.FindStringIndex(l.input[l.pos:])
	if loc == nil {
		return -1
	}
	return loc[0]
}
func lexContent(l *Lexer) lexFunc {
	var next lexFunc
	if l.rawBlock {
		if i := l.indexRegexp(rOpenEndRawLookAhead); i != -1 {
			l.rawBlock = false
			l.pos += i
			next = lexOpenMustache
		} else {
			return l.errorf("Unclosed raw block")
		}
	} else if l.isString(escapedEscapedOpenMustache) {
		l.next()
		l.emitContent()
		l.next()
		l.ignore()
		next = lexContent
	} else if l.isString(escapedOpenMustache) {
		next = lexEscapedOpenMustache
	} else if str := l.findRegexp(rOpenCommentDash); str != "" {
		l.closeComment = rCloseCommentDash
		next = lexComment
	} else if str := l.findRegexp(rOpenComment); str != "" {
		l.closeComment = rCloseComment
		next = lexComment
	} else if l.isString(openMustache) {
		next = lexOpenMustache
	}
	if next != nil {
		l.emitContent()
		return next
	}
	if l.next() == eof {
		l.emitContent()
		l.emit(TokenEOF)
		return nil
	}
	return lexContent
}