Esempio n. 1
0
func parseExprListClosed(p *parser, closeWith string) *ast.ExprList {
	ret := new(ast.ExprList)

	for {
		expr := p.parseExpr()
		if expr == nil {
			return nil
		}
		ret.Exprs = append(ret.Exprs, expr)

		if p.SeeOp(closeWith) {
			return ret
		}

		comma := p.ExpectOp(",")
		if comma == nil {
			return nil
		}
		ret.Commas = append(ret.Commas, comma)

		// could be a trailing comma
		if p.SeeOp(closeWith) {
			return ret
		}
	}

	return ret
}
Esempio n. 2
0
func buildExprList(b *builder, list *ast.ExprList) tast.Expr {
	ret := tast.NewExprList()
	if list == nil {
		return ret
	}
	n := list.Len()
	if n == 0 {
		return ret
	}
	if n == 1 {
		return b.buildExpr(list.Exprs[0])
	}

	for _, expr := range list.Exprs {
		ex := b.buildExpr(expr)
		if ex == nil {
			return nil
		}

		ref := ex.R()
		if !ref.IsSingle() {
			b.Errorf(ast.ExprPos(expr), "cannot put %s in a list", ref)
			return nil
		}

		ret.Append(ex)
	}
	return ret
}
Esempio n. 3
0
func buildConstExprList(b *builder, list *ast.ExprList) tast.Expr {
	n := list.Len()
	if n == 0 {
		b.Errorf(ast.ExprPos(list), "const expression list of zero length")
		return nil
	}
	if n == 1 {
		return b.buildConst(list.Exprs[0])
	}

	ret := tast.NewExprList()
	for _, expr := range list.Exprs {
		ex := b.buildConst(expr)
		if ex == nil {
			return nil
		}
		ref := ex.R()
		if !ref.IsSingle() {
			b.Errorf(ast.ExprPos(expr), "cannot put %s in a list", ref)
			return nil
		}
		ret.Append(ex)
	}
	return ret
}
Esempio n. 4
0
func parseExprList(p *parser) *ast.ExprList {
	ret := new(ast.ExprList)
	for {
		expr := p.parseExpr()
		if expr == nil {
			return nil
		}
		ret.Exprs = append(ret.Exprs, expr)
		if !p.SeeOp(",") {
			break
		}
		ret.Commas = append(ret.Commas, p.Shift())
	}
	return ret
}
Esempio n. 5
0
File: define.go Progetto: Xslxy/e8vm
func buildIdentExprList(b *builder, list *ast.ExprList) (
	idents []*lex8.Token, firstError ast.Expr,
) {
	ret := make([]*lex8.Token, 0, list.Len())
	for _, expr := range list.Exprs {
		op, ok := expr.(*ast.Operand)
		if !ok {
			return nil, expr
		}
		if op.Token.Type != parse.Ident {
			return nil, expr
		}
		ret = append(ret, op.Token)
	}

	return ret, nil
}