this repo has no description
0
fork

Configure Feed

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

cue/scanner: fix JSON compliance

Exponents with a captial 'E' were not handled
correctly.

Disallow multipliers ending with E, Y, or Z for
now to somplify implementation.

The formatter now rewrites a capital E in
exponents to e.

Change-Id: I1b1342e995b3f6f71d5700807feb5c672b010eca
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3481
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+53 -10
+1
cue/format/format_test.go
··· 194 194 {"comments.input", "comments.golden", 0}, 195 195 {"simplify.input", "simplify.golden", simplify}, 196 196 {"expressions.input", "expressions.golden", 0}, 197 + {"values.input", "values.golden", 0}, 197 198 {"imports.input", "imports.golden", sortImps}, 198 199 } 199 200
+5
cue/format/printer.go
··· 17 17 import ( 18 18 "fmt" 19 19 "os" 20 + "strings" 20 21 "text/tabwriter" 21 22 22 23 "cuelang.org/go/cue/ast" ··· 113 114 data[0] == '0' && 114 115 data[1] >= '0' && data[1] <= '9' { 115 116 data = "0o" + data[1:] 117 + } 118 + case token.FLOAT: 119 + if strings.IndexByte(data, 'E') != -1 { 120 + data = strings.ToLower(data) 116 121 } 117 122 } 118 123
+6
cue/format/testdata/values.golden
··· 1 + a: 0e+1 2 + a: 0e1 3 + a: 0e+1 4 + a: 0e1 5 + a: .3e+1 6 + a: .3e+1
+6
cue/format/testdata/values.input
··· 1 + a: 0e+1 2 + a: 0e1 3 + a: 0E+1 4 + a: 0E1 5 + a: .3e+1 6 + a: .3E+1
+13 -5
cue/lit.go
··· 264 264 default: 265 265 // int (base 8 or 10) or float 266 266 p.scanMantissa(8) 267 - if p.ch == '.' || p.ch == 'e' || p.ch == '8' || p.ch == '9' { 267 + if p.ch == '8' || p.ch == '9' { 268 268 p.scanMantissa(10) 269 - if p.ch != '.' && p.ch != 'e' { 270 - return p.error(p.node, "illegal octal number %q", p.src) 269 + if p.ch != '.' && p.ch != 'e' && p.ch != 'E' { 270 + return p.error(p.node, "illegal integer number %q", p.src) 271 271 } 272 + } 273 + switch p.ch { 274 + case 'e', 'E': 275 + if len(p.buf) == 0 { 276 + p.buf = append(p.buf, '0') 277 + } 278 + fallthrough 279 + case '.': 272 280 goto fraction 273 281 } 274 282 if len(p.buf) > 0 { ··· 295 303 296 304 exponent: 297 305 switch p.ch { 298 - case 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y': 306 + case 'K', 'M', 'G', 'T', 'P': 299 307 mul := charToMul[p.ch] 300 308 p.next() 301 309 if p.ch == 'i' { ··· 315 323 } 316 324 return n 317 325 318 - case 'e': 326 + case 'e', 'E': 319 327 isFloat = true 320 328 p.next() 321 329 p.buf = append(p.buf, 'e')
+7
cue/lit_test.go
··· 137 137 {"1.3e+20", mkFloat("1.3e+20")}, 138 138 {"1.3e20", mkFloat("1.3e+20")}, 139 139 {"1.3e-5", mkFloat("1.3e-5")}, 140 + {".3e-1", mkFloat("0.3e-1")}, 141 + {"0e-5", mkFloat("0e-5")}, 142 + {"0E-5", mkFloat("0e-5")}, 143 + {"5e-5", mkFloat("5e-5")}, 144 + {"5E-5", mkFloat("5e-5")}, 140 145 {"0x1234", mkMul(0x1234, 0, 16)}, 141 146 {"0xABCD", mkMul(0xABCD, 0, 16)}, 142 147 {"0b11001000", mkMul(0xc8, 0, 2)}, ··· 172 177 {`"foo\x00"`}, 173 178 {`0x`}, 174 179 {`0o`}, 180 + {`0b`}, 175 181 {`0_`}, 182 + {"0128"}, 176 183 {``}, 177 184 {`"`}, 178 185 {`"a`},
+3 -4
cue/scanner/scanner.go
··· 393 393 seenDigits = true 394 394 s.scanMantissa(10) 395 395 } 396 - if s.ch == '.' || s.ch == 'e' { 396 + if s.ch == '.' || s.ch == 'e' || s.ch == 'E' { 397 397 goto fraction 398 398 } 399 399 if seenDigits { ··· 425 425 426 426 exponent: 427 427 switch s.ch { 428 - case 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y': 428 + case 'K', 'M', 'G', 'T', 'P': 429 429 tok = token.INT // TODO: Or should we allow this to be a float? 430 430 s.next() 431 431 if s.ch == 'i' { ··· 434 434 goto exit 435 435 } 436 436 437 - // TODO: allow 'E' for exponent? Could be used for Exa 438 - if s.ch == 'e' { // || s.ch == 'E' { 437 + if s.ch == 'e' || s.ch == 'E' { 439 438 tok = token.FLOAT 440 439 s.next() 441 440 if s.ch == '-' || s.ch == '+' {
+7
cue/scanner/scanner_test.go
··· 98 98 {token.FLOAT, "1e0", literal}, 99 99 {token.FLOAT, "1e+100", literal}, 100 100 {token.FLOAT, "1e-100", literal}, 101 + {token.FLOAT, "1E+100", literal}, 102 + {token.FLOAT, "1E-100", literal}, 103 + {token.FLOAT, "0e-5", literal}, 104 + {token.FLOAT, "0e+100", literal}, 105 + {token.FLOAT, "0e-100", literal}, 106 + {token.FLOAT, "0E+100", literal}, 107 + {token.FLOAT, "0E-100", literal}, 101 108 {token.FLOAT, "2.71828e-1000", literal}, 102 109 {token.STRING, "'a'", literal}, 103 110 {token.STRING, "'\\000'", literal},
+5 -1
doc/ref/spec.md
··· 322 322 binary_lit = "0b" binary_digit { binary_digit } . 323 323 hex_lit = "0" ( "x" | "X" ) hex_digit { [ "_" ] hex_digit } . 324 324 octal_lit = "0o" octal_digit { [ "_" ] octal_digit } . 325 - multiplier = ( "K" | "M" | "G" | "T" | "P" | "E" | "Y" | "Z" ) [ "i" ] 325 + multiplier = ( "K" | "M" | "G" | "T" | "P" ) [ "i" ] 326 326 327 327 float_lit = decimals "." [ decimals ] [ exponent ] | 328 328 decimals exponent | 329 329 "." decimals [ exponent ]. 330 330 exponent = ( "e" | "E" ) [ "+" | "-" ] decimals . 331 331 ``` 332 + <!-- 333 + TODO: consider allowing Exo (and up), if not followed by a sign 334 + or number. Alternatively one could only allow Ei, Yi, and Zi. 335 + --> 332 336 333 337 ``` 334 338 42