schema/lexer.go
func lexText(l *Lexer) stateFn {
OUTER:
	for {
		l.skipWhitespace()
		remaining := l.remaining()

		if strings.HasPrefix(remaining, comment) { // Start comment
			// state function which lexes a comment
			return lexComment
		} else if strings.HasPrefix(remaining, pkg) { // Start package decl
			// state function which lexes a package decl
			return lexPackage
		} else if strings.HasPrefix(remaining, from) { // Start from decl
			// state function which lexes a from decl
			return lexFrom
		} else if strings.HasPrefix(remaining, typeDef) { // Start type def
			// state function which lexes a type
			return lexTypeDef
		} else if strings.HasPrefix(remaining, version) { // Start version
			// state function which lexes a version
			return lexVersion
		} else if strings.HasPrefix(remaining, required) { // Start required field
			// state function which lexes a field
			l.Pos += len(required)
			l.emit(TokenRequired)
			l.skipWhitespace()

			return lexType
		} else if strings.HasPrefix(remaining, optional) { // Start optional field
			// state function which lexes a field
			l.Pos += len(optional)
			l.emit(TokenOptional)
			l.skipWhitespace()
			return lexType
		} else if strings.HasPrefix(remaining, openScope) { // Open scope
			l.Pos += len(openScope)
			l.emit(TokenOpenCurlyBracket)
		} else if strings.HasPrefix(remaining, closeScope) { // Close scope
			l.Pos += len(closeScope)
			l.emit(TokenCloseCurlyBracket)
		} else {
			switch r := l.next(); {

			case r == eof: // reached EOF?
				l.emit(TokenEOF)
				break OUTER
			default:
				l.errorf("unknown token: %#v", string(r))
			}
		}
	}

	// Stops the run loop
	return nil
}
func lexText(l *Lexer) stateFn {
OUTER:
	for {
		l.skipWhitespace()
		remaining := l.remaining()

		if strings.HasPrefix(remaining, comment) { // Start comment
			// state function which lexes a comment
			return lexComment
		} else if strings.HasPrefix(remaining, pkg) { // Start package decl
			// state function which lexes a package decl
			return lexPackage
		} else if strings.HasPrefix(remaining, from) { // Start from decl
			// state function which lexes a from decl
			return lexFrom
		} else if strings.HasPrefix(remaining, typeDef) { // Start type def
			// state function which lexes a type
			return lexTypeDef
		} else if strings.HasPrefix(remaining, version) { // Start version
			// state function which lexes a version
			return lexVersion
		} else if strings.HasPrefix(remaining, required) { // Start required field
			// state function which lexes a field
			l.Pos += len(required)
			l.emit(TokenRequired)
			l.skipWhitespace()

			return lexType
		} else if strings.HasPrefix(remaining, optional) { // Start optional field
			// state function which lexes a field
			l.Pos += len(optional)
			l.emit(TokenOptional)
			l.skipWhitespace()
			return lexType
		} else if strings.HasPrefix(remaining, openScope) { // Open scope
			l.Pos += len(openScope)
			l.emit(TokenOpenCurlyBracket)
		} else if strings.HasPrefix(remaining, closeScope) { // Close scope
			l.Pos += len(closeScope)
			l.emit(TokenCloseCurlyBracket)
		} else {
			switch r := l.next(); {

			case r == eof: // reached EOF?
				l.emit(TokenEOF)
				break OUTER
			default:
				l.errorf("unknown token: %#v", string(r))
			}
		}
	}

	// Stops the run loop
	return nil
}
// Main lexer loop