1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/* Generated by re2c */
// re2c $INPUT -o $OUTPUT --input-encoding utf8 --recursive-functions -i
// This example supports multiple input encodings: UTF-8 and UTF-32.
// Both lexers are generated from the same rules block, and the use
// blocks add only encoding-specific configurations.
#include <assert.h>
#include <stdint.h>
struct State8 {
const uint8_t* cur;
const uint8_t* mar;
};
int yy0(State8& st);
int yy1(State8& st);
int yy2(State8& st);
int yy3(State8& st);
int yy4(State8& st);
int yy5(State8& st);
int yy6(State8& st);
int yy7(State8& st);
int yy8(State8& st);
int yy9(State8& st);
int yy10(State8& st);
int yy11(State8& st);
int yy12(State8& st);
int lex_utf8(State8& st);
int yy0(State8& st) {
uint8_t yych = *st.cur++;
switch (yych) {
case 0xE2: return yy3(st);
default: return yy1(st);
}
}
int yy1(State8& st) {
return yy2(st);
}
int yy2(State8& st) {
return 1;
}
int yy3(State8& st) {
uint8_t yych = *(st.mar = st.cur);
switch (yych) {
case 0x88:
++st.cur;
return yy4(st);
default: return yy2(st);
}
}
int yy4(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 0x80:
++st.cur;
return yy6(st);
default: return yy5(st);
}
}
int yy5(State8& st) {
st.cur = st.mar;
return yy2(st);
}
int yy6(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 'x':
++st.cur;
return yy7(st);
default: return yy5(st);
}
}
int yy7(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case ' ':
++st.cur;
return yy8(st);
default: return yy5(st);
}
}
int yy8(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 0xE2:
++st.cur;
return yy9(st);
default: return yy5(st);
}
}
int yy9(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 0x88:
++st.cur;
return yy10(st);
default: return yy5(st);
}
}
int yy10(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 0x83:
++st.cur;
return yy11(st);
default: return yy5(st);
}
}
int yy11(State8& st) {
uint8_t yych = *st.cur;
switch (yych) {
case 'y':
++st.cur;
return yy12(st);
default: return yy5(st);
}
}
int yy12(State8& st) {
return 0;
}
int lex_utf8(State8& st) {
return yy0(st);
}
struct State32 {
const uint32_t* cur;
const uint32_t* mar;
};
int yy13(State32& st);
int yy14(State32& st);
int yy15(State32& st);
int yy16(State32& st);
int yy17(State32& st);
int yy18(State32& st);
int yy19(State32& st);
int yy20(State32& st);
int yy21(State32& st);
int lex_utf32(State32& st);
int yy13(State32& st) {
uint32_t yych = *st.cur++;
if (yych == 0x00002200) return yy16(st);
else return yy14(st);
}
int yy14(State32& st) {
return yy15(st);
}
int yy15(State32& st) {
return 1;
}
int yy16(State32& st) {
uint32_t yych = *(st.mar = st.cur);
if (yych == 'x') {
++st.cur;
return yy17(st);
} else {
return yy15(st);
}
}
int yy17(State32& st) {
uint32_t yych = *st.cur;
if (yych == ' ') {
++st.cur;
return yy19(st);
} else {
return yy18(st);
}
}
int yy18(State32& st) {
st.cur = st.mar;
return yy15(st);
}
int yy19(State32& st) {
uint32_t yych = *st.cur;
if (yych == 0x00002203) {
++st.cur;
return yy20(st);
} else {
return yy18(st);
}
}
int yy20(State32& st) {
uint32_t yych = *st.cur;
if (yych == 'y') {
++st.cur;
return yy21(st);
} else {
return yy18(st);
}
}
int yy21(State32& st) {
return 0;
}
int lex_utf32(State32& st) {
return yy13(st);
}
int main() {
static const uint8_t s8[] = // UTF-8
{ 0xe2, 0x88, 0x80, 0x78, 0x20, 0xe2, 0x88, 0x83, 0x79 };
State8 st8 = {s8, nullptr};
static const uint32_t s32[] = // UTF32
{ 0x00002200, 0x00000078, 0x00000020, 0x00002203, 0x00000079 };
State32 st32 = {s32, nullptr};
assert(lex_utf8(st8) == 0);
assert(lex_utf32(st32) == 0);
return 0;
}
|