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

// Expects a null-terminated string.
func lex(_ yyinput: UnsafePointer<UInt8>, _ length: Int) -> Int? {
  var yycursor = 0, yylimit = length, yymarker = 0
  var count = 0

  loop: while true {
    
#sourceLocation(file: "swift/eof/03_eof_rule.swift", line: 13)
  var yych: UInt8 = 0
  var yystate: UInt = 0
  yyl: while true {
    switch yystate {
      case 0:
        yych = yyinput[yycursor]
        switch yych {
          case 0x20:
            yycursor += 1
            yystate = 3
            continue yyl
          case 0x27:
            yycursor += 1
            yystate = 5
            continue yyl
          default:
            if yylimit <= yycursor {
              yystate = 10
              continue yyl
            }
            yycursor += 1
            yystate = 1
            continue yyl
        }
      case 1:
        yystate = 2
        continue yyl
      case 2:
#sourceLocation(file: "swift/eof/03_eof_rule.re", line: 20)
        return nil
#sourceLocation(file: "swift/eof/03_eof_rule.swift", line: 44)
      case 3:
        yych = yyinput[yycursor]
        switch yych {
          case 0x20:
            yycursor += 1
            yystate = 3
            continue yyl
          default:
            yystate = 4
            continue yyl
        }
      case 4:
#sourceLocation(file: "swift/eof/03_eof_rule.re", line: 19)
        continue loop
#sourceLocation(file: "swift/eof/03_eof_rule.swift", line: 59)
      case 5:
        yymarker = yycursor
        yych = yyinput[yycursor]
        if yych >= 0x01 {
          yystate = 7
          continue yyl
        }
        if yylimit <= yycursor {
          yystate = 2
          continue yyl
        }
        yycursor += 1
        yystate = 6
        continue yyl
      case 6:
        yych = yyinput[yycursor]
        yystate = 7
        continue yyl
      case 7:
        switch yych {
          case 0x27:
            yycursor += 1
            yystate = 8
            continue yyl
          case 0x5C:
            yycursor += 1
            yystate = 9
            continue yyl
          default:
            if yylimit <= yycursor {
              yystate = 11
              continue yyl
            }
            yycursor += 1
            yystate = 6
            continue yyl
        }
      case 8:
#sourceLocation(file: "swift/eof/03_eof_rule.re", line: 15)
        
        count += 1
        continue loop

#sourceLocation(file: "swift/eof/03_eof_rule.swift", line: 103)
      case 9:
        yych = yyinput[yycursor]
        if yych <= 0x00 {
          if yylimit <= yycursor {
            yystate = 11
            continue yyl
          }
          yycursor += 1
          yystate = 6
          continue yyl
        }
        yycursor += 1
        yystate = 6
        continue yyl
      case 10:
#sourceLocation(file: "swift/eof/03_eof_rule.re", line: 21)
        return count
#sourceLocation(file: "swift/eof/03_eof_rule.swift", line: 121)
      case 11:
        yycursor = yymarker
        yystate = 2
        continue yyl
      default: fatalError("internal lexer error")
    }
  }
#sourceLocation(file: "swift/eof/03_eof_rule.re", line: 22)

  }
}

func test(_ str: StaticString, _ expect: Int?) {
  assert(lex(str.utf8Start, str.utf8CodeUnitCount) == expect)
}

test("", 0);
test("'qu\0tes' 'are' 'fine: \\'' ", 3);
test("'unterminated\\'", nil);
