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

struct SemVer: Equatable { var major: Int, minor: Int, patch: Int }

func lex(_ yyinput: UnsafePointer<UInt8>) -> SemVer? {
  let tagNone = -1

  var yycursor = 0, yymarker = 0

  // Final tag variables available in semantic action.
  
#sourceLocation(file: "swift/submatch/03_captures.swift", line: 15)
  var yytl0: Int
  var yytl1: Int
  var yytl2: Int
  var yytl3: Int
  var yytr0: Int
  var yytr1: Int
  var yytr2: Int
  var yytr3: Int
#sourceLocation(file: "swift/submatch/03_captures.re", line: 11)


  // Intermediate tag variables used by the lexer (must be autogenerated).
  
#sourceLocation(file: "swift/submatch/03_captures.swift", line: 29)
  var yyt1 = tagNone
  var yyt2 = tagNone
  var yyt3 = tagNone
  var yyt4 = tagNone
  var yyt5 = tagNone
#sourceLocation(file: "swift/submatch/03_captures.re", line: 14)


  
#sourceLocation(file: "swift/submatch/03_captures.swift", line: 39)
  var yych: UInt8 = 0
  var yystate: UInt = 0
  yyl: while true {
    switch yystate {
      case 0:
        yych = yyinput[yycursor]
        switch yych {
          case 0x30...0x39:
            yyt1 = yycursor
            yycursor += 1
            yystate = 3
            continue yyl
          default:
            yycursor += 1
            yystate = 1
            continue yyl
        }
      case 1:
        yystate = 2
        continue yyl
      case 2:
#sourceLocation(file: "swift/submatch/03_captures.re", line: 29)
        return nil
#sourceLocation(file: "swift/submatch/03_captures.swift", line: 63)
      case 3:
        yymarker = yycursor
        yych = yyinput[yycursor]
        switch yych {
          case 0x2E:
            yycursor += 1
            yystate = 4
            continue yyl
          case 0x30...0x39:
            yycursor += 1
            yystate = 6
            continue yyl
          default:
            yystate = 2
            continue yyl
        }
      case 4:
        yych = yyinput[yycursor]
        switch yych {
          case 0x30...0x39:
            yyt2 = yycursor
            yycursor += 1
            yystate = 7
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      case 5:
        yycursor = yymarker
        yystate = 2
        continue yyl
      case 6:
        yych = yyinput[yycursor]
        switch yych {
          case 0x2E:
            yycursor += 1
            yystate = 4
            continue yyl
          case 0x30...0x39:
            yycursor += 1
            yystate = 6
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      case 7:
        yych = yyinput[yycursor]
        switch yych {
          case 0x00:
            yyt3 = yycursor
            yyt4 = -1
            yyt5 = -1
            yycursor += 1
            yystate = 8
            continue yyl
          case 0x2E:
            yyt3 = yycursor
            yyt5 = yycursor
            yycursor += 1
            yystate = 9
            continue yyl
          case 0x30...0x39:
            yycursor += 1
            yystate = 7
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      case 8:
        yytl1 = yyt1
        yytl2 = yyt2
        yytr2 = yyt3
        yytl3 = yyt5
        yytr3 = yyt4
        yytl0 = yyt1
        yytr0 = yycursor
        yytr1 = yyt2
                yytr1 -= 1
#sourceLocation(file: "swift/submatch/03_captures.re", line: 22)
        
      let _ = yytl0; _ = yytr0  // Some variables are unused.
      return SemVer(
        major: s2n(yytl1..<yytr1),
        minor: s2n(yytl2..<yytr2),
        patch: yytl3 != tagNone ? s2n((yytl3 + 1)..<yytr3) : 0)

#sourceLocation(file: "swift/submatch/03_captures.swift", line: 153)
      case 9:
        yych = yyinput[yycursor]
        if yych <= 0x00 {
          yystate = 5
          continue yyl
        }
        yystate = 11
        continue yyl
      case 10:
        yych = yyinput[yycursor]
        yystate = 11
        continue yyl
      case 11:
        switch yych {
          case 0x00:
            yyt4 = yycursor
            yycursor += 1
            yystate = 8
            continue yyl
          case 0x30...0x39:
            yycursor += 1
            yystate = 10
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      default: fatalError("internal lexer error")
    }
  }
#sourceLocation(file: "swift/submatch/03_captures.re", line: 30)


  func s2n(_ range: Range<Int>) -> Int {
    range.reduce(0) { accum, idx in
      accum * 10 + Int(yyinput[idx] - UInt8(ascii: "0"))
    }
  }
}

assert(lex("23.34") == SemVer(major: 23, minor: 34, patch: 0))
assert(lex("1.2.999") == SemVer(major: 1, minor: 2, patch: 999))
assert(lex("1.a") == nil)
