Debian Codegraph @

src/lexer.rs

raw symbols SCIP
1 use craterust-analyzer cargo pp-rs 0.2.1 crate/::tokenrust-analyzer cargo pp-rs 0.2.1 token/::{Floatrust-analyzer cargo pp-rs 0.2.1 token/Float#, Integerrust-analyzer cargo pp-rs 0.2.1 token/Integer#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::Charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Chars#;
3 use unicode_xidrust-analyzer cargo unicode-xid 0.2.6 crate/::UnicodeXIDrust-analyzer cargo unicode-xid 0.2.6 UnicodeXID#;
4
5 type CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine# = (char, u32);
6
7 // GLSL ES 3.20 specification section 3.10. Logical Phases of Compilation
8 // This iterator implements phases 4 and 5 of the logical phases of compilation:
9 //
10 // 4. Each {carriage-return, line-feed} and {line-feed, carriage return} sequence is replaced by
11 // a single newline. All remaining carriage-return and line-feed characters are then each
12 // replaced by a newline.
13 //
14 // 5. Line numbering for each character, which is equal to the number of preceding newlines plus
15 // one, is noted. Note this can only be subsequently changed by the #line directive and is not
16 // affected by the removal of newlines in phase 6 of compilation.
17 //
18 // It expects that phases 1 to 3 are already done and that valid utf8 is passed in.
19 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
20 pub struct CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#<'a> {
21 innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner.: Charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Chars#<'a>,
22 linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line.: u32,
23 }
24
25 impl<'a> CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#<'a> {
26 pub fn newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`] {
27 CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine# {
28 innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner.: input.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().(),
29 linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line.: 1,
30 }
31 }
32
33 pub fn get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`]get_current_ptr().(&self) -> *const u8 {
34 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner..as_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`]as_str().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().()
35 }
36 }
37
38 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#<'a> {
39 type Itemrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Iterator]Item# = CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine#;
40
41 fn nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
42 let current = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
43
44 match current {
45 '\n' => {
46 // Consume the token but see if we can grab a \r that follows
47 let mut peek_inner = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Clone]clone().();
48 if peek_inner.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\r') {
49 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner. = peek_inner;
50 }
51
52 let res = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('\n', self.linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line.));
53 self.linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
54 res
55 }
56 '\r' => {
57 // Consume the token but see if we can grab a \n that follows
58 let mut peek_inner = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Clone]clone().();
59 if peek_inner.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\n') {
60 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#inner. = peek_inner;
61 }
62
63 let res = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('\n', self.linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line.));
64 self.linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
65 res
66 }
67
68 _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((current, self.linerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#line.)),
69 }
70 }
71 }
72
73 // An iterator that adds stage 6 on top of CharsAndLocation:
74 //
75 // 6. Wherever a backslash ('\') occurs immediately before a newline, both are deleted. Note that
76 // no whitespace is substituted, thereby allowing a single preprocessing token to span a
77 // newline. This operation is not recursive; any new {backslash newline} sequences generated
78 // are not removed.
79 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
80 pub struct SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#<'a> {
81 innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner.: CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#<'a>,
82 }
83
84 impl<'a> SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#<'a> {
85 pub fn newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`] {
86 SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline# {
87 innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner.: CharsAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharsAndLine#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`]new().(input),
88 }
89 }
90
91 pub fn get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`]get_current_ptr().(&self) -> *const u8 {
92 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner..get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`]get_current_ptr().()
93 }
94 }
95
96 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#<'a> {
97 type Itemrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]Item# = CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine#;
98
99 fn nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
100 let mut current = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner..nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
101
102 while current.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\\' {
103 let mut peek_inner = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner..clonerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Clone]clone().();
104 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('\n', _)) = peek_inner.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`CharsAndLine<'a>`][Iterator]next().() {
105 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#inner. = peek_inner;
106 current = self.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
107 } else {
108 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current);
109 }
110 }
111
112 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current)
113 }
114 }
115
116 // An iterator that adds stage 7 on top of SkipBackslashNewline:
117 //
118 // 7. All comments are replaced with a single space. All (non-zero) characters and invalid UTF-8
119 // byte sequences are allowed within comments. '//' style comments include the initial '//'
120 // marker and continue up to, but not including, the terminating newline. '/…/' comments
121 // include both the start and end marker.
122 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
123 pub struct ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#<'a> {
124 innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner.: SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#<'a>,
125 }
126
127 // The lexer wants to know when whitespace is a comment to know if a comment was ever processed.
128 // To avoid adding state we use a sentinel value of '\r' because all '\r' have been consumed and
129 // turned into '\n' by CharsAndLocation.
130 pub const COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE.: char = '\r';
131
132 impl<'a> ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#<'a> {
133 pub fn newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`] {
134 ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments# {
135 innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner.: SkipBackslashNewlinerust-analyzer cargo pp-rs 0.2.1 lexer/SkipBackslashNewline#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`]new().(input),
136 }
137 }
138
139 pub fn get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`]get_current_ptr().(&self) -> *const u8 {
140 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner..get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`]get_current_ptr().()
141 }
142 }
143
144 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#<'a> {
145 type Itemrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`][Iterator]Item# = CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine#;
146
147 fn nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
148 let current = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner..nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
149
150 if current.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'/' {
151 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(current.0 != COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE.);
152 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current);
153 }
154
155 let mut peek_inner = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner..clonerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Clone]clone().();
156 match peek_inner.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().() {
157 // The // case, consume until but not including the next \n
158 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('/', _)) => {
159 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner. = peek_inner.clonerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Clone]clone().();
160 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((next, _)) = peek_inner.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().() {
161 if next rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n' {
162 break;
163 }
164 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner. = peek_inner.clonerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Clone]clone().();
165 }
166
167 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE., current.1))
168 }
169 // The /*, consume until the next */
170 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('*', _)) => {
171 let mut was_star = false;
172 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((next, _)) = peek_inner.nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`SkipBackslashNewline<'a>`][Iterator]next().() {
173 if was_star && next rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'/' {
174 break;
175 }
176 was_star = next rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'*';
177 }
178 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#inner. = peek_inner;
179
180 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE., current.1))
181 }
182
183 // Not // or /*, do nothing
184 _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current),
185 }
186 }
187 }
188
189 // A lexer for GLSL tokens that also emits a couple extra tokens that are useful to the
190 // preprocessor: # and newlines. It also include metadata for the token for whether it is at the
191 // start of the line, or if it has leading whitespace.
192
193 // This is a helper iterator to abstract away the tracking of location data (offset, line) from
194 // `Lexer`. It looks like a Peekable<Iterator<char>> with `next_char` and `peek_char` but also
195 // allows querying the last seen/consumed lines / offset.
196 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
197 struct LexerCharIteratorrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#<'a> {
198 innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner.: ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#<'a>,
199 peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine#, *const u8)>,
200 last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed.: (CharAndLinerust-analyzer cargo pp-rs 0.2.1 lexer/CharAndLine#, *const u8),
201 input_startrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#input_start.: *const u8,
202 }
203
204 pub const NONE_CONSUMED_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/NONE_CONSUMED_SENTINEL_VALUE.: char = '\r';
205
206 impl<'a> LexerCharIteratorrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#<'a> {
207 pub fn newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`] {
208 LexerCharIteratorrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator# {
209 innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner.: ReplaceCommentsrust-analyzer cargo pp-rs 0.2.1 lexer/ReplaceComments#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`]new().(input),
210 peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
211 last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed.: ((NONE_CONSUMED_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/NONE_CONSUMED_SENTINEL_VALUE., 0), input.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()),
212 input_startrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#input_start.: input.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().(),
213 }
214 }
215 fn next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> {
216 self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed. = match self.peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
217 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v,
218 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
219 let ptr = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner..get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`]get_current_ptr().();
220 (self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner..nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()., ptr)
221 }
222 };
223 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed..0 .0)
224 }
225
226 fn peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> {
227 match self.peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked. {
228 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v.0 .0),
229 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
230 let ptr = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner..get_current_ptrrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`]get_current_ptr().();
231 let next = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#inner..nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`ReplaceComments<'a>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
232 self.peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((next, ptr));
233 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next.0)
234 }
235 }
236 }
237
238 fn get_last_seen_linerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_seen_line().(&self) -> u32 {
239 self.peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed.).0 .1
240 }
241
242 fn get_last_seen_start_offsetrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_seen_start_offset().(&self) -> usize {
243 self.peekedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#peeked..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed.).1 as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.input_startrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#input_start. as usize
244 }
245
246 fn get_last_consumed_end_offsetrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_consumed_end_offset().(&self) -> usize {
247 self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed..1 as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.input_startrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#input_start. as usize
248 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.last_consumedrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#last_consumed..0 .0.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().()
249 }
250 }
251
252 // A superset of the token value returned by the preprocessor
253 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
254 pub enum TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue# {
255 // Preprocessor specific token values
256 Hashrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Hash#,
257 NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#,
258
259 // Regular token values
260 Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
261 Integerrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Integer#(Integerrust-analyzer cargo pp-rs 0.2.1 token/Integer#),
262 Floatrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Float#(Floatrust-analyzer cargo pp-rs 0.2.1 token/Float#),
263 Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#),
264 }
265
266 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#> for TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue# {
267 fn fromrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`From<Punct>`]from().(punct: Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[TokenValue][`From<Punct>`] {
268 TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(punct)
269 }
270 }
271
272 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
273 pub struct Tokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token# {
274 pub valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#,
275 pub locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#,
276 pub leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Token#leading_whitespace.: bool,
277 pub start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Token#start_of_line.: bool,
278 }
279
280 pub type LexerItemrust-analyzer cargo pp-rs 0.2.1 lexer/LexerItem# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Tokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token#, (PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#, Locationrust-analyzer cargo pp-rs 0.2.1 token/Location#)>;
281 pub struct Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#<'a> {
282 innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner.: LexerCharIteratorrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#<'a>,
283 leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace.: bool,
284 start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line.: bool,
285 had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#had_comments.: bool,
286 }
287
288 impl<'a> Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#<'a> {
289 pub fn newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`] {
290 // TODO bail out on source that is too large.
291 Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer# {
292 innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner.: LexerCharIteratorrust-analyzer cargo pp-rs 0.2.1 lexer/LexerCharIterator#::newrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]new().(input),
293 leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace.: true,
294 start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line.: true,
295 had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#had_comments.: false,
296 }
297 }
298
299 pub fn had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]had_comments().(&self) -> bool {
300 self.had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#had_comments.
301 }
302
303 // TODO: Make a runtime flag to toggle unicode identifiers support
304 // The glsl spec only allows ascii identifiers
305 fn parse_identifierrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_identifier().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#> {
306 let mut identifier = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().();
307
308 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = self.next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(|c| c.is_xid_startrust-analyzer cargo unicode-xid 0.2.6 impl#[char][UnicodeXID]is_xid_start().() || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'_') {
309 identifier.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c);
310 }
311
312 let rest = self.consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(|c| c.is_xid_continuerust-analyzer cargo unicode-xid 0.2.6 impl#[char][UnicodeXID]is_xid_continue().());
313 identifier.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&rest);
314
315 // TODO check if identifier is larger than the limit.
316 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Identrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Ident#(identifier))
317 }
318
319 fn parse_integer_signedness_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_integer_signedness_suffix().(&mut self) -> bool {
320 self.next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'u' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'U').is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
321 }
322
323 fn parse_integer_width_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_integer_width_suffix().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i32, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#> {
324 match self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
325 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('l') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('L') => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::NotSupported64BitLiteralrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#NotSupported64BitLiteral#),
326 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('s') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('S') => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::NotSupported16BitLiteralrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#NotSupported16BitLiteral#),
327 _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(32),
328 }
329 }
330
331 fn parse_float_width_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_float_width_suffix().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i32, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#> {
332 match self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
333 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('l') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('L') => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::NotSupported64BitLiteralrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#NotSupported64BitLiteral#),
334 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('h') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('H') => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::NotSupported16BitLiteralrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#NotSupported16BitLiteral#),
335 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('f') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('F') => {
336 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
337 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(32)
338 }
339 _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(32),
340 }
341 }
342
343 fn next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(&mut self, predicate: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(char) -> bool) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> {
344 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
345 if predicate(c) {
346 return self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
347 }
348 }
349 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
350 }
351
352 fn consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(&mut self, filter: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(char) -> bool) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
353 let mut result: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().();
354 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = self.next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(&filter) {
355 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c);
356 }
357 result
358 }
359
360 fn parse_numberrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_number().(&mut self, first_char: char) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#> {
361 let mut is_float = false;
362 let mut integer_radix = 10;
363 let mut raw: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().();
364 raw.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(first_char);
365
366 // Handle hexadecimal numbers that needs to consume a..f in addition to digits.
367 if first_char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'0' {
368 match self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
369 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('x') | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('X') => {
370 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
371
372 raw rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&self.consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(|c| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, '0'..='9' | 'a'..='f' | 'A'..='F'));
373 integer_radix = 16;
374 }
375
376 // Octal numbers can also be the prefix of floats, so we need to parse all digits
377 // and not just 0..7 in case it is a float like 00009.0f, the parsing of all digits
378 // is done below, but we still need to remember the radix.
379 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9') => {
380 integer_radix = 8;
381 }
382 _ => {}
383 };
384 }
385
386 if first_char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.' {
387 is_float = true;
388 } else {
389 // Parse any digits at the end of integers, or for the non-fractional part of floats.
390 raw rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&self.consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(|c| ('0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9').containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&c));
391
392 if self.next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.').is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
393 raw.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('.');
394 is_float = true;
395 }
396 }
397
398 // At this point either we're an integer missing only suffixes, or we're a float with
399 // everything up to the . consumed.
400 if is_float {
401 raw rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&self.consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(|c| ('0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9').containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&c));
402 }
403
404 // Handle scientific notation with a (e|E)(+|-|)\d+ suffix when we're a float or an
405 // an integer that could turn into a float if we add a exponent to it (so 0x1E-1
406 // isn't recognized as a float).
407 if (is_float || integer_radix rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().8 || integer_radix rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().10)
408 && self.next_char_ifrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]next_char_if().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'e' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'E').is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()
409 {
410 raw.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('e');
411 is_float = true;
412
413 match self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
414 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('+') => {
415 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
416 raw.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('+');
417 }
418 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('-') => {
419 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
420 raw.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
421 }
422 _ => {}
423 }
424
425 // TODO: what should we do when there is no number after the exponent?
426 raw rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&self.consume_charsrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]consume_chars().(|c| ('0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9').containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&c));
427 }
428
429 if is_float {
430 // TODO: Depending on the GLSL version make it an error to not have the suffix.
431 let width = self.parse_float_width_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_float_width_suffix().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
432
433 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Floatrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Float#(Floatrust-analyzer cargo pp-rs 0.2.1 token/Float# {
434 valuerust-analyzer cargo pp-rs 0.2.1 token/Float#value.: raw
435 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f32>()
436 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::FloatParsingErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#FloatParsingError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
437 widthrust-analyzer cargo pp-rs 0.2.1 token/Float#width.,
438 }))
439 } else {
440 let signed = self.parse_integer_signedness_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_integer_signedness_suffix().();
441 let width = self.parse_integer_width_suffixrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_integer_width_suffix().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
442
443 // Skip the initial 0 in hexa or octal (in hexa we never added the 'x').
444 if integer_radix rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().10 {
445 raw = raw.split_offrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]split_off().(1);
446 }
447
448 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Integerrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Integer#(Integerrust-analyzer cargo pp-rs 0.2.1 token/Integer# {
449 valuerust-analyzer cargo pp-rs 0.2.1 token/Integer#value.: u64::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_str_radix().(&raw, integer_radix)
450 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_err| PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::IntegerOverflowrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#IntegerOverflow#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
451 signedrust-analyzer cargo pp-rs 0.2.1 token/Integer#signed.,
452 widthrust-analyzer cargo pp-rs 0.2.1 token/Integer#width.,
453 }))
454 }
455 }
456
457 fn parse_punctuationrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_punctuation().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#, PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#> {
458 let save_point = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..clonerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`][Clone]clone().();
459
460 let char0 = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().('\0');
461 let char1 = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().('\0');
462 let char2 = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().('\0');
463
464 let maybe_punct = match (char0, char1, char2) {
465 ('<', '<', '=') => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftShiftAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftShiftAssign#, 3)),
466 ('<', '<', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftShiftrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftShift#, 2)),
467 ('<', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LessEqualrust-analyzer cargo pp-rs 0.2.1 token/Punct#LessEqual#, 2)),
468 ('<', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftAnglerust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftAngle#, 1)),
469
470 ('>', '>', '=') => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightShiftAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightShiftAssign#, 3)),
471 ('>', '>', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightShiftrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightShift#, 2)),
472 ('>', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::GreaterEqualrust-analyzer cargo pp-rs 0.2.1 token/Punct#GreaterEqual#, 2)),
473 ('>', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightAnglerust-analyzer cargo pp-rs 0.2.1 token/Punct#RightAngle#, 1)),
474
475 ('+', '+', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Incrementrust-analyzer cargo pp-rs 0.2.1 token/Punct#Increment#, 2)),
476 ('+', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::AddAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#AddAssign#, 2)),
477 ('+', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Plusrust-analyzer cargo pp-rs 0.2.1 token/Punct#Plus#, 1)),
478
479 ('-', '-', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Decrementrust-analyzer cargo pp-rs 0.2.1 token/Punct#Decrement#, 2)),
480 ('-', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::SubAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#SubAssign#, 2)),
481 ('-', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Minusrust-analyzer cargo pp-rs 0.2.1 token/Punct#Minus#, 1)),
482
483 ('&', '&', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LogicalAndrust-analyzer cargo pp-rs 0.2.1 token/Punct#LogicalAnd#, 2)),
484 ('&', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::AndAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#AndAssign#, 2)),
485 ('&', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Ampersandrust-analyzer cargo pp-rs 0.2.1 token/Punct#Ampersand#, 1)),
486
487 ('|', '|', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LogicalOrrust-analyzer cargo pp-rs 0.2.1 token/Punct#LogicalOr#, 2)),
488 ('|', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::OrAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#OrAssign#, 2)),
489 ('|', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Piperust-analyzer cargo pp-rs 0.2.1 token/Punct#Pipe#, 1)),
490
491 ('^', '^', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LogicalXorrust-analyzer cargo pp-rs 0.2.1 token/Punct#LogicalXor#, 2)),
492 ('^', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::XorAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#XorAssign#, 2)),
493 ('^', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Caretrust-analyzer cargo pp-rs 0.2.1 token/Punct#Caret#, 1)),
494
495 ('=', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::EqualEqualrust-analyzer cargo pp-rs 0.2.1 token/Punct#EqualEqual#, 2)),
496 ('=', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Equalrust-analyzer cargo pp-rs 0.2.1 token/Punct#Equal#, 1)),
497 ('!', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::NotEqualrust-analyzer cargo pp-rs 0.2.1 token/Punct#NotEqual#, 2)),
498 ('!', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Bangrust-analyzer cargo pp-rs 0.2.1 token/Punct#Bang#, 1)),
499
500 ('*', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::MulAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#MulAssign#, 2)),
501 ('*', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Starrust-analyzer cargo pp-rs 0.2.1 token/Punct#Star#, 1)),
502 ('/', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::DivAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#DivAssign#, 2)),
503 ('/', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Slashrust-analyzer cargo pp-rs 0.2.1 token/Punct#Slash#, 1)),
504 ('%', '=', _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::ModAssignrust-analyzer cargo pp-rs 0.2.1 token/Punct#ModAssign#, 2)),
505 ('%', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Percentrust-analyzer cargo pp-rs 0.2.1 token/Punct#Percent#, 1)),
506
507 ('(', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftParen#, 1)),
508 (')', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightParenrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightParen#, 1)),
509 ('{', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftBracerust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftBrace#, 1)),
510 ('}', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightBracerust-analyzer cargo pp-rs 0.2.1 token/Punct#RightBrace#, 1)),
511 ('[', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::LeftBracketrust-analyzer cargo pp-rs 0.2.1 token/Punct#LeftBracket#, 1)),
512 (']', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::RightBracketrust-analyzer cargo pp-rs 0.2.1 token/Punct#RightBracket#, 1)),
513
514 (',', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Commarust-analyzer cargo pp-rs 0.2.1 token/Punct#Comma#, 1)),
515 (';', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Semicolonrust-analyzer cargo pp-rs 0.2.1 token/Punct#Semicolon#, 1)),
516 (':', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Colonrust-analyzer cargo pp-rs 0.2.1 token/Punct#Colon#, 1)),
517 ('~', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Tilderust-analyzer cargo pp-rs 0.2.1 token/Punct#Tilde#, 1)),
518 ('?', _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Questionrust-analyzer cargo pp-rs 0.2.1 token/Punct#Question#, 1)),
519 // Note that Dot (".") is handled in Lexer::next since it can be
520 // either punctuation or the start of a floating point number.
521 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
522 };
523
524 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((punct, size)) = maybe_punct {
525 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner. = save_point;
526 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#size {
527 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
528 }
529 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(punct.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
530 } else if char0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'#' {
531 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner. = save_point;
532 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
533 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Hashrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Hash#)
534 } else {
535 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PreprocessorErrorrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#::UnexpectedCharacterrust-analyzer cargo pp-rs 0.2.1 token/PreprocessorError#UnexpectedCharacter#)
536 }
537 }
538 }
539
540 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Lexerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#<'a> {
541 type Itemrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`][Iterator]Item# = LexerItemrust-analyzer cargo pp-rs 0.2.1 lexer/LexerItem#;
542
543 fn nextrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
544 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current_char) = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
545 let had_leading_whitespace = self.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace.;
546 self.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace. = false;
547
548 let mut location = Locationrust-analyzer cargo pp-rs 0.2.1 token/Location# {
549 linerust-analyzer cargo pp-rs 0.2.1 token/Location#line.: self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..get_last_seen_linerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_seen_line().(),
550 startrust-analyzer cargo pp-rs 0.2.1 token/Location#start.: self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..get_last_seen_start_offsetrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_seen_start_offset().() as u32,
551 endrust-analyzer cargo pp-rs 0.2.1 token/Location#end.: 0,
552 };
553
554 let was_start_of_line = self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line.;
555 self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line. = false;
556
557 let value = match current_char {
558 ' ' | '\t' | '\x0b' | '\x0c' | COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE. => {
559 if current_char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().COMMENT_SENTINEL_VALUErust-analyzer cargo pp-rs 0.2.1 lexer/COMMENT_SENTINEL_VALUE. {
560 self.had_commentsrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#had_comments. = true;
561 }
562 self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line. = was_start_of_line;
563 self.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace. = true;
564 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
565 continue;
566 }
567 '\n' => {
568 self.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace. = true;
569 self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line. = true;
570 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
571 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#)
572 }
573
574 c @ '0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9' => {
575 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
576 self.parse_numberrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_number().(c)
577 }
578
579 // Special case . as a punctuation because it can be the start of a float.
580 '.' => {
581 self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..next_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]next_char().();
582
583 match self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..peek_charrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]peek_char().() {
584 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9') => self.parse_numberrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_number().('.'),
585 _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::Punctrust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#Punct#(Punctrust-analyzer cargo pp-rs 0.2.1 token/Punct#::Dotrust-analyzer cargo pp-rs 0.2.1 token/Punct#Dot#)),
586 }
587 }
588 _ => {
589 // TODO: see todo in `parse_identifier` for information
590 if current_char.is_xid_startrust-analyzer cargo unicode-xid 0.2.6 impl#[char][UnicodeXID]is_xid_start().() || current_char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'_' {
591 self.parse_identifierrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_identifier().()
592 } else {
593 self.parse_punctuationrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`Lexer<'a>`]parse_punctuation().()
594 }
595 }
596 };
597
598 location.endrust-analyzer cargo pp-rs 0.2.1 token/Location#end. = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..get_last_consumed_end_offsetrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_consumed_end_offset().() as u32;
599
600 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| (e, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo pp-rs 0.2.1 token/impl#[Location][Default]default().())).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|t| Tokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token# {
601 valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value.: t,
602 locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.,
603 leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Token#leading_whitespace.: had_leading_whitespace,
604 start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Token#start_of_line.: was_start_of_line,
605 }));
606 }
607
608 // Do the C hack of always ending with a newline so that preprocessor directives are ended.
609 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line. {
610 self.start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#start_of_line. = true;
611
612 let end_offset = self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..get_last_consumed_end_offsetrust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_consumed_end_offset().() as u32;
613
614 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Tokenrust-analyzer cargo pp-rs 0.2.1 lexer/Token# {
615 valuerust-analyzer cargo pp-rs 0.2.1 lexer/Token#value.: TokenValuerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#::NewLinerust-analyzer cargo pp-rs 0.2.1 lexer/TokenValue#NewLine#,
616 locationrust-analyzer cargo pp-rs 0.2.1 lexer/Token#location.: Locationrust-analyzer cargo pp-rs 0.2.1 token/Location# {
617 linerust-analyzer cargo pp-rs 0.2.1 token/Location#line.: self.innerrust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#inner..get_last_seen_linerust-analyzer cargo pp-rs 0.2.1 lexer/impl#[`LexerCharIterator<'a>`]get_last_seen_line().(),
618 startrust-analyzer cargo pp-rs 0.2.1 token/Location#start.: end_offset,
619 endrust-analyzer cargo pp-rs 0.2.1 token/Location#end.: end_offset,
620 },
621 leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Token#leading_whitespace.: self.leading_whitespacerust-analyzer cargo pp-rs 0.2.1 lexer/Lexer#leading_whitespace.,
622 start_of_linerust-analyzer cargo pp-rs 0.2.1 lexer/Token#start_of_line.: false,
623 }))
624 } else {
625 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
626 }
627 }
628 }