/* Generated by re2swift */
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 1)
// re2swift $INPUT -o $OUTPUT -c

#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 6)
let yycinit: UInt = 0
let yycbin: UInt = 10
let yycoct: UInt = 14
let yycdec: UInt = 18
let yychex: UInt = 22
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 3)


func parseUInt32(_ yyinput: UnsafePointer<UInt8>) -> UInt32? {
  var yycursor = 0, yymarker = 0, yycond = yycinit

  var accum: UInt64 = 0

  loop: while true {
    
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 22)
  var yych: UInt8 = 0
  var yystate: UInt = yycond
  yyl: while true {
    switch yystate {
      case 0:
        yych = yyinput[yycursor]
        yycursor += 1
        switch yych {
          case 0x30:
            yystate = 2
            continue yyl
          case 0x31...0x39:
            yystate = 4
            continue yyl
          default:
            yystate = 1
            continue yyl
        }
      case 1:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 28)
        return nil
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 44)
      case 2:
        yymarker = yycursor
        yych = yyinput[yycursor]
        switch yych {
          case 0x42:
            fallthrough
          case 0x62:
            yycursor += 1
            yystate = 5
            continue yyl
          case 0x58:
            fallthrough
          case 0x78:
            yycursor += 1
            yystate = 7
            continue yyl
          default:
            yystate = 3
            continue yyl
        }
      case 3:
        yycond = yycoct
        yystate = yycoct
        continue yyl
      case 4:
        yycursor -= 1
        yycond = yycdec
        yystate = yycdec
        continue yyl
      case 5:
        yych = yyinput[yycursor]
        switch yych {
          case 0x30...0x31:
            yycursor += 1
            yystate = 8
            continue yyl
          default:
            yystate = 6
            continue yyl
        }
      case 6:
        yycursor = yymarker
        yystate = 3
        continue yyl
      case 7:
        yych = yyinput[yycursor]
        switch yych {
          case 0x30...0x39:
            fallthrough
          case 0x41...0x46:
            fallthrough
          case 0x61...0x66:
            yycursor += 1
            yystate = 9
            continue yyl
          default:
            yystate = 6
            continue yyl
        }
      case 8:
        yycursor -= 1
        yycond = yycbin
        yystate = yycbin
        continue yyl
      case 9:
        yycursor -= 1
        yycond = yychex
        yystate = yychex
        continue yyl
      case 10:
        yych = yyinput[yycursor]
        yycursor += 1
        switch yych {
          case 0x00:
            yystate = 11
            continue yyl
          case 0x30...0x31:
            yystate = 13
            continue yyl
          default:
            yystate = 12
            continue yyl
        }
      case 11:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 26)
        return UInt32(exactly: accum)
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 131)
      case 12:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 28)
        return nil
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 135)
      case 13:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 19)
        add("0", 2);      continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 139)
      case 14:
        yych = yyinput[yycursor]
        yycursor += 1
        switch yych {
          case 0x00:
            yystate = 15
            continue yyl
          case 0x30...0x37:
            yystate = 17
            continue yyl
          default:
            yystate = 16
            continue yyl
        }
      case 15:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 26)
        return UInt32(exactly: accum)
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 157)
      case 16:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 28)
        return nil
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 161)
      case 17:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 20)
        add("0", 8);      continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 165)
      case 18:
        yych = yyinput[yycursor]
        yycursor += 1
        switch yych {
          case 0x00:
            yystate = 19
            continue yyl
          case 0x30...0x39:
            yystate = 21
            continue yyl
          default:
            yystate = 20
            continue yyl
        }
      case 19:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 26)
        return UInt32(exactly: accum)
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 183)
      case 20:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 28)
        return nil
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 187)
      case 21:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 21)
        add("0", 10);     continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 191)
      case 22:
        yych = yyinput[yycursor]
        yycursor += 1
        switch yych {
          case 0x00:
            yystate = 23
            continue yyl
          case 0x30...0x39:
            yystate = 25
            continue yyl
          case 0x41...0x46:
            yystate = 26
            continue yyl
          case 0x61...0x66:
            yystate = 27
            continue yyl
          default:
            yystate = 24
            continue yyl
        }
      case 23:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 26)
        return UInt32(exactly: accum)
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 215)
      case 24:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 28)
        return nil
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 219)
      case 25:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 22)
        add("0", 16);     continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 223)
      case 26:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 24)
        add("A", 16, 10); continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 227)
      case 27:
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 23)
        add("a", 16, 10); continue loop
#sourceLocation(file: "swift/conditions/parse_u32_conditions.swift", line: 231)
      default: fatalError("internal lexer error")
    }
  }
#sourceLocation(file: "swift/conditions/parse_u32_conditions.re", line: 29)

  }

  func add(_ charOrigin: UnicodeScalar, _ base: UInt64, _ offset: UInt64 = 0) {
    let digit = yyinput[yycursor - 1] - UInt8(ascii: charOrigin)
    accum = min(accum * base + UInt64(digit) + offset, UInt64(UInt32.max) + 1)
  }
}

assert(parseUInt32("") == nil)
assert(parseUInt32("1234567890") == 1234567890)
assert(parseUInt32("0b1101") == 13)
assert(parseUInt32("0x7Fe") == 2046)
assert(parseUInt32("0644") == 420)
assert(parseUInt32("9999999999") == nil)
