// Convert an expression into an expression list split at the periods of
// selector expressions.
494188
func selectorExprList(expr ast.Expr) (list []ast.Expr) {
	// split expression
	for expr != nil {
		var suffix ast.Expr
		expr, suffix = splitSelector(expr)
		list = append(list, suffix)
	}

	// reverse list
	for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
		list[i], list[j] = list[j], list[i]
	}

	return
}
537681
func tokenizeExpression(ch rune, tokenType token, check runeCategoryValidator, r *bufio.Reader) (token, string, error) {
	var data []rune
	data = append(data, ch)

	for {
		c, _, err := r.ReadRune()

		if c == zeroRune {
			break
		}

		if err != nil {
			return tokenError, "", err
		}

		if check(c) {
			data = append(data, c)
		} else {
			err := r.UnreadRune()

			if err != nil {
				return tokenError, "", err
			}

			return tokenType, string(data), nil
		}
	}

	return tokenType, string(data), nil
}
496911
func Tokenise(expr string) []string {

	spaced := unary_minus_rx.ReplaceAllString(expr, "$1 @")
	spaced = fp_rx.ReplaceAllString(spaced, " ${1} ")
	spaced = functions_rx.ReplaceAllString(spaced, " ${1} ")

	if symbols_rx != nil {
		spaced = symbols_rx.ReplaceAllString(spaced, " ${1} ")
	}

	symbols := []string{"(", ")"}
	for _, symbol := range symbols {
		spaced = strings.Replace(spaced, symbol, fmt.Sprintf(" %s ", symbol), -1)
	}

	stripped := whitespace_rx.ReplaceAllString(strings.TrimSpace(spaced), "|")
	result := strings.Split(stripped, "|")
	return result
}
852949
func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression {
	result := make([]Expression, 0, len(funcs))
	for _, col := range funcs {
		result = append(result, col)
	}
	return result
}
317579
func (p *parser) parseAdditiveExpr(n node) node {
	opnd := p.parseMultiplicativeExpr(n)
Loop:
	for {
		var op string
		switch p.r.typ {
		case itemPlus:
			op = "+"
		case itemMinus:
			op = "-"
		default:
			break Loop
		}
		p.next()
		opnd = newOperatorNode(op, opnd, p.parseMultiplicativeExpr(n))
	}
	return opnd
}
839266
func Compile(s string) (expr Expression, err error) {
	if s == "0" {
		return constValue{value: 0}, nil
	}
	if !strings.Contains(s, "?") {
		s += "?1:0"
	}
	return compileExpression(s)
}
1129590
func (p *Parser) Selector() bool {

	if p.PeekByte() != '{' {
		return false
	}
	p.Byte()

	i := p.ev.Level()

	p.ev.Add(TypeSelector)
	p.ev.Inc()

	p.Space()
	p.Expression()
	p.Space()

	if p.PeekByte() != '}' {
		return false // error
	}
	p.Byte()

	// Level before and after is the same
	p.ev.SetLevel(i)
	return true
}
143149
func (c *ConfigParser) evaluateExpressions(m map[string]interface{}, seenKeys []string, testOnly bool) error {
	for k, ei := range m {
		thisPath := append(seenKeys, k)
		switch subval := ei.(type) {
		case string, bool, float64, nil:
			continue
		case []interface{}:
			if len(subval) == 0 {
				continue
			}
			evaled, err := c.evalValue(subval)
			if err != nil {
				return fmt.Errorf("%s: value error %v", strings.Join(thisPath, "."), err)
			}
			if !testOnly {
				m[k] = evaled
			}
		case map[string]interface{}:
			if err := c.evaluateExpressions(subval, thisPath, testOnly); err != nil {
				return err
			}
		default:
			return fmt.Errorf("%s: unhandled type %T", strings.Join(thisPath, "."), ei)
		}
	}
	return nil
}
299910
func GenerateExpressionSequence(command string) (expressionSequence, error) {
	seq := expressionSequence{}
	if command == "" {
		return seq, nil
	}
	got, err := ParseReader("", strings.NewReader(command))
	if err != nil {
		return nil, err
	}
	for _, exp := range got.([]interface{}) {
		seq = append(seq, exp.(expression))
	}
	return seq, nil
}
359859
func (exp *GetAttrExpr) All() []Node {
	res := []Node{exp.Cont, exp.Attr}
	for _, v := range exp.Args {
		res = append(res, v)
	}
	return res
}
377177
func Splitlines(s string) []string {
	s = strings.Replace(s, "\r", "\n", -1)
	s = strings.Replace(s, "\r\n", "\n", -1)
	return MapS(trimnewlines, FilterS(nonempty, strings.Split(s, "\n")))
}
390883
func (this *ExpressionTree) collapse() {
	ncs := make([]*ExpressionTree, 0)
	for _, c := range this.Children {
		c.collapse()
		if c.Name == "" && c.Value == -1 {
			for _, gc := range c.Children {
				ncs = append(ncs, gc)
			}
		} else {
			ncs = append(ncs, c)
		}
	}
	this.Children = ncs
}
351060
func (v *printVisitor) VisitExpression(node *Expression) interface{} {
	if v.inBlock {
		v.indent()
	}

	// path
	node.Path.Accept(v)

	// params
	v.str(" [")
	for i, n := range node.Params {
		if i > 0 {
			v.str(", ")
		}
		n.Accept(v)
	}
	v.str("]")

	// hash
	if node.Hash != nil {
		v.str(" ")
		node.Hash.Accept(v)
	}

	if v.inBlock {
		v.nl()
	}

	return nil
}
1142085
func regexpSelection(text []byte, expr string) Selection {
	var matches [][]int
	if rx, err := regexp.Compile(expr); err == nil {
		matches = rx.FindAllIndex(text, -1)
	}
	return makeSelection(matches)
}
524323
func Compile(expr string) (*Expr, error) {
	if expr == "" {
		return nil, errors.New("expr expression is nil")
	}
	qy, err := build(expr)
	if err != nil {
		return nil, err
	}
	return &Expr{s: expr, q: qy}, nil
}
425274
func SortedExplainExpressionList(exprs []Expression) []byte {
	buffer := bytes.NewBufferString("")
	exprInfos := make([]string, 0, len(exprs))
	for _, expr := range exprs {
		exprInfos = append(exprInfos, expr.ExplainInfo())
	}
	sort.Strings(exprInfos)
	for i, info := range exprInfos {
		buffer.WriteString(info)
		if i+1 < len(exprInfos) {
			buffer.WriteString(", ")
		}
	}
	return buffer.Bytes()
}
327982
func Expr(expression string, args ...interface{}) *expr {
	return &expr{expr: expression, args: args}
}