func ParseRange()

in pkg/eas/types/types.go [176:269]


func ParseRange(input string) (Range, error) {
	const (
		stateBegin = iota
		stateEnd
		stateLVal
		stateRVal
		stateDelim
		stateInf
	)
	var (
		err             error
		state           = stateBegin
		result          = Range{}
		lval, rval, inf []rune
	)
	// remove all spaces.
	for i, c := range strings.ReplaceAll(input, " ", "") {
		switch state {
		case stateBegin:
			switch c {
			case '(':
				result.LeftInclude = false
				state = stateLVal
			case '[':
				result.LeftInclude = true
				state = stateLVal
			default:
				return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
			}
		case stateLVal:
			switch c {
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
				lval = append(lval, c)
			case ',':
				if len(lval) == 0 {
					return result, fmt.Errorf("malformed range left value")
				}
				state = stateDelim
			default:
				return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
			}
		case stateDelim:
			result.Begin, err = strconv.ParseUint(string(lval), 10, 64)
			if err != nil {
				return result, err
			}
			switch c {
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
				rval = append(rval, c)
				state = stateRVal
			case '+', 'i', 'I':
				state = stateInf
			default:
				return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
			}
		case stateRVal:
			switch c {
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
				rval = append(rval, c)
			case ')', ']':
				state = stateEnd
				result.End, err = strconv.ParseUint(string(rval), 10, 64)
				if err != nil {
					return result, err
				}
				switch c {
				case ']':
					result.RightInclude = true
				case ')':
					result.RightInclude = false
				}
			default:
				return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
			}
		case stateInf:
			switch c {
			case 'i', 'n', 'f', '+':
				inf = append(inf, c)
			case ')':
				state = stateEnd
				if string(inf) == "+inf" || string(inf) == "inf" || string(inf) == "+Inf" || string(inf) == "Inf" {
					result.PositiveInf = true
				} else {
					return result, fmt.Errorf("invalid symbol '%s'", string(inf))
				}
			default:
				return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
			}
		case stateEnd:
			return result, fmt.Errorf("invalid character '%c' at index %d", c, i)
		}
	}
	return result, nil
}