]> Cypherpunks repositories - gostls13.git/commitdiff
- have explicit KeyValueExpr node instead of BinaryExpr ':' (as discussed)
authorRobert Griesemer <gri@golang.org>
Sat, 28 Mar 2009 02:26:03 +0000 (19:26 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 28 Mar 2009 02:26:03 +0000 (19:26 -0700)
- remove ':' token from operator precedence levels

R=rsc
DELTA=25  (13 added, 8 deleted, 4 changed)
OCL=26850
CL=26854

src/lib/go/ast.go
src/lib/go/token.go

index d597e97a02948e3ca11525b6135424fd9d1288fb..591adbc0851384d8ff7f11096919434ea69daccc 100644 (file)
@@ -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); }
index 696210979324bc01f51bbda04e1f63b2f27c67c4..b031b7f61c5df7173b66b112468c6d691b3483ad 100644 (file)
@@ -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: