示例#1
0
文件: lexerfunc_test.go 项目: otm/lex
// 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
}
示例#2
0
文件: endtoend_test.go 项目: otm/lex
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))
	}
}