func (op *OperatorToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	target := operatorList.Keys
	all := operatorList.Values
	if op.IsBegin {
		target = op.Maybes
	}
	index := op.CompareIndex
	maybes := []string{}
	for _, key := range target {
		item := all[key]
		rn := item.Runes
		maxIndex := len(rn) - 1
		if index <= maxIndex && s == rn[index] {
			if index == maxIndex {
				op.Exact = item
				op.Name = key
				op.Stat.Values = rn
				ok = true
			} else {
				maybes = append(maybes, key)
			}
		}
	}
	if len(maybes) == 0 {
		if op.Exact != nil {
			isComplete = true
			op.IsComplete = true
		}
		return
	}
	if !op.IsBegin {
		op.IsBegin = true
	}
	ok = true
	op.Maybes = maybes
	op.CompareIndex++
	return
}
Add for OperatorToken
package expression
import (
	"fmt"
	"log"
	"sort"
	"strconv"
	"unicode"
	"github.com/fefit/fet/types"
	"github.com/fefit/fet/utils"
)
type Indexs = types.Indexs
type Type int
type Runes []rune
type Flags map[string]bool
type Operator struct {
	Runes    Runes
	Priority int
}
type Expression struct {
	Parser  *Parser
	Initial bool
}
type Node struct {
	Left      *Node     
	Right     *Node     
	Root      *Node     
	Token     AnyToken  
	Type      string    
	Operator  string    
	Arguments []*Node   
	Function  *Node     
}
type OperatorList struct {
	Keys   []string
	Values map[string]*Operator
}
const (
	Quote              = '"'
	LeftRoundBracket   = '('
	RightRoundBracket  = ')'
	LeftSquareBracket  = '['
	RightSquareBracket = ']'
	Minus              = '-'
	Plus               = '+'
	Underline          = '_'
	Translate          = '\\'
	Space              = ' '
	Bitor              = "bitor"
	Dollar             = '$'
	VarSymbol          = '`'
)
var (
	operators = [][]string{
		{","},
		{"||"},
		{"&&"},
		{Bitor},
		{"^"},
		{"&"},
		{"==", "!="},
		{">=", "<=", "<", ">"},
		{"+", "-"},
		{"*", "/", "%"},
		{"**"},
		{"!"},
		{".", "|", ":", "(", ")", "[", "]"},
	}
	keywordOperators = map[string]string{
		"bitor": "bitor",
		"and":   "&&",
		"or":    "||",
		"not":   "!",
		"eq":    "==",
		"ne":    "!=",
		"lt":    "<",
		"le":    "<=",
		"gt":    ">",
		"ge":    ">=",
	}
	operatorList = func() OperatorList {
		preIndex := 8      
		ignoreIndex := 12  
		keys, values := []string{}, map[string]*Operator{}
		keys = append(keys, operators[preIndex]...)
		for i, total := 0, len(operators); i < total; i++ {
			ops := operators[i]
			for j, count := 0, len(ops); j < count; j++ {
				key := ops[j]
				values[key] = &Operator{
					Priority: i,
					Runes:    Runes(key),
				}
				if i == preIndex || (i == ignoreIndex && j > 2) {
					continue
				}
				keys = append(keys, key)
			}
		}
		return OperatorList{
			Keys:   keys,
			Values: values,
		}
	}()
	bases = map[rune]int{
		'b': 2,
		'o': 8,
		'x': 16,
	}
)
type Any interface{}
type AnyToken interface {
	Add(s rune) (bool, bool, bool, error)
	Validate(prevTokens []AnyToken) (AnyToken, error)
	SetStat(stat *TokenStat)
	GetStat() *TokenStat
}
func typeOf(token Any) string {
	name := fmt.Sprintf("%T", token)
	rns := Runes(name)
	total := len(rns)
	for total >= 0 {
		total--
		if r := rns[total]; r == '.' {
			break
		}
	}
	return string(rns[total+1:])
}
func getNoSpaceTokens(tokens []AnyToken, num int) (isPrevSpace bool, result []AnyToken) {
	isTwo := num == 2
	if num != 1 && !isTwo {
		log.Fatal("wrong num argments:getNoSpaceTokens")
	}
	prevs := getPrevTokens(tokens, num*2)
	p0, p1 := prevs[0], prevs[1]
	val, match := p0, p1
	if _, isSpace := p0.(*SpaceToken); isSpace {
		val = p1
		isPrevSpace = true
		if isTwo {
			p2, p3 := prevs[2], prevs[3]
			if _, isStillSpace := p2.(*SpaceToken); isStillSpace {
				match = p3
			} else {
				match = p2
			}
		}
	}
	result = append(result, val)
	if isTwo {
		result = append(result, match)
	}
	return
}
type TokenStat struct {
	StartIndex int
	Index      int
	ParseIndex int
	RBLevel    int
	RBSubLevel int
	SBLevel    int
	SBSubLevel int
	Logics     Flags
	Context    *Runes
	Values     Runes
}
type Token struct {
	IsComplete bool
	IsBegin    bool
	Stat       *TokenStat
}
type ValidateNextFn func(token AnyToken) error
func getPrevTokens(tokens []AnyToken, num int) []AnyToken {
	i, count, prevTokens := 1, len(tokens), []AnyToken{}
	for i <= num {
		if count >= i {
			prevTokens = append(prevTokens, tokens[count-i])
		} else {
			prevTokens = append(prevTokens, nil)
		}
		i++
	}
	return prevTokens
}
func (token *Token) GetStat() *TokenStat {
	return token.Stat
}
func (token *Token) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	return
}
func (token *Token) Judge() (ok bool, isComplete bool, retry bool, err error) {
	if token.IsBegin {
		token.IsComplete = true
		isComplete = true
	}
	return
}
func (token *Token) AddBracket(s rune, bracket rune) (ok bool, isComplete bool, retry bool, err error) {
	if s == bracket {
		ok = true
		isComplete = true
		stat := token.Stat
		stat.Values = append(stat.Values, bracket)
	}
	return
}
func (token *Token) SetStat(stat *TokenStat) {
	token.Stat = stat
}
type LeftBracketToken struct {
	Token
}
func (bracket *LeftBracketToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	return bracket.AddBracket(s, LeftRoundBracket)
}
func (bracket *LeftBracketToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	hasSpace, prevs := getNoSpaceTokens(tokens, 1)
	prev := prevs[0]
	if prev == nil {
		return
	}
	switch prev.(type) {
	case *OperatorToken, *LeftBracketToken:
	case *IdentifierToken, *RightSquareBracketToken:
		if hasSpace {
			return nil, fmt.Errorf("wrong space between function name and (")
		}
		stat := bracket.Stat
		stat.Logics = Flags{
			"IsFunc": true,
		}
	default:
		return nil, fmt.Errorf("wrong left round bracket previous token")
	}
	return
}
type RightBracketToken struct {
	Token
}
func (bracket *RightBracketToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	return bracket.AddBracket(s, RightRoundBracket)
}
func (bracket *RightBracketToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	stat := bracket.Stat
	if stat.RBLevel < 1 {
		return nil, fmt.Errorf("wrong right round bracket without start:%d", stat.StartIndex)
	}
	prevs := getPrevTokens(tokens, 1)
	p0 := prevs[0]
	if p0, ok := p0.(*LeftBracketToken); ok && !p0.Stat.Logics["IsFunc"] {
		return nil, fmt.Errorf("empty expression")
	}
	return
}
type LeftSquareBracketToken struct {
	Token
}
func (bracket *LeftSquareBracketToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	return bracket.AddBracket(s, LeftSquareBracket)
}
func (bracket *LeftSquareBracketToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	prevs := getPrevTokens(tokens, 1)
	p0 := prevs[0]
	switch p0.(type) {
	case *IdentifierToken, *RightSquareBracketToken, *RightBracketToken:
	default:
		return nil, fmt.Errorf("wrong member or index of object")
	}
	return
}
type RightSquareBracketToken struct {
	Token
}
func (bracket *RightSquareBracketToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	return bracket.AddBracket(s, RightSquareBracket)
}
func (bracket *RightSquareBracketToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	stat := bracket.Stat
	if stat.SBLevel < 0 {
		return nil, fmt.Errorf("can not find matched left square bracket:%d", stat.StartIndex)
	}
	_, prevs := getNoSpaceTokens(tokens, 2)
	val, match := prevs[0], prevs[1]
	if _, isLS := match.(*LeftSquareBracketToken); isLS {
		switch token := val.(type) {
		case *StringToken, *IdentifierToken:
		case *NumberToken:
			logics := token.Stat.Logics
			if logics["IsFloat"] || logics["IsPower"] {
				return nil, fmt.Errorf("can't use float or power number as index")
			}
		default:
			return nil, fmt.Errorf("wrong member visit")
		}
	} else if _, isLS := val.(*LeftSquareBracketToken); isLS {
		return nil, fmt.Errorf("empty member")
	}
	return
}
type SpaceToken struct {
	Token
}
func (space *SpaceToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	if unicode.IsSpace(s) {
		ok = true
		if !space.IsBegin {
			space.IsBegin = true
		}
		stat := space.Stat
		stat.Values = append(stat.Values, s)
		return
	}
	return space.Judge()
}
type IdentifierToken struct {
	Token
}
func (identifier *IdentifierToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	stat := identifier.Stat
	if isDigit := utils.IsArabicNumber(s); utils.IsEnLetter(s) || isDigit || s == Underline || s == Dollar {
		if !identifier.IsBegin {
			if isDigit {
				return
			}
			identifier.IsBegin = true
		} else if s == Dollar {
			err = fmt.Errorf("the $ can only use in identifier head")
			return
		}
		stat.Values = append(stat.Values, s)
		ok = true
		return
	}
	vals := stat.Values
	if len(vals) == 1 && (vals[0] == Underline || vals[0] == Dollar) {
		err = fmt.Errorf("can not use single %s as identifier", string(vals[0]))
		return
	}
	return identifier.Judge()
}
func (identifier *IdentifierToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	hasSpace, prevs := getNoSpaceTokens(tokens, 1)
	prev := prevs[0]
	stat := identifier.Stat
	ident := string(stat.Values)
	if op, ok := keywordOperators[ident]; ok {
		if op == "!" && prev == nil {
		} else if !hasSpace {
			return nil, fmt.Errorf("the keyword operator '%s' must have a left space after string or number", ident)
		}
		return buildOperatorToken(stat, op, ident), nil
	}
	if prev == nil {
		return
	}
	switch prev.(type) {
	case *OperatorToken, *LeftBracketToken, *LeftSquareBracketToken:
	default:
		return nil, fmt.Errorf("wrong idenfier token")
	}
	return
}
type StringToken struct {
	Token
	Variables []*Indexs
}
func (str *StringToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	stat := str.Stat
	if !str.IsBegin {
		if s == Quote {
			ok = true
			stat.Values = append(stat.Values, s)
			stat.Logics = Flags{}
			str.IsBegin = true
			return
		}
		return
	}
	ok = true
	logics := stat.Logics
	stat.Values = append(stat.Values, s)
	if logics["IsInTransalte"] {
		logics["IsInTransalte"] = false
		return
	}
	if s == Translate {
		logics["IsInTransalte"] = true
		logics["IsInVar"] = false
		return
	}
	if s == VarSymbol {
		if logics["IsInVar"] {
			last := str.Variables[len(str.Variables)-1]
			last.EndIndex = len(stat.Values)
		} else {
			logics["IsInVar"] = true
			str.Variables = append(str.Variables, &Indexs{
				StartIndex: len(stat.Values) - 1,
			})
		}
	}
	if s == Quote {
		isComplete = true
		str.IsComplete = true
		vars := str.Variables
		realVars := []*Indexs{}
		if len(vars) > 0 {
			for _, pos := range vars {
				if pos.EndIndex > pos.StartIndex+1 {
					realVars = append(realVars, pos)
				}
			}
			str.Variables = realVars
		}
	}
	return
}
func (str *StringToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	_, prevs := getNoSpaceTokens(tokens, 1)
	prev := prevs[0]
	if prev == nil {
		return
	}
	switch token := prev.(type) {
	case *LeftSquareBracketToken, *LeftBracketToken:
	case *OperatorToken:
		name := token.Name
		ops := operatorList.Values
		if value, exists := ops[name]; exists {
			name = string(value.Runes)
			if name == "+" || name == "," || (name == "!=" || name == "==" || name == "&&" || name == "||") || name == ":" {
				return
			}
		}
		return nil, fmt.Errorf("can not use operator '%v' with strings", name)
	default:
		return nil, fmt.Errorf("can not use string")
	}
	return
}
type NumberToken struct {
	Token
	Base     int
	Dicimals Runes
	Power    *NumberToken
}
func (number *NumberToken) setNumberBegin(s rune) {
	stat := number.Stat
	logics := stat.Logics
	logics["IsNumberBegin"] = true
	if s == '0' {
		logics["IsZeroBegin"] = true
	} else {
		stat.Values = append(stat.Values, s)
	}
}
func (number *NumberToken) Add(s rune) (ok bool, isComplete bool, retry bool, err error) {
	if !number.IsBegin {
		if isDigit := utils.IsArabicNumber(s); isDigit || s == Plus || s == Minus {
			number.IsBegin = true
			ok = true
			stat := number.Stat
			stat.Logics = Flags{}
			if isDigit {
				number.setNumberBegin(s)
				return
			}
			if s == Plus {
				stat.Logics["IsPlus"] = true
			} else {
				stat.Logics["IsMinus"] = true
			}
		}
		return
	}
	stat := number.Stat
	logics := stat.Logics
	if !logics["IsNumberBegin"] {
		if !utils.IsArabicNumber(s) {
			ok = false
			retry = true
			err = fmt.Errorf("should try a operator")
			return
		}
		ok = true
		number.setNumberBegin(s)
		return
	}
	if logics["IsBase"] {
		switch number.Base {
		case 2:
			ok = s == '0' || s == '1'
		case 8:
			ok = s >= '0' && s <= '7'
		case 16:
			ok = (s >= '0' && s <= '9') || (s >= 'a' && s <= 'f') || (s >= 'A' && s <= 'F')
		}
		if ok {
			stat.Values = append(stat.Values, s)
			return
		}
		if stat.Values != nil {
			isComplete = true
		} else {
			err = fmt.Errorf("unrecognize base %d:%v", number.Base, string(s))
		}
		return
	}
	if number.Power != nil {
		power := number.Power
		if powerOk, isPowerComplete, _, powerErr := power.Add(s); powerErr != nil {
			err = powerErr
		} else {
			if powerOk {
				powerLogics := power.Stat.Logics
				if powerLogics["IsFloat"] || powerLogics["IsBase"] || powerLogics["IsPower"] {
					err = fmt.Errorf("wrong scientific notation:%s", string(s))
				} else {
					ok = true
				}
			} else {
				if isPowerComplete {
					isComplete = true
					number.IsComplete = true
				} else {
					err = fmt.Errorf("wrong scientific notation: %v", s)
				}
			}
		}
		return
	}
	isFloat := logics["IsFloat"]
	isStillInt := !isFloat && stat.Values != nil
	if isFloat || isStillInt {
		if isDigit := utils.IsArabicNumber(s); isDigit {
			ok = true
			if isFloat {
				number.Dicimals = append(number.Dicimals, s)
			} else {
				stat.Values = append(stat.Values, s)
			}
			return
		}
		if s == 'e' {
			if isFloat && number.Dicimals == nil {
				err = fmt.Errorf("wrong float without dicimals")
				return
			}
			ok = true
			logics["IsPower"] = true
			number.Power = &NumberToken{
				Token: Token{
					Stat: &TokenStat{},
				},
			}
			return
		}
		if s == '.' && isStillInt {
			ok = true
			logics["IsFloat"] = true
			return
		}
		ok = false
		isComplete = true
		return
	}
	if logics["IsZeroBegin"] {
		if base, exists := bases[s]; exists {
			number.Base = base
			logics["IsBase"] = true
			ok = true
			return
		} else if s == '.' {
			ok = true
			logics["IsFloat"] = true
			return
		}
		isComplete = true
		return
	}
	return
}
func buildOperatorToken(stat *TokenStat, name string, keyword string) *OperatorToken {
	retryStat := &TokenStat{}
	*retryStat = *stat
	retryStat.Values = Runes(name)
	retryStat.Logics = Flags{}
	op := operatorList.Values[name]
	return &OperatorToken{
		Token: Token{
			IsBegin:    true,
			IsComplete: true,
			Stat:       retryStat,
		},
		Keyword: keyword,
		Exact:   op,
		Name:    name,
	}
}
func (number *NumberToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	hasSpace, prevs := getNoSpaceTokens(tokens, 1)
	prev := prevs[0]
	if prev == nil {
		return
	}
	stat := number.Stat
	logics := stat.Logics
	switch token := prev.(type) {
	case *LeftSquareBracketToken, *LeftBracketToken:
	case *OperatorToken:
		name := token.Name
		if !hasSpace {
			if (name == "-" && logics["IsMinus"]) || (name == "+" && logics["IsPlus"]) {
				return nil, fmt.Errorf("can not use %#v%#v operator", name, name)
			}
		}
	default:
		if logics["IsMinus"] || logics["IsPlus"] {
			var name string
			if logics["IsMinus"] {
				name = "-"
				logics["IsMinus"] = false
			} else {
				name = "+"
				logics["IsPlus"] = false
			}
			retryToken := buildOperatorToken(stat, name, "")
			stat.StartIndex++
			stat.Index++
			return retryToken, nil
		}
		return nil, fmt.Errorf("wrong number")
	}
	return
}
func (number *NumberToken) ToNumber() float64 {
	stat := number.Stat
	logics := stat.Logics
	values := string(stat.Values)
	power := 1.0
	symbol := 1.0
	var num float64
	if logics["IsMinus"] {
		symbol = -1.0
	}
	if logics["IsBase"] {
		cur, _ := strconv.ParseInt(values, number.Base, 64)
		num = float64(cur)
	} else {
		if logics["IsFloat"] {
			num, _ = strconv.ParseFloat(values+"."+string(number.Dicimals), 10)
		} else {
			num, _ = strconv.ParseFloat(values, 10)
		}
		if number.Power != nil {
			power = number.Power.ToNumber()
		}
	}
	return symbol * num * power
}
type OperatorToken struct {
	CompareIndex int
	Name         string
	Keyword      string
	Maybes       []string
	Exact        *Operator
	Token
}
func (op *OperatorToken) Validate(tokens []AnyToken) (retryToken AnyToken, err error) {
	_, prevs := getNoSpaceTokens(tokens, 1)
	prev := prevs[0]
	name := op.Name
	switch prev.(type) {
	case *NumberToken, *IdentifierToken, *RightBracketToken, *RightSquareBracketToken:
	case *OperatorToken, nil:
		if name != "!" {
			return nil, fmt.Errorf("wrong operator token")
		}
	case *StringToken:
		if name == "&&" || name == "||" || name == "," || name == ":" || name == "|" {
		} else {
			return nil, fmt.Errorf("wrong opeator with previous token 'string'")
		}
	default:
		return nil, fmt.Errorf("wrong operator token" + name)
	}
	return
}