summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/go/ast.go18
-rw-r--r--src/lib/go/token.go11
2 files changed, 17 insertions, 12 deletions
diff --git a/src/lib/go/ast.go b/src/lib/go/ast.go
index d597e97a0..591adbc08 100644
--- a/src/lib/go/ast.go
+++ b/src/lib/go/ast.go
@@ -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); }
diff --git a/src/lib/go/token.go b/src/lib/go/token.go
index 696210979..b031b7f61 100644
--- a/src/lib/go/token.go
+++ b/src/lib/go/token.go
@@ -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: