Commit aec0116
pkg/strconv: add ParseNumber builtin
Expose literal.ParseNum via pkg/strconv so CUE code can parse native
number literals through the standard library. The wrapper returns an
internal.Decimal and surfaces syntax issues as *strconv.NumError,
matching the existing ParseInt/ParseFloat helpers.
The main use case here is being able to parse CUE number strings
such as 1Ki, which are not accepted by strconv.ParseInt.
Moreover, this API accepts both integer and floating point numbers,
so it's a superset of both strconv's ParseInt and ParseFloat.
We choose to name the built-in ParseNumber rather than ParseNum
given that this directly reflects the "number" predeclared identifier
in the CUE spec, so it's best to not shorten that name.
Closes #4139 as merged as of commit ac7daa6.
Signed-off-by: Carlos Jorge <[email protected]>
Change-Id: I1ed97630a24300884588bfdda0130fe40a7e7e2b
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1226125
Reviewed-by: Marcel van Lohuizen <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>1 parent 5e7258e commit aec0116
3 files changed
+62
-0
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
68 | 100 | | |
69 | 101 | | |
70 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
| |||
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
101 | 112 | | |
102 | 113 | | |
103 | 114 | | |
| |||
150 | 161 | | |
151 | 162 | | |
152 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
153 | 171 | | |
154 | 172 | | |
155 | 173 | | |
| |||
0 commit comments