parsing.go
func optimizeTokens(tokens []ExpressionToken) ([]ExpressionToken, error) {

	var token ExpressionToken
	var symbol OperatorSymbol
	var err error
	var index int

	for index, token = range tokens {

		// if we find a regex operator, and the right-hand value is a constant, precompile and replace with a pattern.
		if token.Kind != COMPARATOR {
			continue
		}

		symbol = comparatorSymbols[token.Value.(string)]
		if symbol != REQ && symbol != NREQ {
			continue
		}

		index++
		token = tokens[index]
		if token.Kind == STRING {

			token.Kind = PATTERN
			token.Value, err = regexp.Compile(token.Value.(string))

			if err != nil {
				return tokens, err
			}

			tokens[index] = token
		}
	}
	return tokens, nil
}
func optimizeTokens(tokens []ExpressionToken) ([]ExpressionToken, error) {

	var token ExpressionToken
	var symbol OperatorSymbol
	var err error
	var index int

	for index, token = range tokens {

		// if we find a regex operator, and the right-hand value is a constant, precompile and replace with a pattern.
		if token.Kind != COMPARATOR {
			continue
		}

		symbol = comparatorSymbols[token.Value.(string)]
		if symbol != REQ && symbol != NREQ {
			continue
		}

		index++
		token = tokens[index]
		if token.Kind == STRING {

			token.Kind = PATTERN
			token.Value, err = regexp.Compile(token.Value.(string))

			if err != nil {
				return tokens, err
			}

			tokens[index] = token
		}
	}
	return tokens, nil
}
func optimizeTokens ( tokens [ ] ExpressionToken ) ( [ ] ExpressionToken , error ) { var token ExpressionToken var symbol OperatorSymbol var err error var index int for index , token = range tokens { // if we find a regex operator, and the right-hand value is a constant, precompile and replace with a pattern. if token . Kind != COMPARATOR { continue } symbol = comparatorSymbols [ token . Value . ( string ) ] if symbol != REQ && symbol != NREQ { continue } index ++ token = tokens [ index ] if token . Kind == STRING { token . Kind = PATTERN token . Value , err = regexp . Compile ( token . Value . ( string ) ) if err != nil { return tokens , err } tokens [ index ] = token } } return tokens , nil }
/*
	Checks to see if any optimizations can be performed on the given [tokens], which form a complete, valid expression.
	The returns slice will represent the optimized (or unmodified) list of tokens to use.
*/
/ * Checks to see if any optimizations can be performed on the given [ tokens ] which form a complete valid expression . The returns slice will represent the optimized ( or unmodified ) list of tokens to use .