Blender V5.3
types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Clement Foucault
2 *
3 * SPDX-License-Identifier: MIT */
4
5#pragma once
6
7#include <cstdint>
8
9namespace lexit {
10
20enum class CharClass : uint8_t {
21 /* Will decay into single char token. */
22 None = 0,
23 /* Will decay into single char of the token. */
24 Separator = (1 << 1),
25 /* Will decay into the first char of the token. */
26 MultiTok = (1 << 2),
27 WhiteSpace = (1 << 3),
28 /* Will decay into Word. Can start an identifier. */
29 Alpha = 'A', /* 0b01000001 */
30 /* Will decay into Number. Can continue an identifier. */
31 Numeric = '1', /* 0b00110001 */
32
33 /* These classes will merge characters together. */
34 CanMerge = Alpha | Numeric | MultiTok | WhiteSpace,
35 /* Classes above this value will cast to TokenType instead of using the character. */
36 ClassToTypeThreshold = Numeric - 1,
37};
38
39/* Make sure to declare this enum as being a char.
40 * This is allow casting to string possible. */
41enum TokenType : uint8_t {
45 /* Use printable ascii chars to store them in string, and for easy debugging / testing. */
46 NewLine = '\n',
47 Space = ' ',
48 Dot = '.',
49 Hash = '#',
50 Ampersand = '&',
53 ParOpen = '(',
54 ParClose = ')',
59 AngleOpen = '<',
61 Assign = '=',
62 SemiColon = ';',
63 Question = '?',
64 Not = '!',
65 Colon = ':',
66 Comma = ',',
67 Star = '*',
68 Plus = '+',
69 Minus = '-',
70 Divide = '/',
71 Tilde = '~',
72 Caret = '^',
73 Pipe = '|',
74 Percent = '%',
75 Backslash = '\\',
76 /* Mark end of stream. */
77 EndOfFile = '\0',
78
79 /* --- Keywords --- */
80
82 // Word = 'A',
83 Break = 'b',
84 Typename = 'B',
85 Const = 'c',
86 Constexpr = 'C',
87 Do = 'd',
88 Decrement = 'D',
89 NotEqual = 'e',
90 Equal = 'E',
91 For = 'f',
92 While = 'F',
93 LogicalOr = 'g',
94 GEqual = 'G',
95 Switch = 'h',
96 Case = 'H',
97 If = 'i',
98 Else = 'I',
99 Elif = 'j',
100 Endif = 'J',
101 Ifdef = 'k',
102 Ifndef = 'K',
103 Inline = 'l',
104 LEqual = 'L',
105 Static = 'm',
106 Enum = 'M',
108 Define = 'N',
109 Union = 'o',
110 Continue = 'O',
111 Line = 'p',
113 Pragma = 'q',
115 Return = 'r',
116 // Unused = 'R',
117 Struct = 's',
118 Class = 'S',
119 Template = 't',
120 This = 'T',
121 Using = 'u',
122 Undef = 'U',
123 Private = 'v',
124 Public = 'V',
125 LShift = 'w',
126 RShift = 'W',
127 // Unused = 'x',
128 // Unused = 'X',
129 Default = 'y',
132 Comment = 'Z',
134 // Number = '1',
140 // Unused = '7',
141 // Unused = '8',
142 // Unused = '9',
143
144 /* Aliases. */
153
156};
157
158/* Unique identifier to a word token. */
159using TokenAtom = uint16_t;
160
161} // namespace lexit
uint16_t TokenAtom
Definition types.hh:159
TokenType
Definition types.hh:41
@ RShift
Definition types.hh:126
@ GThan
Definition types.hh:149
@ ParOpen
Definition types.hh:53
@ Default
Definition types.hh:129
@ While
Definition types.hh:92
@ Slash
Definition types.hh:155
@ EndOfFile
Definition types.hh:77
@ Private
Definition types.hh:123
@ AssignSub
Definition types.hh:135
@ LThan
Definition types.hh:150
@ For
Definition types.hh:91
@ BracketOpen
Definition types.hh:55
@ LogicalOr
Definition types.hh:93
@ Return
Definition types.hh:115
@ Do
Definition types.hh:87
@ Hash
Definition types.hh:49
@ Not
Definition types.hh:64
@ Static
Definition types.hh:105
@ Enum
Definition types.hh:106
@ Struct
Definition types.hh:117
@ Union
Definition types.hh:109
@ AssignAdd
Definition types.hh:133
@ SquareOpen
Definition types.hh:57
@ Question
Definition types.hh:63
@ Modulo
Definition types.hh:152
@ And
Definition types.hh:146
@ Space
Definition types.hh:47
@ Percent
Definition types.hh:74
@ LogicalAnd
Definition types.hh:81
@ Pipe
Definition types.hh:73
@ Ampersand
Definition types.hh:50
@ BitwiseNot
Definition types.hh:151
@ Multiply
Definition types.hh:145
@ Dot
Definition types.hh:48
@ Switch
Definition types.hh:95
@ ParClose
Definition types.hh:54
@ SingleQuote
Definition types.hh:52
@ AssignLShift
Definition types.hh:138
@ Case
Definition types.hh:96
@ Else
Definition types.hh:98
@ AssignRShift
Definition types.hh:139
@ LEqual
Definition types.hh:104
@ Namespace
Definition types.hh:107
@ TemplateOpen
Definition types.hh:130
@ SquareClose
Definition types.hh:58
@ Plus
Definition types.hh:68
@ Break
Definition types.hh:83
@ Colon
Definition types.hh:65
@ Pragma
Definition types.hh:113
@ Continue
Definition types.hh:110
@ TemplateClose
Definition types.hh:131
@ Using
Definition types.hh:121
@ Decrement
Definition types.hh:88
@ Increment
Definition types.hh:112
@ DoubleQuote
Definition types.hh:51
@ Constexpr
Definition types.hh:86
@ AssignDiv
Definition types.hh:137
@ NotEqual
Definition types.hh:89
@ String
Definition types.hh:154
@ If
Definition types.hh:97
@ Endif
Definition types.hh:100
@ Const
Definition types.hh:85
@ NewLine
Definition types.hh:46
@ Ifndef
Definition types.hh:102
@ Number
Definition types.hh:44
@ Comment
Definition types.hh:132
@ Equal
Definition types.hh:90
@ Divide
Definition types.hh:70
@ Define
Definition types.hh:108
@ Elif
Definition types.hh:99
@ Xor
Definition types.hh:148
@ SemiColon
Definition types.hh:62
@ LShift
Definition types.hh:125
@ Inline
Definition types.hh:103
@ Assign
Definition types.hh:61
@ Minus
Definition types.hh:69
@ Ifdef
Definition types.hh:101
@ Tilde
Definition types.hh:71
@ AngleOpen
Definition types.hh:59
@ Line
Definition types.hh:111
@ Word
Definition types.hh:43
@ This
Definition types.hh:120
@ Typename
Definition types.hh:84
@ Star
Definition types.hh:67
@ AssignMul
Definition types.hh:136
@ AngleClose
Definition types.hh:60
@ Invalid
Definition types.hh:42
@ Public
Definition types.hh:124
@ GEqual
Definition types.hh:94
@ Undef
Definition types.hh:122
@ BracketClose
Definition types.hh:56
@ Caret
Definition types.hh:72
@ Or
Definition types.hh:147
@ Template
Definition types.hh:119
@ DoubleHash
Definition types.hh:114
@ Class
Definition types.hh:118
@ Comma
Definition types.hh:66
@ Backslash
Definition types.hh:75
CharClass
Definition types.hh:20