Debian Codegraph @

src/token.rs

raw symbols SCIP
1 //TODO: Source file
2 #[derive(Clone, Copy, PartialEq, Debug)]
3 pub struct Location {
4 /// Byte offset into the source string where the first char begins
5 pub start: u32,
6 /// Byte offset into the source string where the first char not belonging to
7 /// this `Location` begins
8 pub end: u32,
9 /// used internally in the `#line` directive and the `__LINE__` macro
10 pub(crate) line: u32,
11 }
12
13 impl Default for Location {
14 fn default() -> Self {
15 Location {
16 start: 0,
17 end: 0,
18 line: 1,
19 }
20 }
21 }
22
23 #[derive(Clone, Copy, PartialEq, Debug)]
24 pub enum Punct {
25 // Compound assignments
26 AddAssign,
27 SubAssign,
28 MulAssign,
29 DivAssign,
30 ModAssign,
31 LeftShiftAssign,
32 RightShiftAssign,
33 AndAssign,
34 XorAssign,
35 OrAssign,
36
37 // Two character punctuation
38 Increment,
39 Decrement,
40 LogicalAnd,
41 LogicalOr,
42 LogicalXor,
43 LessEqual,
44 GreaterEqual,
45 EqualEqual,
46 NotEqual,
47 LeftShift,
48 RightShift,
49
50 // Parenthesis or similar
51 LeftBrace,
52 RightBrace,
53 LeftParen,
54 RightParen,
55 LeftBracket,
56 RightBracket,
57
58 // Other one character punctuation
59 LeftAngle,
60 RightAngle,
61 Semicolon,
62 Comma,
63 Colon,
64 Dot,
65 Equal,
66 Bang,
67 Minus,
68 Tilde,
69 Plus,
70 Star,
71 Slash,
72 Percent,
73 Pipe,
74 Caret,
75 Ampersand,
76 Question,
77 }
78
79 #[derive(Clone, PartialEq, Debug)]
80 // TODO location?
81 pub enum PreprocessorError {
82 IntegerOverflow,
83 FloatParsingError,
84 UnexpectedCharacter,
85 UnexpectedToken(TokenValue),
86 UnexpectedHash,
87 UnexpectedNewLine,
88 UnexpectedEndOfInput,
89 TooFewDefineArguments,
90 TooManyDefineArguments,
91 ErrorDirective,
92 DuplicateParameter,
93 UnknownDirective,
94 DefineRedefined,
95 ElifOutsideOfBlock,
96 ElseOutsideOfBlock,
97 EndifOutsideOfBlock,
98 ElifAfterElse,
99 MoreThanOneElse,
100 UnfinishedBlock,
101 LineOverflow,
102 NotSupported16BitLiteral,
103 NotSupported64BitLiteral,
104 MacroNotDefined,
105 RecursionLimitReached,
106 DivisionByZero,
107 RemainderByZero,
108 }
109
110 #[derive(Clone, PartialEq, Debug)]
111 pub struct Integer {
112 pub value: u64,
113 pub signed: bool,
114 pub width: i32,
115 }
116
117 #[derive(Clone, PartialEq, Debug)]
118 pub struct Float {
119 pub value: f32,
120 pub width: i32,
121 }
122
123 #[derive(Clone, PartialEq, Debug)]
124 pub struct Version {
125 pub tokens: Vec<Token>,
126 pub is_first_directive: bool,
127 pub has_comments_before: bool,
128 }
129
130 #[derive(Clone, PartialEq, Debug)]
131 pub struct Extension {
132 pub tokens: Vec<Token>,
133 pub has_non_directive_before: bool,
134 }
135
136 #[derive(Clone, PartialEq, Debug)]
137 pub struct Pragma {
138 pub tokens: Vec<Token>,
139 }
140
141 #[derive(Clone, PartialEq, Debug)]
142 pub enum TokenValue {
143 Ident(String),
144
145 Integer(Integer),
146 Float(Float),
147 Punct(Punct),
148
149 Version(Version),
150 Extension(Extension),
151 Pragma(Pragma),
152 }
153
154 #[derive(Clone, PartialEq, Debug)]
155 pub struct Token {
156 pub value: TokenValue,
157 pub location: Location,
158 // TODO macro invocation stack?
159 }