1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2026 Hemashushu <hippospark@gmail.com>, All rights reserved.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License version 2.0 and additional exceptions.
// For more details, see the LICENSE, LICENSE.additional, and CONTRIBUTING files.
use ;
use crateRange;
// Tokens for number literals.
//
// Note that the sign token (minus `-` and plus `+`) is not part of the `NumberToken` in
// the first stage of lexing. For example, `-128` is tokenized into two tokens:
//
// - `Token::Minus`
// - `Token::Number(NumberToken::I8(128))`
//
// Since `128` overflows `i8`, so using `u8` to represent the value part.
// After normalization, the sign token is merged into the `NumberToken`,
// so `-128` will be normalized to `Token::Number(NumberToken::I8(128))`.
// Where `128` is Two's Complement Representation of `-128` in `i8`.
//
// Another example, `-3` is tokenized into two tokens:
// - `Token::Minus`
// - `Token::Number(NumberToken::I32(3))`
//
// After normalization, it will be normalized to `Token::Number(NumberToken::I32(253))`.
// Where `253` is Two's Complement Representation of `-3` in `i32`.
//
// The reason for this design is that it simplifies the lexing process, as we can first tokenize
// the number literal without worrying about the sign and the valid range.