/* Generated by re2swift */
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 1)
// re2swift $INPUT -o $OUTPUT
import Foundation

func lex(_ str: Data) -> Int? {
  var cursor = 0, limit = str.count
  var count = 0

  loop: while true {
    
#sourceLocation(file: "swift/eof/04_fake_sentinel.swift", line: 13)
  var yych: UInt8 = 0
  var yystate: UInt = 0
  yyl: while true {
    switch yystate {
      case 0:
        yych = cursor < limit ? str[cursor] : 0
        cursor += 1
        switch yych {
          case 0x00:
            yystate = 1
            continue yyl
          case 0x20:
            yystate = 3
            continue yyl
          case 0x61...0x7A:
            yystate = 5
            continue yyl
          default:
            yystate = 2
            continue yyl
        }
      case 1:
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 19)
        return count
#sourceLocation(file: "swift/eof/04_fake_sentinel.swift", line: 38)
      case 2:
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 21)
        return nil
#sourceLocation(file: "swift/eof/04_fake_sentinel.swift", line: 42)
      case 3:
        yych = cursor < limit ? str[cursor] : 0
        switch yych {
          case 0x20:
            cursor += 1
            yystate = 3
            continue yyl
          default:
            yystate = 4
            continue yyl
        }
      case 4:
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 20)
        continue loop
#sourceLocation(file: "swift/eof/04_fake_sentinel.swift", line: 57)
      case 5:
        yych = cursor < limit ? str[cursor] : 0
        switch yych {
          case 0x61...0x7A:
            cursor += 1
            yystate = 5
            continue yyl
          default:
            yystate = 6
            continue yyl
        }
      case 6:
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 15)
        
        count += 1
        continue loop

#sourceLocation(file: "swift/eof/04_fake_sentinel.swift", line: 75)
      default: fatalError("internal lexer error")
    }
  }
#sourceLocation(file: "swift/eof/04_fake_sentinel.re", line: 22)

  }
}

func test(_ str: String, _ expect: Int?) {
  // For the sake of example create a string without terminating null.
  assert(lex(Data(str.utf8)) == expect)
}

test("", 0)
test("one two three ", 3)
test("f0ur", nil)
