Skip to content

Commit b545d8e

Browse files
committed
cue: add String method for Op
Change-Id: Iebe2ecdd0a62538a58cb8be47ebacf8e12c4ffa6 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2346 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent a5286e4 commit b545d8e

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

cue/op.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import "cuelang.org/go/cue/token"
2020
// use to evaluate a value.
2121
type Op int
2222

23+
func (o Op) String() string {
24+
return opToString[o]
25+
}
26+
2327
// Values of Op.
2428
const (
2529
NoOp Op = iota
@@ -84,6 +88,37 @@ var opToOp = map[op]Op{
8488
opIMod: IntModuloOp,
8589
}
8690

91+
var opToString = map[Op]string{
92+
AndOp: "&",
93+
OrOp: "|",
94+
BooleanAndOp: "&&",
95+
BooleanOrOp: "||",
96+
EqualOp: "==",
97+
NotOp: "!",
98+
NotEqualOp: "!=",
99+
LessThanOp: "<",
100+
LessThanEqualOp: "<=",
101+
GreaterThanOp: ">",
102+
GreaterThanEqualOp: ">=",
103+
RegexMatchOp: "=~",
104+
NotRegexMatchOp: "!~",
105+
AddOp: "+",
106+
SubtractOp: "-",
107+
MultiplyOp: "*",
108+
FloatQuotientOp: "/",
109+
FloatRemainOp: "%",
110+
IntQuotientOp: "quo",
111+
IntRemainderOp: "rem",
112+
IntDivideOp: "div",
113+
IntModuloOp: "mod",
114+
115+
SelectorOp: ".",
116+
IndexOp: "[]",
117+
SliceOp: "[:]",
118+
CallOp: "()",
119+
InterpolationOp: `\()`,
120+
}
121+
87122
func opIn(op op, anyOf ...op) bool {
88123
for _, o := range anyOf {
89124
if o == op {

cue/types_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,34 +2016,3 @@ func TestExpr(t *testing.T) {
20162016
})
20172017
}
20182018
}
2019-
2020-
var opToString = map[Op]string{
2021-
AndOp: "&",
2022-
OrOp: "|",
2023-
BooleanAndOp: "&&",
2024-
BooleanOrOp: "||",
2025-
EqualOp: "==",
2026-
NotOp: "!",
2027-
NotEqualOp: "!=",
2028-
LessThanOp: "<",
2029-
LessThanEqualOp: "<=",
2030-
GreaterThanOp: ">",
2031-
GreaterThanEqualOp: ">=",
2032-
RegexMatchOp: "=~",
2033-
NotRegexMatchOp: "!~",
2034-
AddOp: "+",
2035-
SubtractOp: "-",
2036-
MultiplyOp: "*",
2037-
FloatQuotientOp: "/",
2038-
FloatRemainOp: "%",
2039-
IntQuotientOp: "quo",
2040-
IntRemainderOp: "rem",
2041-
IntDivideOp: "div",
2042-
IntModuloOp: "mod",
2043-
2044-
SelectorOp: ".",
2045-
IndexOp: "[]",
2046-
SliceOp: "[:]",
2047-
CallOp: "()",
2048-
InterpolationOp: `\()`,
2049-
}

0 commit comments

Comments
 (0)