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
|
/* Generated by re2swift */
// re2swift $INPUT -o $OUTPUT --api generic --recursive-functions -i
class State {
let string: UnsafeBufferPointer<UInt8>
var cursor: Int = 0
init(string: UnsafeBufferPointer<UInt8>) {
self.string = string
}
}
func yy0(_ s: State) -> Bool {
let yych = s.string[s.cursor]
s.cursor += 1
switch yych {
case 0x41...0x5A:
fallthrough
case 0x61...0x7A: return yy2(s)
default: return yy1(s)
}
}
func yy1(_ s: State) -> Bool {
return false
}
func yy2(_ s: State) -> Bool {
let yych = s.string[s.cursor]
switch yych {
case 0x30...0x39:
fallthrough
case 0x41...0x5A:
fallthrough
case 0x61...0x7A:
s.cursor += 1
return yy2(s)
default: return yy3(s)
}
}
func yy3(_ s: State) -> Bool {
return true
}
func lex(_ s: State) -> Bool {
return yy0(s)
}
@main struct Program {
static func main() {
let test1: StaticString = "qwerty42\0"
let test2: StaticString = "??\0"
test1.withUTF8Buffer {
assert(lex(State(string: $0)))
}
test2.withUTF8Buffer {
assert(!lex(State(string: $0)))
}
}
}
|