Debian Codegraph @

third_party/rust/naga/src/front/glsl/token.rs

raw
1 pub use pp_rs::token::{Float, Integer, Location, Token as PPToken};
2
3 use alloc::{string::String, vec::Vec};
4
5 use super::ast::Precision;
6 use crate::{Interpolation, Sampling, Span, Type};
7
8 impl From<Location> for Span {
9 fn from(loc: Location) -> Self {
10 Span::new(loc.start, loc.end)
11 }
12 }
13
14 #[derive(Debug)]
15 #[cfg_attr(test, derive(PartialEq))]
16 pub struct Token {
17 pub value: TokenValue,
18 pub meta: Span,
19 }
20
21 /// A token passed from the lexing used in the parsing.
22 ///
23 /// This type is exported since it's returned in the
24 /// [`InvalidToken`](super::ErrorKind::InvalidToken) error.
25 #[derive(Clone, Debug, PartialEq)]
26 pub enum TokenValue {
27 Identifier(String),
28
29 FloatConstant(Float),
30 IntConstant(Integer),
31 BoolConstant(bool),
32
33 Layout,
34 In,
35 Out,
36 InOut,
37 Uniform,
38 Buffer,
39 Const,
40 Shared,
41
42 Restrict,
43 /// A `glsl` memory qualifier such as `writeonly`
44 ///
45 /// The associated [`crate::StorageAccess`] is the access being allowed
46 /// (for example `writeonly` has an associated value of [`crate::StorageAccess::STORE`])
47 MemoryQualifier(crate::StorageAccess),
48
49 Invariant,
50 Interpolation(Interpolation),
51 Sampling(Sampling),
52 Precision,
53 PrecisionQualifier(Precision),
54
55 Continue,
56 Break,
57 Return,
58 Discard,
59
60 If,
61 Else,
62 Switch,
63 Case,
64 Default,
65 While,
66 Do,
67 For,
68
69 Void,
70 Struct,
71 TypeName(Type),
72
73 Assign,
74 AddAssign,
75 SubAssign,
76 MulAssign,
77 DivAssign,
78 ModAssign,
79 LeftShiftAssign,
80 RightShiftAssign,
81 AndAssign,
82 XorAssign,
83 OrAssign,
84
85 Increment,
86 Decrement,
87
88 LogicalOr,
89 LogicalAnd,
90 LogicalXor,
91
92 LessEqual,
93 GreaterEqual,
94 Equal,
95 NotEqual,
96
97 LeftShift,
98 RightShift,
99
100 LeftBrace,
101 RightBrace,
102 LeftParen,
103 RightParen,
104 LeftBracket,
105 RightBracket,
106 LeftAngle,
107 RightAngle,
108
109 Comma,
110 Semicolon,
111 Colon,
112 Dot,
113 Bang,
114 Dash,
115 Tilde,
116 Plus,
117 Star,
118 Slash,
119 Percent,
120 VerticalBar,
121 Caret,
122 Ampersand,
123 Question,
124 }
125
126 #[derive(Debug)]
127 #[cfg_attr(test, derive(PartialEq))]
128 pub struct Directive {
129 pub kind: DirectiveKind,
130 pub tokens: Vec<PPToken>,
131 }
132
133 #[derive(Debug)]
134 #[cfg_attr(test, derive(PartialEq))]
135 pub enum DirectiveKind {
136 Version { is_first_directive: bool },
137 Extension,
138 Pragma,
139 }