1#[derive(Clone, Copy, PartialEq, Debug)]
3pub struct Location {
4 pub start: u32,
6 pub end: u32,
9 pub(crate) line: u32,
11}
12
13impl 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)]
24pub enum Punct {
25 AddAssign,
27 SubAssign,
28 MulAssign,
29 DivAssign,
30 ModAssign,
31 LeftShiftAssign,
32 RightShiftAssign,
33 AndAssign,
34 XorAssign,
35 OrAssign,
36
37 Increment,
39 Decrement,
40 LogicalAnd,
41 LogicalOr,
42 LogicalXor,
43 LessEqual,
44 GreaterEqual,
45 EqualEqual,
46 NotEqual,
47 LeftShift,
48 RightShift,
49
50 LeftBrace,
52 RightBrace,
53 LeftParen,
54 RightParen,
55 LeftBracket,
56 RightBracket,
57
58 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)]
80pub 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)]
111pub struct Integer {
112 pub value: u64,
113 pub signed: bool,
114 pub width: i32,
115}
116
117#[derive(Clone, PartialEq, Debug)]
118pub struct Float {
119 pub value: f32,
120 pub width: i32,
121}
122
123#[derive(Clone, PartialEq, Debug)]
124pub 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)]
131pub struct Extension {
132 pub tokens: Vec<Token>,
133 pub has_non_directive_before: bool,
134}
135
136#[derive(Clone, PartialEq, Debug)]
137pub struct Pragma {
138 pub tokens: Vec<Token>,
139}
140
141#[derive(Clone, PartialEq, Debug)]
142pub 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)]
155pub struct Token {
156 pub value: TokenValue,
157 pub location: Location,
158 }