// Code generated by re2c, DO NOT EDIT.
//line "go/submatch/01_stags.re":1
//go:generate re2go $INPUT -o $OUTPUT
package main

import "reflect"

type SemVer struct { major, minor, patch int }

func s2n(s string) int { // convert pre-parsed string to a number
	n := 0
	for _, c := range s { n = n*10 + int(c-'0') }
	return n
}

func parse(str string) *SemVer {
	var cur, mar int

	// User-defined tag variables that are available in semantic action.
	var t1, t2, t3, t4, t5 int

	// Autogenerated tag variables used by the lexer to track tag values.
	
//line "go/submatch/01_stags.go":25
var yyt1 int
	var yyt2 int
	var yyt3 int
	var yyt4 int
//line "go/submatch/01_stags.re":21


	
//line "go/submatch/01_stags.go":34
{
	var yych byte
	yych = str[cur]
	switch (yych) {
	case '0','1','2','3','4','5','6','7','8','9':
		yyt1 = cur
		goto yy3
	default:
		goto yy1
	}
yy1:
	cur += 1
yy2:
//line "go/submatch/01_stags.re":44
	{ return nil }
//line "go/submatch/01_stags.go":50
yy3:
	cur += 1
	mar = cur
	yych = str[cur]
	switch (yych) {
	case '.':
		goto yy4
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy6
	default:
		goto yy2
	}
yy4:
	cur += 1
	yych = str[cur]
	switch (yych) {
	case '0','1','2','3','4','5','6','7','8','9':
		yyt2 = cur
		goto yy7
	default:
		goto yy5
	}
yy5:
	cur = mar
	goto yy2
yy6:
	cur += 1
	yych = str[cur]
	switch (yych) {
	case '.':
		goto yy4
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy6
	default:
		goto yy5
	}
yy7:
	cur += 1
	yych = str[cur]
	switch (yych) {
	case 0x00:
		yyt3 = cur
		yyt4 = -1
		goto yy8
	case '.':
		yyt3 = cur
		goto yy9
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy7
	default:
		goto yy5
	}
yy8:
	cur += 1
	t1 = yyt1
	t3 = yyt2
	t4 = yyt3
	t5 = yyt4
	t2 = yyt2
	t2 += -1
//line "go/submatch/01_stags.re":37
	{
			major := s2n(str[t1:t2])
			minor := s2n(str[t3:t4])
			patch := 0
			if t5 != -1 { patch = s2n(str[t5:cur-1]) }
			return &SemVer{major, minor, patch}
		}
//line "go/submatch/01_stags.go":119
yy9:
	cur += 1
	yych = str[cur]
	switch (yych) {
	case '0','1','2','3','4','5','6','7','8','9':
		yyt4 = cur
		goto yy10
	default:
		goto yy5
	}
yy10:
	cur += 1
	yych = str[cur]
	switch (yych) {
	case 0x00:
		goto yy8
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy10
	default:
		goto yy5
	}
}
//line "go/submatch/01_stags.re":45

}

func main() {
	assert_eq := func(x, y *SemVer) {
		if !reflect.DeepEqual(x, y) { panic("error") }
	}
	assert_eq(parse("23.34\000"), &SemVer{23, 34, 0})
	assert_eq(parse("1.2.9999\000"), &SemVer{1, 2, 9999})
	assert_eq(parse("1.a\000"), nil)
}
