this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: remove support for infix div, mod, quo, and rem

These have been rewritten to functions via `cue fix` since a change
in late 2020: https://cue-review.googlesource.com/c/cue/+/7824

Similarly, the infix syntax has not been documented anywhere,
not even the spec, for half a decade now.

This transition was meant to later deprecate and remove support
for the old infix form of these operations. We didn't do that yet,
so do it now. Given the length of time it has been, we can go ahead
and remove all support at this point.

If there is any user who comes back to CUE after this many years,
they can resolve this hiccup by installing CUE v0.16.0 and using
that version's `cue fix` command once.

Most of the existing tests are rewritten to the new form,
with the exception of the tools/fix test, as that feature is now gone,
and the cue/parser test, as it specifically tested the infix parsing
with identifier operators. We no longer have any of those.

Fixes #2932.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia33d621eccb5b05c204f9baee27f691b68cefd82
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1234429
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+180 -306
-2
cue/format/printer.go
··· 470 470 return true, true 471 471 } 472 472 switch prev { 473 - case token.IQUO, token.IREM, token.IDIV, token.IMOD: 474 - return false, false 475 473 case token.INT: 476 474 before = next == token.PERIOD // 1. 477 475 case token.ADD:
+6 -6
cue/format/testdata/expressions.txtar
··· 93 93 e: f(3*4*5) 94 94 e: f(3+4*5) 95 95 96 - e: f(3 + 4 div 5) 96 + e: f(3 + div(4, 5)) 97 97 98 98 e: 3<4&&5>4 99 99 e: a || b && c || d ··· 109 109 e: a - b*c 110 110 e: a - (b * c) 111 111 e: a * b / c 112 - e: a div b + 5 112 + e: div(a, b) + 5 113 113 e: a / b 114 114 e: x[a|b] 115 115 e: x[a /b] 116 116 e: a & b 117 117 e: a + +b 118 118 e: a - -b 119 - e: a div - b 119 + e: div(a, - b) 120 120 e: x[a*-b] 121 121 e: x[a + +b] 122 122 e: len(longVariableName) * 2 ··· 377 377 e: f(3 * 4 * 5) 378 378 e: f(3 + 4*5) 379 379 380 - e: f(3 + 4 div 5) 380 + e: f(3 + div(4, 5)) 381 381 382 382 e: 3 < 4 && 5 > 4 383 383 e: a || b && c || d ··· 393 393 e: a - b*c 394 394 e: a - (b * c) 395 395 e: a * b / c 396 - e: a div b + 5 396 + e: div(a, b) + 5 397 397 e: a / b 398 398 e: x[a | b] 399 399 e: x[a/b] 400 400 e: a & b 401 401 e: a + +b 402 402 e: a - -b 403 - e: a div -b 403 + e: div(a, -b) 404 404 e: x[a*-b] 405 405 e: x[a + +b] 406 406 e: len(longVariableName) * 2
-4
cue/op.go
··· 52 52 SubtractOp Op = adt.SubtractOp 53 53 MultiplyOp Op = adt.MultiplyOp 54 54 FloatQuotientOp Op = adt.FloatQuotientOp 55 - IntQuotientOp Op = adt.IntQuotientOp 56 - IntRemainderOp Op = adt.IntRemainderOp 57 - IntDivideOp Op = adt.IntDivideOp 58 - IntModuloOp Op = adt.IntModuloOp 59 55 60 56 InterpolationOp Op = adt.InterpolationOp 61 57
+1 -20
cue/parser/parser.go
··· 1723 1723 return p.parsePrimaryExpr() 1724 1724 } 1725 1725 1726 - func (p *parser) tokPrec() (token.Token, int) { 1727 - tok := p.tok 1728 - if tok == token.IDENT { 1729 - switch p.lit { 1730 - case "quo": 1731 - return token.IQUO, 7 1732 - case "rem": 1733 - return token.IREM, 7 1734 - case "div": 1735 - return token.IDIV, 7 1736 - case "mod": 1737 - return token.IMOD, 7 1738 - default: 1739 - return tok, 0 1740 - } 1741 - } 1742 - return tok, tok.Precedence() 1743 - } 1744 - 1745 1726 // If lhs is set and the result is an identifier, it is not resolved. 1746 1727 func (p *parser) parseBinaryExpr(prec1 int) ast.Expr { 1747 1728 if p.trace { ··· 1755 1736 1756 1737 func (p *parser) parseBinaryExprTail(prec1 int, x ast.Expr) ast.Expr { 1757 1738 for { 1758 - op, prec := p.tokPrec() 1739 + op, prec := p.tok, p.tok.Precedence() 1759 1740 if prec < prec1 { 1760 1741 return x 1761 1742 }
-8
cue/parser/parser_test.go
··· 453 453 out: "a: (2+3)*5, b: (2+3)+4, c: 2+3+4, d: -1, e: !foo, f: _|_", 454 454 }, 455 455 { 456 - desc: "pseudo keyword expressions", 457 - in: ` a: (2 div 3) mod 5 458 - b: (2 quo 3) rem 4 459 - c: 2 div 3 div 4 460 - `, 461 - out: "a: (2 div 3) mod 5, b: (2 quo 3) rem 4, c: 2 div 3 div 4", 462 - }, 463 - { 464 456 desc: "ranges", 465 457 in: ` a: >=1 & <=2 466 458 b: >2.0 & <= 40.0
+34 -42
cue/testdata/basicrewrite/002_arithmetic.txtar
··· 13 13 b: 1 != 4 14 14 add: div1 + 1.0 15 15 16 - idiv00: 0 div 0 17 - imod00: 0 mod 0 18 - iquo00: 0 quo 0 19 - irem00: 0 rem 0 16 + idiv00: div(0, 0) 17 + imod00: mod(0, 0) 18 + iquo00: quo(0, 0) 19 + irem00: rem(0, 0) 20 20 21 21 v1: 1.0T / 2.0 22 22 v2: 2.0 == 2 23 23 v3: 2.0 / 3.0 24 - v5: i1 div i2 24 + v5: div(i1, i2) 25 25 26 26 e0: 2 + "a" 27 27 // these are now all alloweed ··· 29 29 // e2: i1 / 2.0 30 30 // e3: 3.0 % i2 31 31 // e4: i1 % 2.0 32 - e5: 1.0 div 2 33 - e6: 2 rem 2.0 34 - e7: 2 quo 2.0 35 - e8: 1.0 mod 1 32 + e5: div(1.0, 2) 33 + e6: rem(2, 2.0) 34 + e7: quo(2, 2.0) 35 + e8: mod(1.0, 1) 36 36 -- out/compile -- 37 37 --- in.cue 38 38 { ··· 46 46 div00: (0 / 0) 47 47 b: (1 != 4) 48 48 add: (〈0;div1〉 + 1.0) 49 - idiv00: (0 div 0) 50 - imod00: (0 mod 0) 51 - iquo00: (0 quo 0) 52 - irem00: (0 rem 0) 49 + idiv00: div(0, 0) 50 + imod00: mod(0, 0) 51 + iquo00: quo(0, 0) 52 + irem00: rem(0, 0) 53 53 v1: (1000000000000 / 2.0) 54 54 v2: (2.0 == 2) 55 55 v3: (2.0 / 3.0) 56 - v5: (〈0;i1〉 div 〈0;i2〉) 56 + v5: div(〈0;i1〉, 〈0;i2〉) 57 57 e0: (2 + "a") 58 - e5: (1.0 div 2) 59 - e6: (2 rem 2.0) 60 - e7: (2 quo 2.0) 61 - e8: (1.0 mod 1) 58 + e5: div(1.0, 2) 59 + e6: rem(2, 2.0) 60 + e7: quo(2, 2.0) 61 + e8: mod(1.0, 1) 62 62 } 63 63 -- out/eval/stats -- 64 64 Leaks: 0 ··· 87 87 e0: invalid operands 2 and "a" to '+' (type int and string): 88 88 ./in.cue:23:5 89 89 ./in.cue:23:9 90 - e5: invalid operands 1.0 and 2 to 'div' (type float and int): 91 - ./in.cue:29:5 92 - ./in.cue:29:13 93 - e6: invalid operands 2 and 2.0 to 'rem' (type int and float): 94 - ./in.cue:30:5 95 - ./in.cue:30:11 96 - e7: invalid operands 2 and 2.0 to 'quo' (type int and float): 97 - ./in.cue:31:5 98 - ./in.cue:31:11 99 - e8: invalid operands 1.0 and 1 to 'mod' (type float and int): 100 - ./in.cue:32:5 101 - ./in.cue:32:13 90 + e5: cannot use 1.0 (type float) as int in argument 1 to div: 91 + ./in.cue:29:9 92 + e6: cannot use 2.0 (type float) as int in argument 2 to rem: 93 + ./in.cue:30:12 94 + e7: cannot use 2.0 (type float) as int in argument 2 to quo: 95 + ./in.cue:31:12 96 + e8: cannot use 1.0 (type float) as int in argument 1 to mod: 97 + ./in.cue:32:9 102 98 103 99 Result: 104 100 (_|_){ ··· 145 141 // ./in.cue:23:9 146 142 } 147 143 e5: (_|_){ 148 - // [eval] e5: invalid operands 1.0 and 2 to 'div' (type float and int): 149 - // ./in.cue:29:5 150 - // ./in.cue:29:13 144 + // [eval] e5: cannot use 1.0 (type float) as int in argument 1 to div: 145 + // ./in.cue:29:9 151 146 } 152 147 e6: (_|_){ 153 - // [eval] e6: invalid operands 2 and 2.0 to 'rem' (type int and float): 154 - // ./in.cue:30:5 155 - // ./in.cue:30:11 148 + // [eval] e6: cannot use 2.0 (type float) as int in argument 2 to rem: 149 + // ./in.cue:30:12 156 150 } 157 151 e7: (_|_){ 158 - // [eval] e7: invalid operands 2 and 2.0 to 'quo' (type int and float): 159 - // ./in.cue:31:5 160 - // ./in.cue:31:11 152 + // [eval] e7: cannot use 2.0 (type float) as int in argument 2 to quo: 153 + // ./in.cue:31:12 161 154 } 162 155 e8: (_|_){ 163 - // [eval] e8: invalid operands 1.0 and 1 to 'mod' (type float and int): 164 - // ./in.cue:32:5 165 - // ./in.cue:32:13 156 + // [eval] e8: cannot use 1.0 (type float) as int in argument 1 to mod: 157 + // ./in.cue:32:9 166 158 } 167 159 }
+80 -96
cue/testdata/basicrewrite/003_integer-specific_arithmetic.txtar
··· 1 1 #name: integer-specific arithmetic 2 2 #evalPartial 3 3 -- in.cue -- 4 - q1: 5 quo 2 // 2 5 - q2: 5 quo -2 // -2 6 - q3: -5 quo 2 // -2 7 - q4: -5 quo -2 // 2 8 - qe1: 2.0 quo 1 9 - qe2: 2 quo 1.0 4 + q1: quo(5, 2) // 2 5 + q2: quo(5, -2) // -2 6 + q3: quo(-5, 2) // -2 7 + q4: quo(-5, -2) // 2 8 + qe1: quo(2.0, 1) 9 + qe2: quo(2, 1.0) 10 10 11 - r1: 5 rem 2 // 1 12 - r2: 5 rem -2 // 1 13 - r3: -5 rem 2 // -1 14 - r4: -5 rem -2 // -1 15 - re1: 2.0 rem 1 16 - re2: 2 rem 1.0 11 + r1: rem(5, 2) // 1 12 + r2: rem(5, -2) // 1 13 + r3: rem(-5, 2) // -1 14 + r4: rem(-5, -2) // -1 15 + re1: rem(2.0, 1) 16 + re2: rem(2, 1.0) 17 17 18 - d1: 5 div 2 // 2 19 - d2: 5 div -2 // -2 20 - d3: -5 div 2 // -3 21 - d4: -5 div -2 // 3 22 - de1: 2.0 div 1 23 - de2: 2 div 1.0 18 + d1: div(5, 2) // 2 19 + d2: div(5, -2) // -2 20 + d3: div(-5, 2) // -3 21 + d4: div(-5, -2) // 3 22 + de1: div(2.0, 1) 23 + de2: div(2, 1.0) 24 24 25 - m1: 5 mod 2 // 1 26 - m2: 5 mod -2 // 1 27 - m3: -5 mod 2 // 1 28 - m4: -5 mod -2 // 1 29 - me1: 2.0 mod 1 30 - me2: 2 mod 1.0 25 + m1: mod(5, 2) // 1 26 + m2: mod(5, -2) // 1 27 + m3: mod(-5, 2) // 1 28 + m4: mod(-5, -2) // 1 29 + me1: mod(2.0, 1) 30 + me2: mod(2, 1.0) 31 31 -- out/compile -- 32 32 --- in.cue 33 33 { 34 - q1: (5 quo 2) 35 - q2: (5 quo -2) 36 - q3: (-5 quo 2) 37 - q4: (-5 quo -2) 38 - qe1: (2.0 quo 1) 39 - qe2: (2 quo 1.0) 40 - r1: (5 rem 2) 41 - r2: (5 rem -2) 42 - r3: (-5 rem 2) 43 - r4: (-5 rem -2) 44 - re1: (2.0 rem 1) 45 - re2: (2 rem 1.0) 46 - d1: (5 div 2) 47 - d2: (5 div -2) 48 - d3: (-5 div 2) 49 - d4: (-5 div -2) 50 - de1: (2.0 div 1) 51 - de2: (2 div 1.0) 52 - m1: (5 mod 2) 53 - m2: (5 mod -2) 54 - m3: (-5 mod 2) 55 - m4: (-5 mod -2) 56 - me1: (2.0 mod 1) 57 - me2: (2 mod 1.0) 34 + q1: quo(5, 2) 35 + q2: quo(5, -2) 36 + q3: quo(-5, 2) 37 + q4: quo(-5, -2) 38 + qe1: quo(2.0, 1) 39 + qe2: quo(2, 1.0) 40 + r1: rem(5, 2) 41 + r2: rem(5, -2) 42 + r3: rem(-5, 2) 43 + r4: rem(-5, -2) 44 + re1: rem(2.0, 1) 45 + re2: rem(2, 1.0) 46 + d1: div(5, 2) 47 + d2: div(5, -2) 48 + d3: div(-5, 2) 49 + d4: div(-5, -2) 50 + de1: div(2.0, 1) 51 + de2: div(2, 1.0) 52 + m1: mod(5, 2) 53 + m2: mod(5, -2) 54 + m3: mod(-5, 2) 55 + m4: mod(-5, -2) 56 + me1: mod(2.0, 1) 57 + me2: mod(2, 1.0) 58 58 } 59 59 -- out/eval/stats -- 60 60 Leaks: 0 ··· 68 68 Disjuncts: 25 69 69 -- out/evalalpha -- 70 70 Errors: 71 - qe1: invalid operands 2.0 and 1 to 'quo' (type float and int): 72 - ./in.cue:5:6 73 - ./in.cue:5:14 74 - qe2: invalid operands 2 and 1.0 to 'quo' (type int and float): 75 - ./in.cue:6:6 76 - ./in.cue:6:12 77 - re1: invalid operands 2.0 and 1 to 'rem' (type float and int): 78 - ./in.cue:12:6 79 - ./in.cue:12:14 80 - re2: invalid operands 2 and 1.0 to 'rem' (type int and float): 81 - ./in.cue:13:6 82 - ./in.cue:13:12 83 - de1: invalid operands 2.0 and 1 to 'div' (type float and int): 84 - ./in.cue:19:6 85 - ./in.cue:19:14 86 - de2: invalid operands 2 and 1.0 to 'div' (type int and float): 87 - ./in.cue:20:6 88 - ./in.cue:20:12 89 - me1: invalid operands 2.0 and 1 to 'mod' (type float and int): 90 - ./in.cue:26:6 91 - ./in.cue:26:14 92 - me2: invalid operands 2 and 1.0 to 'mod' (type int and float): 93 - ./in.cue:27:6 94 - ./in.cue:27:12 71 + qe1: cannot use 2.0 (type float) as int in argument 1 to quo: 72 + ./in.cue:5:10 73 + qe2: cannot use 1.0 (type float) as int in argument 2 to quo: 74 + ./in.cue:6:13 75 + re1: cannot use 2.0 (type float) as int in argument 1 to rem: 76 + ./in.cue:12:10 77 + re2: cannot use 1.0 (type float) as int in argument 2 to rem: 78 + ./in.cue:13:13 79 + de1: cannot use 2.0 (type float) as int in argument 1 to div: 80 + ./in.cue:19:10 81 + de2: cannot use 1.0 (type float) as int in argument 2 to div: 82 + ./in.cue:20:13 83 + me1: cannot use 2.0 (type float) as int in argument 1 to mod: 84 + ./in.cue:26:10 85 + me2: cannot use 1.0 (type float) as int in argument 2 to mod: 86 + ./in.cue:27:13 95 87 96 88 Result: 97 89 (_|_){ ··· 101 93 q3: (int){ -2 } 102 94 q4: (int){ 2 } 103 95 qe1: (_|_){ 104 - // [eval] qe1: invalid operands 2.0 and 1 to 'quo' (type float and int): 105 - // ./in.cue:5:6 106 - // ./in.cue:5:14 96 + // [eval] qe1: cannot use 2.0 (type float) as int in argument 1 to quo: 97 + // ./in.cue:5:10 107 98 } 108 99 qe2: (_|_){ 109 - // [eval] qe2: invalid operands 2 and 1.0 to 'quo' (type int and float): 110 - // ./in.cue:6:6 111 - // ./in.cue:6:12 100 + // [eval] qe2: cannot use 1.0 (type float) as int in argument 2 to quo: 101 + // ./in.cue:6:13 112 102 } 113 103 r1: (int){ 1 } 114 104 r2: (int){ 1 } 115 105 r3: (int){ -1 } 116 106 r4: (int){ -1 } 117 107 re1: (_|_){ 118 - // [eval] re1: invalid operands 2.0 and 1 to 'rem' (type float and int): 119 - // ./in.cue:12:6 120 - // ./in.cue:12:14 108 + // [eval] re1: cannot use 2.0 (type float) as int in argument 1 to rem: 109 + // ./in.cue:12:10 121 110 } 122 111 re2: (_|_){ 123 - // [eval] re2: invalid operands 2 and 1.0 to 'rem' (type int and float): 124 - // ./in.cue:13:6 125 - // ./in.cue:13:12 112 + // [eval] re2: cannot use 1.0 (type float) as int in argument 2 to rem: 113 + // ./in.cue:13:13 126 114 } 127 115 d1: (int){ 2 } 128 116 d2: (int){ -2 } 129 117 d3: (int){ -3 } 130 118 d4: (int){ 3 } 131 119 de1: (_|_){ 132 - // [eval] de1: invalid operands 2.0 and 1 to 'div' (type float and int): 133 - // ./in.cue:19:6 134 - // ./in.cue:19:14 120 + // [eval] de1: cannot use 2.0 (type float) as int in argument 1 to div: 121 + // ./in.cue:19:10 135 122 } 136 123 de2: (_|_){ 137 - // [eval] de2: invalid operands 2 and 1.0 to 'div' (type int and float): 138 - // ./in.cue:20:6 139 - // ./in.cue:20:12 124 + // [eval] de2: cannot use 1.0 (type float) as int in argument 2 to div: 125 + // ./in.cue:20:13 140 126 } 141 127 m1: (int){ 1 } 142 128 m2: (int){ 1 } 143 129 m3: (int){ 1 } 144 130 m4: (int){ 1 } 145 131 me1: (_|_){ 146 - // [eval] me1: invalid operands 2.0 and 1 to 'mod' (type float and int): 147 - // ./in.cue:26:6 148 - // ./in.cue:26:14 132 + // [eval] me1: cannot use 2.0 (type float) as int in argument 1 to mod: 133 + // ./in.cue:26:10 149 134 } 150 135 me2: (_|_){ 151 - // [eval] me2: invalid operands 2 and 1.0 to 'mod' (type int and float): 152 - // ./in.cue:27:6 153 - // ./in.cue:27:12 136 + // [eval] me2: cannot use 1.0 (type float) as int in argument 2 to mod: 137 + // ./in.cue:27:13 154 138 } 155 139 }
+2 -2
cue/testdata/eval/expressions.txtar
··· 5 5 a: 1 6 6 b: 1 + 2 7 7 c: 3 - 1 8 - d: 5 rem 3 8 + d: rem(5, 3) 9 9 10 10 // StructCmp examples - now that the experiment is accepted 11 11 structComparison: { ··· 102 102 a: 1 103 103 b: (1 + 2) 104 104 c: (3 - 1) 105 - d: (5 rem 3) 105 + d: rem(5, 3) 106 106 structComparison: { 107 107 equalStructs: { 108 108 t: ({
+1 -6
cue/token/token.go
··· 57 57 POW // ^ 58 58 QUO // / 59 59 60 - IQUO // quo 61 - IREM // rem 62 - IDIV // div 63 - IMOD // mod 64 - 65 60 AND // & 66 61 OR // | 67 62 ··· 151 146 return 5 152 147 case ADD, SUB: 153 148 return 6 154 - case MUL, QUO, IDIV, IMOD, IQUO, IREM: 149 + case MUL, QUO: 155 150 return 7 156 151 } 157 152 return lowestPrec
+44 -48
cue/token/token_string.go
··· 26 26 _ = x[MUL-15] 27 27 _ = x[POW-16] 28 28 _ = x[QUO-17] 29 - _ = x[IQUO-18] 30 - _ = x[IREM-19] 31 - _ = x[IDIV-20] 32 - _ = x[IMOD-21] 33 - _ = x[AND-22] 34 - _ = x[OR-23] 35 - _ = x[LAND-24] 36 - _ = x[LOR-25] 37 - _ = x[BIND-26] 38 - _ = x[EQL-27] 39 - _ = x[LSS-28] 40 - _ = x[GTR-29] 41 - _ = x[NOT-30] 42 - _ = x[ARROW-31] 43 - _ = x[NEQ-32] 44 - _ = x[LEQ-33] 45 - _ = x[GEQ-34] 46 - _ = x[MAT-35] 47 - _ = x[NMAT-36] 48 - _ = x[LPAREN-37] 49 - _ = x[LBRACK-38] 50 - _ = x[LBRACE-39] 51 - _ = x[COMMA-40] 52 - _ = x[PERIOD-41] 53 - _ = x[ELLIPSIS-42] 54 - _ = x[RPAREN-43] 55 - _ = x[RBRACK-44] 56 - _ = x[RBRACE-45] 57 - _ = x[SEMICOLON-46] 58 - _ = x[COLON-47] 59 - _ = x[OPTION-48] 60 - _ = x[TILDE-49] 61 - _ = x[operatorEnd-50] 62 - _ = x[keywordBeg-51] 63 - _ = x[IF-52] 64 - _ = x[ELSE-53] 65 - _ = x[FOR-54] 66 - _ = x[IN-55] 67 - _ = x[LET-56] 68 - _ = x[TRY-57] 69 - _ = x[FALLBACK-58] 70 - _ = x[FUNC-59] 71 - _ = x[TRUE-60] 72 - _ = x[FALSE-61] 73 - _ = x[NULL-62] 74 - _ = x[keywordEnd-63] 29 + _ = x[AND-18] 30 + _ = x[OR-19] 31 + _ = x[LAND-20] 32 + _ = x[LOR-21] 33 + _ = x[BIND-22] 34 + _ = x[EQL-23] 35 + _ = x[LSS-24] 36 + _ = x[GTR-25] 37 + _ = x[NOT-26] 38 + _ = x[ARROW-27] 39 + _ = x[NEQ-28] 40 + _ = x[LEQ-29] 41 + _ = x[GEQ-30] 42 + _ = x[MAT-31] 43 + _ = x[NMAT-32] 44 + _ = x[LPAREN-33] 45 + _ = x[LBRACK-34] 46 + _ = x[LBRACE-35] 47 + _ = x[COMMA-36] 48 + _ = x[PERIOD-37] 49 + _ = x[ELLIPSIS-38] 50 + _ = x[RPAREN-39] 51 + _ = x[RBRACK-40] 52 + _ = x[RBRACE-41] 53 + _ = x[SEMICOLON-42] 54 + _ = x[COLON-43] 55 + _ = x[OPTION-44] 56 + _ = x[TILDE-45] 57 + _ = x[operatorEnd-46] 58 + _ = x[keywordBeg-47] 59 + _ = x[IF-48] 60 + _ = x[ELSE-49] 61 + _ = x[FOR-50] 62 + _ = x[IN-51] 63 + _ = x[LET-52] 64 + _ = x[TRY-53] 65 + _ = x[FALLBACK-54] 66 + _ = x[FUNC-55] 67 + _ = x[TRUE-56] 68 + _ = x[FALSE-57] 69 + _ = x[NULL-58] 70 + _ = x[keywordEnd-59] 75 71 } 76 72 77 - const _Token_name = "ILLEGALEOFCOMMENTATTRIBUTEliteralBegIDENTINTFLOATSTRINGINTERPOLATION_|_literalEndoperatorBeg+-*^/quoremdivmod&|&&||===<>!<-!=<=>==~!~([{,....)]};:?~operatorEndkeywordBegifelseforinlettryfallbackfunctruefalsenullkeywordEnd" 73 + const _Token_name = "ILLEGALEOFCOMMENTATTRIBUTEliteralBegIDENTINTFLOATSTRINGINTERPOLATION_|_literalEndoperatorBeg+-*^/&|&&||===<>!<-!=<=>==~!~([{,....)]};:?~operatorEndkeywordBegifelseforinlettryfallbackfunctruefalsenullkeywordEnd" 78 74 79 - var _Token_index = [...]uint8{0, 7, 10, 17, 26, 36, 41, 44, 49, 55, 68, 71, 81, 92, 93, 94, 95, 96, 97, 100, 103, 106, 109, 110, 111, 113, 115, 116, 118, 119, 120, 121, 123, 125, 127, 129, 131, 133, 134, 135, 136, 137, 138, 141, 142, 143, 144, 145, 146, 147, 148, 159, 169, 171, 175, 178, 180, 183, 186, 194, 198, 202, 207, 211, 221} 75 + var _Token_index = [...]uint8{0, 7, 10, 17, 26, 36, 41, 44, 49, 55, 68, 71, 81, 92, 93, 94, 95, 96, 97, 98, 99, 101, 103, 104, 106, 107, 108, 109, 111, 113, 115, 117, 119, 121, 122, 123, 124, 125, 126, 129, 130, 131, 132, 133, 134, 135, 136, 147, 157, 159, 163, 166, 168, 171, 174, 182, 186, 190, 195, 199, 209} 80 76 81 77 func (i Token) String() string { 82 78 idx := int(i) - 0
+8 -8
cue/types_test.go
··· 4052 4052 input: "v: 2 / 5", 4053 4053 want: "/(2 5)", 4054 4054 }, { 4055 - input: "v: 2 quo 5", 4056 - want: "quo(2 5)", 4055 + input: "v: quo(2, 5)", 4056 + want: "()(quo 2 5)", 4057 4057 }, { 4058 - input: "v: 2 rem 5", 4059 - want: "rem(2 5)", 4058 + input: "v: rem(2, 5)", 4059 + want: "()(rem 2 5)", 4060 4060 }, { 4061 - input: "v: 2 div 5", 4062 - want: "div(2 5)", 4061 + input: "v: div(2, 5)", 4062 + want: "()(div 2 5)", 4063 4063 }, { 4064 - input: "v: 2 mod 5", 4065 - want: "mod(2 5)", 4064 + input: "v: mod(2, 5)", 4065 + want: "()(mod 2 5)", 4066 4066 }, { 4067 4067 input: "@experiment(explicitopen)\n v: #Y..., #Y: {b: 2}", 4068 4068 want: `...(.(〈〉 "#Y"))`,
-20
internal/core/adt/binop.go
··· 232 232 if leftKind&NumberKind != 0 && rightKind&NumberKind != 0 { 233 233 return c.Quo(c.Num(left, op), c.Num(right, op)) 234 234 } 235 - 236 - case IntDivideOp: 237 - if leftKind&IntKind != 0 && rightKind&IntKind != 0 { 238 - return c.IntDiv(c.Num(left, op), c.Num(right, op)) 239 - } 240 - 241 - case IntModuloOp: 242 - if leftKind&IntKind != 0 && rightKind&IntKind != 0 { 243 - return c.IntMod(c.Num(left, op), c.Num(right, op)) 244 - } 245 - 246 - case IntQuotientOp: 247 - if leftKind&IntKind != 0 && rightKind&IntKind != 0 { 248 - return c.IntQuo(c.Num(left, op), c.Num(right, op)) 249 - } 250 - 251 - case IntRemainderOp: 252 - if leftKind&IntKind != 0 && rightKind&IntKind != 0 { 253 - return c.IntRem(c.Num(left, op), c.Num(right, op)) 254 - } 255 235 } 256 236 257 237 return c.NewErrf("invalid operands %s and %s to '%s' (type %s and %s)",
-9
internal/core/adt/op.go
··· 52 52 SubtractOp // - 53 53 MultiplyOp // * 54 54 FloatQuotientOp // / 55 - IntQuotientOp // quo 56 - IntRemainderOp // rem 57 - IntDivideOp // div 58 - IntModuloOp // mod 59 55 60 56 InterpolationOp // \() 61 57 ··· 80 76 token.SUB: SubtractOp, // - 81 77 token.MUL: MultiplyOp, // * 82 78 token.QUO: FloatQuotientOp, // / 83 - 84 - token.IDIV: IntDivideOp, // div 85 - token.IMOD: IntModuloOp, // mod 86 - token.IQUO: IntQuotientOp, // quo 87 - token.IREM: IntRemainderOp, // rem 88 79 89 80 token.LAND: BoolAndOp, // && 90 81 token.LOR: BoolOrOp, // ||
+4 -8
internal/core/adt/op_string.go
··· 30 30 _ = x[SubtractOp-19] 31 31 _ = x[MultiplyOp-20] 32 32 _ = x[FloatQuotientOp-21] 33 - _ = x[IntQuotientOp-22] 34 - _ = x[IntRemainderOp-23] 35 - _ = x[IntDivideOp-24] 36 - _ = x[IntModuloOp-25] 37 - _ = x[InterpolationOp-26] 38 - _ = x[SpreadOp-27] 33 + _ = x[InterpolationOp-22] 34 + _ = x[SpreadOp-23] 39 35 } 40 36 41 - const _Op_name = "NoOp&|.[][:]()&&||==!!=<<=>>==~!~+-*/quoremdivmod\\()..." 37 + const _Op_name = "NoOp&|.[][:]()&&||==!!=<<=>>==~!~+-*/\\()..." 42 38 43 - var _Op_index = [...]uint8{0, 4, 5, 6, 7, 9, 12, 14, 16, 18, 20, 21, 23, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 40, 43, 46, 49, 52, 55} 39 + var _Op_index = [...]uint8{0, 4, 5, 6, 7, 9, 12, 14, 16, 18, 20, 21, 23, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 40, 43} 44 40 45 41 func (i Op) String() string { 46 42 idx := int(i) - 0
-9
tools/fix/fix.go
··· 142 142 switch n := n.(type) { 143 143 case *ast.BinaryExpr: 144 144 switch n.Op { 145 - case token.IDIV, token.IMOD, token.IQUO, token.IREM: 146 - // Rewrite integer division operations to use builtins. 147 - ast.SetRelPos(n.X, token.NoSpace) 148 - c.Replace(&ast.CallExpr{ 149 - // Use the __foo version to prevent accidental shadowing. 150 - Fun: ast.NewIdent("__" + n.Op.String()), 151 - Args: []ast.Expr{n.X, n.Y}, 152 - }) 153 - 154 145 case token.ADD, token.MUL: 155 146 // The fix here only works when at least one argument is a 156 147 // literal list. It would be better to be able to use CUE
-18
tools/fix/fix_test.go
··· 30 30 exps []string 31 31 }{ 32 32 { 33 - name: "rewrite integer division", 34 - in: `package foo 35 - 36 - a: 1 div 2 37 - b: 3 mod 5 38 - c: 2 quo 9 39 - d: 1.0 rem 1.0 // pass on illegal values. 40 - `, 41 - out: `package foo 42 - 43 - a: __div(1, 2) 44 - b: __mod(3, 5) 45 - c: __quo(2, 9) 46 - d: __rem(1.0, 1.0) // pass on illegal values. 47 - `, 48 - }, 49 - 50 - { 51 33 name: "simplify literal tops", 52 34 simplify: true, 53 35 in: `