Commit 82ebe7d
committed
fix lex_number for leading-zero handling and digit separators in fraction
There are some cases which are a little strange but lexically valid.
- `1.2.3.4` lexically this tokenises as `1.2` DOT `3.4`, because a dot
in the fractional or exponent part of a number is simply treated the
same as any other possible terminating character (any character that
isn't part of the valid number lexical syntax)
- `1e2.34` lexically is `1e2` DOT `34` (same as the first case)
- `1e2e34` lexically is `1e2` (number) `e34` (identifier)
These behaviours are basically preserved/extrapolated in the case of
digit separators, so for example `1_2.3_4.5_6` is lexically parsed
as `12.34` DOT `56`. And `1e2_3e4` is lexically parsed as
`1e23` (number), `e4` (identifier). These both look very confusing,
but it probably doesn't matter because those token sequences are,
I think, not valid syntactically so they'll just be rejected by
the parser.
Note that in JSON (and jsonnet), leading zeros are not allowed in
numeric literals. This behaviour is explicitly kept with digit
separators, so `0_5` is explicitly rejected. The alternatives are:
- Treat underscore after an initial zero the same as any terminator
character, so `0_5` lexes as tokens `0` followed by identifier `_5`.
- Allow underscore, thereby breaking the no-leading-zeros rule, so
`0_5` tokenises as `05`.
Either option seems confusing, hence it seems better to explicitly
reject an underscore after an initial zero.1 parent 7784da1 commit 82ebe7d
2 files changed
+61
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | | - | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
269 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
| |||
290 | 295 | | |
291 | 296 | | |
292 | 297 | | |
293 | | - | |
| 298 | + | |
294 | 299 | | |
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
298 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
299 | 326 | | |
300 | 327 | | |
301 | 328 | | |
| |||
333 | 360 | | |
334 | 361 | | |
335 | 362 | | |
336 | | - | |
| 363 | + | |
337 | 364 | | |
338 | 365 | | |
339 | 366 | | |
340 | 367 | | |
341 | 368 | | |
342 | | - | |
| 369 | + | |
343 | 370 | | |
344 | 371 | | |
345 | 372 | | |
| |||
351 | 378 | | |
352 | 379 | | |
353 | 380 | | |
354 | | - | |
| 381 | + | |
355 | 382 | | |
356 | 383 | | |
357 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
118 | 130 | | |
119 | 131 | | |
120 | 132 | | |
| |||
131 | 143 | | |
132 | 144 | | |
133 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
134 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
135 | 163 | | |
136 | 164 | | |
137 | 165 | | |
| |||
0 commit comments