|
1 | 1 | use glsl_lang::ast::SmolStr;
|
2 | 2 | use petgraph::graph::NodeIndex;
|
3 | 3 |
|
4 |
| -#[derive(Clone, Copy)] |
5 |
| -enum ExtractIdentState { |
6 |
| - Init, |
7 |
| - Ident { start_position: usize }, |
8 |
| -} |
9 |
| - |
10 |
| -pub struct ExtractIdents<'i> { |
11 |
| - input: &'i str, |
12 |
| - current_position: usize, |
13 |
| - state: ExtractIdentState, |
14 |
| -} |
15 |
| - |
16 |
| -impl<'i> Iterator for ExtractIdents<'i> { |
17 |
| - type Item = &'i str; |
18 |
| - |
19 |
| - fn next(&mut self) -> Option<Self::Item> { |
20 |
| - // The rest of the string that wasn't parsed yet |
21 |
| - let remaining = &self.input[self.current_position..]; |
22 |
| - |
23 |
| - let mut last_index = self.current_position; |
24 |
| - |
25 |
| - for (i, ch) in remaining.char_indices() { |
26 |
| - self.current_position = i; |
27 |
| - |
28 |
| - match self.state { |
29 |
| - ExtractIdentState::Init => { |
30 |
| - // Initial state, look for a valid char |
31 |
| - if ch == '_' || ch.is_ascii_lowercase() || ch.is_ascii_uppercase() { |
32 |
| - self.state = ExtractIdentState::Ident { start_position: i }; |
33 |
| - } |
34 |
| - } |
35 |
| - ExtractIdentState::Ident { start_position } => { |
36 |
| - // First char seen, look for following chars |
37 |
| - if ch == '_' |
38 |
| - || ch.is_ascii_lowercase() |
39 |
| - || ch.is_ascii_uppercase() |
40 |
| - || ch.is_ascii_digit() |
41 |
| - { |
42 |
| - // Stay in the current state |
43 |
| - self.state = ExtractIdentState::Ident { start_position }; |
44 |
| - } else { |
45 |
| - // Not an ident, reset state |
46 |
| - self.state = ExtractIdentState::Init; |
47 |
| - |
48 |
| - // Return ident slice |
49 |
| - return Some(&self.input[start_position..=last_index]); |
50 |
| - } |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - last_index = i; |
55 |
| - } |
56 |
| - |
57 |
| - None |
58 |
| - } |
59 |
| -} |
60 |
| - |
61 | 4 | #[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
62 | 5 | pub enum ExternalIdentifier {
|
63 | 6 | /// Function definition
|
|
0 commit comments