Beispiel #1
0
// LexBegin is the initial lexer function
func LexBegin(lexer *lex.Lexer) lex.StateFn {
	lexer.AcceptWhitespace(lex.Ignore)

	if strings.HasPrefix(lexer.InputToEnd(), MinusSign) {
		return LexSingleLineComment
	}
	return LexCode
}
Beispiel #2
0
func lexStart(l *lex.Lexer) lex.StateFn {
	l.AcceptWhitespace(lex.Ignore)

	r := l.Next()
	switch r {
	case lex.EOF:
		l.Emit(lex.TEOF)
		return nil
	case leftBracket:
		l.Backup()
		return lexLeftBracket
	default:
		if lex.IsAlphaNumeric(r) {
			return lexKey
		}
		return l.Errorf("Unknown charecter: %v", string(r))
	}
}