func (p *parser) parse() (Template, error) {
	p.next()
	if err := p.expect('/'); err != nil {
		return Template{}, err
	}
	segments, err := p.parseSegments()
	if err != nil {
		return Template{}, err
	}
	var verb string
	if p.tok == ':' {
		v, err := p.parseVerb()
		if err != nil {
			return Template{}, err
		}
		verb = v
	}
	if p.tok != -1 {
		return Template{}, fmt.Errorf("expected EOF, got %q", p.tok)
	}
	return Template{
		Segments: segments,
		Verb:     verb,
	}, nil
}
Grammar:

Template = "/" Segments [ Verb ] ;
Segments = Segment { "/" Segment } ;
Segment  = "*" | "**" | LITERAL | Variable ;
Variable = "{" FieldPath [ "=" Segments ] "}" ;
FieldPath = IDENT { "." IDENT } ;
Verb     = ":" LITERAL ;
package httprule
import "fmt"
type Template struct {
	Segments []Segment
	Verb     string
}
type Segment struct {
	Kind     SegmentKind
	Literal  string
	Variable VariableSegment
}
type SegmentKind int
const (
	SegmentKindLiteral SegmentKind = iota
	SegmentKindMatchSingle
	SegmentKindMatchMultiple
	SegmentKindVariable
)
type VariableSegment struct {
	FieldPath FieldPath
	Segments  []Segment
}
func ParseTemplate(s string) (Template, error) {
	p := &parser{
		content: s,
	}
	template, err := p.parse()
	if err != nil {
		return Template{}, err
	}
	if err := validate(template); err != nil {
		return Template{}, err
	}
	return template, nil
}
type parser struct {
	content string
	pos int
	tok rune
}