cue/token: rename names for & and |
This is shorter, nicer and nicely indicates the analogy
with && and ||, as well as logic.
It also reads nicer:
a: >=3 & <=5 // a is GEQ 3 AND LEQ 5.
b: 1 | 2 // b is 1 OR 2
Change-Id: Idb1077aaedfff05478028572a718ee3e9e8a0463
Reviewed-on: https://cue-review.googlesource.com/c/1561
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cmd/cue/cmd/trim.go b/cmd/cue/cmd/trim.go
index 92e0f3d..8449b64 100644
--- a/cmd/cue/cmd/trim.go
+++ b/cmd/cue/cmd/trim.go
@@ -256,7 +256,7 @@
func isDisjunctionOfStruct(n ast.Node) bool {
switch x := n.(type) {
case *ast.BinaryExpr:
- if x.Op == token.DISJUNCTION {
+ if x.Op == token.OR {
return hasStruct(x.X) || hasStruct(x.Y)
}
}
diff --git a/cue/ast.go b/cue/ast.go
index 3ca7fd5..9bfc98e 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -477,7 +477,7 @@
case *ast.BinaryExpr:
switch n.Op {
- case token.DISJUNCTION:
+ case token.OR:
d := &disjunction{baseValue: newExpr(n)}
v.addDisjunctionElem(d, n.X, false)
v.addDisjunctionElem(d, n.Y, false)
@@ -506,7 +506,7 @@
func (v *astVisitor) addDisjunctionElem(d *disjunction, n ast.Node, mark bool) {
switch x := n.(type) {
case *ast.BinaryExpr:
- if x.Op == token.DISJUNCTION {
+ if x.Op == token.OR {
v.addDisjunctionElem(d, x.X, mark)
v.addDisjunctionElem(d, x.Y, mark)
return
diff --git a/cue/export.go b/cue/export.go
index c76ea8f..cb9f923 100644
--- a/cue/export.go
+++ b/cue/export.go
@@ -204,7 +204,7 @@
}
bin := p.expr(x.values[0])
for _, v := range x.values[1:] {
- bin = &ast.BinaryExpr{X: bin, Op: token.UNIFY, Y: p.expr(v)}
+ bin = &ast.BinaryExpr{X: bin, Op: token.AND, Y: p.expr(v)}
}
return bin
@@ -221,7 +221,7 @@
}
bin := expr(x.values[0])
for _, v := range x.values[1:] {
- bin = &ast.BinaryExpr{X: bin, Op: token.DISJUNCTION, Y: expr(v)}
+ bin = &ast.BinaryExpr{X: bin, Op: token.OR, Y: expr(v)}
}
return bin
@@ -419,7 +419,7 @@
p.expr(x.typ),
}},
},
- Op: token.UNIFY,
+ Op: token.AND,
Y: list,
}
diff --git a/cue/op.go b/cue/op.go
index 7d020aa..6385903 100644
--- a/cue/op.go
+++ b/cue/op.go
@@ -99,8 +99,8 @@
func (op op) String() string { return opStrings[op] }
var tokenMap = map[token.Token]op{
- token.DISJUNCTION: opDisjunction, // |
- token.UNIFY: opUnify, // &
+ token.OR: opDisjunction, // |
+ token.AND: opUnify, // &
token.ADD: opAdd, // +
token.SUB: opSub, // -
diff --git a/cue/scanner/scanner.go b/cue/scanner/scanner.go
index f3ce8ed..21b0aed 100644
--- a/cue/scanner/scanner.go
+++ b/cue/scanner/scanner.go
@@ -835,14 +835,14 @@
s.next()
tok = token.LAND
default:
- tok = token.UNIFY
+ tok = token.AND
}
case '|':
if s.ch == '|' {
s.next()
tok = token.LOR
} else {
- tok = token.DISJUNCTION
+ tok = token.OR
}
default:
// next reports unexpected BOMs - don't repeat
diff --git a/cue/scanner/scanner_test.go b/cue/scanner/scanner_test.go
index d0c63cb..422f9a8 100644
--- a/cue/scanner/scanner_test.go
+++ b/cue/scanner/scanner_test.go
@@ -115,8 +115,8 @@
{token.QUO, "/", operator},
{token.REM, "%", operator},
- {token.UNIFY, "&", operator},
- {token.DISJUNCTION, "|", operator},
+ {token.AND, "&", operator},
+ {token.OR, "|", operator},
{token.LAND, "&&", operator},
{token.LOR, "||", operator},
diff --git a/cue/token/token.go b/cue/token/token.go
index 560573b..87110b6 100644
--- a/cue/token/token.go
+++ b/cue/token/token.go
@@ -55,9 +55,8 @@
IDIV // div
IMOD // mod
- // TODO: rename to AND and OR
- UNIFY // &
- DISJUNCTION // |
+ AND // &
+ OR // |
LAND // &&
LOR // ||
@@ -129,8 +128,8 @@
IDIV: "div",
IMOD: "mod",
- UNIFY: "&",
- DISJUNCTION: "|",
+ AND: "&",
+ OR: "|",
LAND: "&&",
LOR: "||",
@@ -213,9 +212,9 @@
//
func (tok Token) Precedence() int {
switch tok {
- case DISJUNCTION:
+ case OR:
return 1
- case UNIFY:
+ case AND:
return 2
case LOR:
return 3