mirror of
https://github.com/golang/go
synced 2024-11-12 03:00:22 -07:00
- have explicit KeyValueExpr node instead of BinaryExpr ':' (as discussed)
- remove ':' token from operator precedence levels R=rsc DELTA=25 (13 added, 8 deleted, 4 changed) OCL=26850 CL=26854
This commit is contained in:
parent
5617028ab6
commit
7cba8e6f72
@ -179,9 +179,6 @@ type (
|
||||
};
|
||||
|
||||
// A CompositeLit node represents a composite literal.
|
||||
// A pair (x : y) in a CompositeLit is represented by
|
||||
// a binary expression with the Colon operator.
|
||||
// TODO decide if better to use a Pair node instead.
|
||||
//
|
||||
CompositeLit struct {
|
||||
Type Expr; // literal type
|
||||
@ -248,9 +245,6 @@ type (
|
||||
};
|
||||
|
||||
// A BinaryExpr node represents a binary expression.
|
||||
// A pair (x : y) in a CompositeLit is represented by
|
||||
// a binary expression with the Colon operator.
|
||||
// TODO decide if better to use a Pair node instead.
|
||||
//
|
||||
BinaryExpr struct {
|
||||
X Expr; // left operand
|
||||
@ -258,6 +252,15 @@ type (
|
||||
Op token.Token; // operator
|
||||
Y Expr; // right operand
|
||||
};
|
||||
|
||||
// A KeyValueExpr node represents (key : value) pairs
|
||||
// in composite literals.
|
||||
//
|
||||
KeyValueExpr struct {
|
||||
Key Expr;
|
||||
Colon token.Position; // position of ":"
|
||||
Value Expr;
|
||||
};
|
||||
)
|
||||
|
||||
|
||||
@ -342,6 +345,7 @@ func (x *SliceExpr) Pos() token.Position { return x.X.Pos(); }
|
||||
func (x *TypeAssertExpr) Pos() token.Position { return x.X.Pos(); }
|
||||
func (x *CallExpr) Pos() token.Position { return x.Fun.Pos(); }
|
||||
func (x *BinaryExpr) Pos() token.Position { return x.X.Pos(); }
|
||||
func (x *KeyValueExpr) Pos() token.Position { return x.Key.Pos(); }
|
||||
|
||||
|
||||
// All expression/type nodes implement a Visit method which takes
|
||||
@ -369,6 +373,7 @@ type ExprVisitor interface {
|
||||
DoStarExpr(x *StarExpr);
|
||||
DoUnaryExpr(x *UnaryExpr);
|
||||
DoBinaryExpr(x *BinaryExpr);
|
||||
DoKeyValueExpr(x *KeyValueExpr);
|
||||
|
||||
// Type expressions
|
||||
DoEllipsis(x *Ellipsis);
|
||||
@ -403,6 +408,7 @@ func (x *CallExpr) Visit(v ExprVisitor) { v.DoCallExpr(x); }
|
||||
func (x *StarExpr) Visit(v ExprVisitor) { v.DoStarExpr(x); }
|
||||
func (x *UnaryExpr) Visit(v ExprVisitor) { v.DoUnaryExpr(x); }
|
||||
func (x *BinaryExpr) Visit(v ExprVisitor) { v.DoBinaryExpr(x); }
|
||||
func (x *KeyValueExpr) Visit(v ExprVisitor) { v.DoKeyValueExpr(x); }
|
||||
|
||||
func (x *ArrayType) Visit(v ExprVisitor) { v.DoArrayType(x); }
|
||||
func (x *SliceType) Visit(v ExprVisitor) { v.DoSliceType(x); }
|
||||
|
@ -243,24 +243,23 @@ func (tok Token) String() string {
|
||||
|
||||
// A set of constants for precedence-based expression parsing.
|
||||
// Non-operators have lowest precedence, followed by operators
|
||||
// starting with precedence 0 up to unary operators. The highest
|
||||
// starting with precedence 1 up to unary operators. The highest
|
||||
// precedence corresponds serves as "catch-all" precedence for
|
||||
// selector, indexing, and other operator and delimiter tokens.
|
||||
//
|
||||
const (
|
||||
LowestPrec = -1; // non-operators
|
||||
LowestPrec = 0; // non-operators
|
||||
UnaryPrec = 7;
|
||||
HighestPrec = 8;
|
||||
)
|
||||
|
||||
|
||||
// Precedence returns the syntax precedence of the operator
|
||||
// token op or LowestPrecedence if op is not an operator.
|
||||
// Precedence returns the operator precedence of the binary
|
||||
// operator op. If op is not a binary operator, the result
|
||||
// is LowestPrecedence.
|
||||
//
|
||||
func (op Token) Precedence() int {
|
||||
switch op {
|
||||
case COLON:
|
||||
return 0;
|
||||
case LOR:
|
||||
return 1;
|
||||
case LAND:
|
||||
|
Loading…
Reference in New Issue
Block a user