/* Generated by re2swift */
#sourceLocation(file: "swift/submatch/01_stags.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/01_stags.swift", line: 15)
var t1 = tagNone
var t2 = tagNone
var t3 = tagNone
var t4 = tagNone
var t5 = tagNone
#sourceLocation(file: "swift/submatch/01_stags.re", line: 11)


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


  
#sourceLocation(file: "swift/submatch/01_stags.swift", line: 35)
  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/01_stags.re", line: 34)
        return nil
#sourceLocation(file: "swift/submatch/01_stags.swift", line: 59)
      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
            yycursor += 1
            yystate = 8
            continue yyl
          case 0x2E:
            yyt3 = yycursor
            yycursor += 1
            yystate = 9
            continue yyl
          case 0x30...0x39:
            yycursor += 1
            yystate = 7
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      case 8:
        t1 = yyt1
        t3 = yyt2
        t4 = yyt3
        t5 = yyt4
        t2 = yyt2
                t2 -= 1
#sourceLocation(file: "swift/submatch/01_stags.re", line: 22)
        
      let s2n = { (range: Range<Int>) in
        range.reduce(0) { accum, idx in
          accum * 10 + Int(yyinput[idx] - UInt8(ascii: "0"))
        }
      }

      return SemVer(
        major: s2n(t1..<t2),
        minor: s2n(t3..<t4),
        patch: t5 != tagNone ? s2n(t5..<(yycursor - 1)) : 0)

#sourceLocation(file: "swift/submatch/01_stags.swift", line: 149)
      case 9:
        yych = yyinput[yycursor]
        switch yych {
          case 0x30...0x39:
            yyt4 = yycursor
            yycursor += 1
            yystate = 10
            continue yyl
          default:
            yystate = 5
            continue yyl
        }
      case 10:
        yych = yyinput[yycursor]
        switch yych {
          case 0x00:
            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/01_stags.re", line: 35)

}

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)
