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
|
/* Generated by re2swift */
// re2swift $INPUT -o $OUTPUT -i
enum Result { case ok, fail }
func lex(_ yyinput: UnsafePointer<UInt8>) -> Result {
var yycursor = 0, yymarker = 0
var yych: UInt8 = 0
var yyaccept: UInt = 0
var yystate: UInt = 0
yyl: while true {
switch yystate {
case 0:
yych = yyinput[yycursor]
yycursor += 1
switch yych {
case 0x2E:
yystate = 3
continue yyl
case 0x30:
yystate = 4
continue yyl
case 0x31...0x39:
yystate = 5
continue yyl
default:
yystate = 1
continue yyl
}
case 1:
yystate = 2
continue yyl
case 2: return .fail
case 3:
yych = yyinput[yycursor]
switch yych {
case 0x30...0x39:
yycursor += 1
yystate = 7
continue yyl
default:
yystate = 2
continue yyl
}
case 4:
yyaccept = 0
yymarker = yycursor
yych = yyinput[yycursor]
switch yych {
case 0x2E:
yycursor += 1
yystate = 7
continue yyl
case 0x30...0x39:
yycursor += 1
yystate = 9
continue yyl
case 0x45:
fallthrough
case 0x65:
yycursor += 1
yystate = 11
continue yyl
default:
yystate = 2
continue yyl
}
case 5:
yyaccept = 1
yymarker = yycursor
yych = yyinput[yycursor]
switch yych {
case 0x2E:
yycursor += 1
yystate = 7
continue yyl
case 0x30...0x39:
yycursor += 1
yystate = 5
continue yyl
case 0x45:
fallthrough
case 0x65:
yycursor += 1
yystate = 11
continue yyl
default:
yystate = 6
continue yyl
}
case 6: return .ok
case 7:
yyaccept = 2
yymarker = yycursor
yych = yyinput[yycursor]
switch yych {
case 0x30...0x39:
yycursor += 1
yystate = 7
continue yyl
case 0x45:
fallthrough
case 0x65:
yycursor += 1
yystate = 11
continue yyl
default:
yystate = 8
continue yyl
}
case 8: return .ok
case 9:
yych = yyinput[yycursor]
switch yych {
case 0x2E:
yycursor += 1
yystate = 7
continue yyl
case 0x30...0x39:
yycursor += 1
yystate = 9
continue yyl
case 0x45:
fallthrough
case 0x65:
yycursor += 1
yystate = 11
continue yyl
default:
yystate = 10
continue yyl
}
case 10:
yycursor = yymarker
switch yyaccept {
case 0:
yystate = 2
continue yyl
case 1:
yystate = 6
continue yyl
default:
yystate = 8
continue yyl
}
case 11:
yych = yyinput[yycursor]
switch yych {
case 0x2B:
fallthrough
case 0x2D:
yycursor += 1
yystate = 12
continue yyl
case 0x30...0x39:
yycursor += 1
yystate = 13
continue yyl
default:
yystate = 10
continue yyl
}
case 12:
yych = yyinput[yycursor]
switch yych {
case 0x30...0x39:
yycursor += 1
yystate = 13
continue yyl
default:
yystate = 10
continue yyl
}
case 13:
yych = yyinput[yycursor]
switch yych {
case 0x30...0x39:
yycursor += 1
yystate = 13
continue yyl
default:
yystate = 8
continue yyl
}
default: fatalError("internal lexer error")
}
}
}
assert(lex("123") == .ok)
assert(lex("123.4567") == .ok)
|