You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: template.go
    path of file: ./repos/grafana/pkg/services/ngalert/migration
    
    the code of the file until where you have to start completion: // This file contains code that parses templates from old alerting into a sequence
// of tokens. Each token can be either a string literal or a variable.

package migration

import (
	"bytes"
	"errors"
	"fmt"
	"strconv"
	"strings"
	"unicode"

	"github.com/grafana/grafana/pkg/infra/log"
	"github.com/grafana/grafana/pkg/services/ngalert/state/template"
)

// Token contains either a string literal or a variable.
type Token struct {
	Literal  
    
func tokenizeVariable(in []rune) (Token, int, error) {
	var (
		pos   int
		r     rune
		runes []rune
	)

	if !startVariable(in) {
		return Token{}, pos, fmt.Errorf("expected '${', got '%s'", string(in[:2]))
	}
	pos += 2 // seek past opening delimiter

	// consume valid runes until we hit a closing brace
	// non-space whitespace and the opening delimiter are invalid
	for pos < len(in) {
		r = in[pos]

		if unicode.IsSpace(r) && r != ' ' {
			return Token{}, pos, errors.New("unexpected whitespace")
		}

		if startVariable(in[pos:]) {
			return Token{}, pos, errors.New("ambiguous delimiter")
		}

		if r == '}' {
			pos++
			break
		}

		runes = append(runes, r)
		pos++
	}

	// variable must end with '}' delimiter