Serenity Operating System
1// This file is used for automatically generating the ANSI escape sequence state machine
2//
3// The description of the state machine is taken from https://vt100.net/emu/dec_ansi_parser
4// with added support for UTF-8 parsing
5
6@name EscapeSequenceStateMachine
7@namespace VT
8@begin Ground
9
10@anywhere {
11 0x18 => (Ground, Execute)
12 0x1a => (Ground, Execute)
13 0x1b => (Escape, _)
14}
15
16Ground {
17 [0x00..0x17] => (_, Execute)
18 0x19 => (_, Execute)
19 [0x1c..0x1f] => (_, Execute)
20
21 [0x20..0x7f] => (_, Print)
22
23 [0x80..0xc1] => (Ground, FailUTF8)
24 [0xc2..0xdf] => (UTF81ByteNeeded, BeginUTF8)
25 [0xe0..0xef] => (UTF82BytesNeeded, BeginUTF8)
26 [0xf0..0xf4] => (UTF83BytesNeeded, BeginUTF8)
27 [0xf5..0xff] => (Ground, FailUTF8)
28}
29
30UTF81ByteNeeded {
31 [0x00..0x7f] => (Ground, FailUTF8)
32 [0x80..0xbf] => (Ground, PrintUTF8)
33 [0xc0..0xff] => (Ground, FailUTF8)
34}
35
36UTF82BytesNeeded {
37 [0x00..0x7f] => (Ground, FailUTF8)
38 [0x80..0xbf] => (UTF81ByteNeeded, AdvanceUTF8)
39 [0xc0..0xff] => (Ground, FailUTF8)
40}
41
42UTF83BytesNeeded {
43 [0x00..0x7f] => (Ground, FailUTF8)
44 [0x80..0xbf] => (UTF82BytesNeeded, AdvanceUTF8)
45 [0xc0..0xff] => (Ground, FailUTF8)
46}
47
48Escape {
49 @entry Clear
50
51 [0x00..0x17] => (_, Execute)
52 0x19 => (_, Execute)
53 [0x1c..0x1f] => (_, Execute)
54
55 [0x20..0x2f] => (EscapeIntermediate, Collect)
56 [0x30..0x4f] => (Ground, EscDispatch)
57 0x50 => (DcsEntry, _)
58 [0x51..0x57] => (Ground, EscDispatch)
59 0x58 => (SosPmApcString, _)
60 0x59 => (Ground, EscDispatch)
61 0x5a => (Ground, EscDispatch)
62 0x5b => (CsiEntry, _)
63 0x5c => (Ground, EscDispatch)
64 0x5d => (OscString, _)
65 0x5e => (SosPmApcString, _)
66 0x5f => (SosPmApcString, _)
67 [0x60..0x7e] => (Ground, EscDispatch)
68 0x7f => (_, _)
69}
70
71EscapeIntermediate {
72 [0x00..0x17] => (_, Execute)
73 0x19 => (_, Execute)
74 [0x1c..0x1f] => (_, Execute)
75 [0x20..0x2f] => (_, Collect)
76 [0x30..0x7e] => (Ground, EscDispatch)
77 0x7f => (_, _)
78}
79
80CsiEntry {
81 @entry Clear
82
83 [0x00..0x17] => (_, Execute)
84 0x19 => (_, Execute)
85 [0x1c..0x1f] => (_, Execute)
86
87 [0x20..0x2f] => (CsiIntermediate, Execute)
88 [0x30..0x39] => (CsiParam, Param)
89 0x3a => (CsiIgnore, _)
90 0x3b => (CsiParam, Param)
91 [0x3c..0x3f] => (CsiParam, Collect)
92 [0x40..0x7e] => (Ground, CsiDispatch)
93 0x7f => (_, _)
94}
95
96CsiIgnore {
97 [0x00..0x17] => (_, Execute)
98 0x19 => (_, Execute)
99 [0x1c..0x1f] => (_, Execute)
100
101 [0x20..0x3f] => (_, _)
102 [0x40..0x7e] => (Ground, _)
103 0x7f => (_, _)
104}
105
106CsiParam {
107 [0x00..0x17] => (_, Execute)
108 0x19 => (_, Execute)
109 [0x1c..0x1f] => (_, Execute)
110
111 [0x20..0x2f] => (CsiIntermediate, Collect)
112 [0x30..0x39] => (_, Param)
113 0x3a => (CsiIgnore, _)
114 0x3b => (_, Param)
115 [0x3c..0x3f] => (CsiIgnore, _)
116 [0x40..0x7e] => (Ground, CsiDispatch)
117 0x7f => (_, _)
118}
119
120CsiIntermediate {
121 [0x00..0x17] => (_, Execute)
122 0x19 => (_, Execute)
123 [0x1c..0x1f] => (_, Execute)
124
125 [0x20..0x2f] => (_, Collect)
126 [0x30..0x3f] => (CsiIgnore, _)
127 [0x40..0x7e] => (Ground, CsiDispatch)
128 0x7f => (_, _)
129}
130
131DcsEntry {
132 @entry Clear
133
134 [0x00..0x17] => (_, _)
135 0x19 => (_, _)
136 [0x1c..0x1f] => (_, _)
137
138 [0x20..0x2f] => (DcsIntermediate, Collect)
139 [0x30..0x39] => (DcsParam, Param)
140 0x3a => (DcsIgnore, _)
141 0x3b => (DcsParam, Param)
142 [0x3c..0x3f] => (DcsParam, Collect)
143 [0x40..0x7e] => (DcsPassthrough, _)
144 0x7f => (_, _)
145}
146
147DcsIntermediate {
148 [0x00..0x17] => (_, _)
149 0x19 => (_, _)
150 [0x1c..0x1f] => (_, _)
151
152 [0x20..0x2f] => (_, Collect)
153 [0x30..0x3f] => (DcsIgnore, _)
154 [0x40..0x7e] => (DcsPassthrough, _)
155 0x7f => (_, _)
156}
157
158DcsIgnore {
159 [0x00..0x17] => (_, _)
160 0x19 => (_, _)
161 [0x1c..0x1f] => (_, _)
162 [0x20..0x7f] => (_, _)
163 0x9c => (Ground, _)
164}
165
166DcsParam {
167 [0x00..0x17] => (_, _)
168 0x19 => (_, _)
169 [0x1c..0x1f] => (_, _)
170
171 [0x20..0x2f] => (DcsIntermediate, Collect)
172 [0x30..0x39] => (_, Param)
173 0x3a => (DcsIgnore, _)
174 0x3b => (_, Param)
175 [0x3c..0x3f] => (DcsIgnore, _)
176 [0x40..0x7e] => (DcsPassthrough, _)
177 0x7f => (_, _)
178}
179
180DcsPassthrough {
181 @entry Hook
182
183 [0x00..0x17] => (_, Put)
184 0x19 => (_, Put)
185 [0x1c..0x1f] => (_, Put)
186 [0x20..0x7e] => (_, Put)
187 0x7f => (_, _)
188 0x9c => (Ground, _)
189
190 @exit Unhook
191}
192
193SosPmApcString {
194 [0x00..0x17] => (_, _)
195 0x19 => (_, _)
196 [0x1c..0x1f] => (_, _)
197 [0x20..0x7f] => (_, _)
198 0x9c => (Ground, _)
199}
200
201OscString {
202 @entry OscStart
203
204 [0x00..0x06] => (_, _)
205
206 // While the standard says that only ST can terminate the string,
207 // xterm uses BEL (0x07)
208 0x07 => (Ground, _)
209
210 [0x08..0x17] => (_, _)
211 0x19 => (_, _)
212 [0x1c..0x1f] => (_, _)
213
214 [0x20..0xff] => (_, OscPut)
215 @exit OscEnd
216}