<commit_before>package reference

import (
	"fmt"
	"io"
	"strconv"
	"strings"
)

// symbolicRefPathStmt parse a following statement master~2
// to split branch name and refrence path
type symbolicRefPathStmt struct {
	branchName string
	refPath    []int
}

// parser represents a parser.
type parser struct {
	s   *scanner
	buf struct {
		tok token
		lit string
		n   int
	}
}

// newParser returns a new instance of parser.
func newParser(r io.Reader) *parser {
	return &parser{s: newScanner(r)}
}

// ParseSymbolicReferencePath creates a symbolicRefPathStmt
func (p *parser) parseSymbolicReferencePath() (*symbolicRefPathStmt, error) {
	branchName, err := p.parseBranchName()

	if err != nil {
		return nil, err
	}

	refPath, err := p.parseRefPath()

	if err != nil {
		return nil, err
	}

	return &symbolicRefPathStmt{
		branchName: branchName,
		refPath:    refPath,
	}, nil
}

// parseFuncArg parse one function argument
func (p *parser) parseBranchName() (string, error) {
	var tok token
	var previousTok token
	var lit string
	var buf string
	var subBuf string

	for {
		tok, lit = p.scan()

		if tok == dot && buf == "" {
			return "", fmt.Errorf("branch name must not start with a dot")
		}

		if tok == colon {
			return "", fmt.Errorf("branch name must not contains any colon")
		}

		if tok == slash {
			return "", fmt.Errorf("branch name must not end with a slash")
		}

		if tok == dot && previousTok == dot {
			return "", fmt.Errorf("branch name must not contains any double dot")
		}

		if tok == space {
			return "", fmt.Errorf("branch name contains a space character")
		}

		if tok == control {
			return "", fmt.Errorf("branch name contains a control character")
		}

		if len(buf) > 4 {
			subBuf = strings.ToLower(buf[len(buf)-5 : len(buf)])
		}

		if (tok == tilde || tok == caret || tok == eof) && subBuf == ".lock" {
			return "", fmt.Errorf("branch name cannot end with .lock")
		}

		if tok == tilde || tok == caret {
			p.unscan()

			return buf, nil<commit_msg>ref(reference) : should omit second index in slice<commit_after>package reference

import (
	"fmt"
	"io"
	"strconv"
	"strings"
)

// symbolicRefPathStmt parse a following statement master~2
// to split branch name and refrence path
type symbolicRefPathStmt struct {
	branchName string
	refPath    []int
}

// parser represents a parser.
type parser struct {
	s   *scanner
	buf struct {
		tok token
		lit string
		n   int
	}
}

// newParser returns a new instance of parser.
func newParser(r io.Reader) *parser {
	return &parser{s: newScanner(r)}
}

// ParseSymbolicReferencePath creates a symbolicRefPathStmt
func (p *parser) parseSymbolicReferencePath() (*symbolicRefPathStmt, error) {
	branchName, err := p.parseBranchName()

	if err != nil {
		return nil, err
	}

	refPath, err := p.parseRefPath()

	if err != nil {
		return nil, err
	}

	return &symbolicRefPathStmt{
		branchName: branchName,
		refPath:    refPath,
	}, nil
}

// parseFuncArg parse one function argument
func (p *parser) parseBranchName() (string, error) {
	var tok token
	var previousTok token
	var lit string
	var buf string
	var subBuf string

	for {
		tok, lit = p.scan()

		if tok == dot && buf == "" {
			return "", fmt.Errorf("branch name must not start with a dot")
		}

		if tok == colon {
			return "", fmt.Errorf("branch name must not contains any colon")
		}

		if tok == slash {
			return "", fmt.Errorf("branch name must not end with a slash")
		}

		if tok == dot && previousTok == dot {
			return "", fmt.Errorf("branch name must not contains any double dot")
		}

		if tok == space {
			return "", fmt.Errorf("branch name contains a space character")
		}

		if tok == control {
			return "", fmt.Errorf("branch name contains a control character")
		}

		if len(buf) > 4 {
			subBuf = strings.ToLower(buf[len(buf)-5:])
		}

		if (tok == tilde || tok == caret || tok == eof) && subBuf == ".lock" {
			return "", fmt.Errorf("branch name cannot end with .lock")
		}

		if tok == tilde || tok == caret {
			p.unscan()

			return buf, nil
{'fraction_non_alphanumeric': 0.12235235484674807, 'fraction_numerical': 0.00149514079242462, 'mean_word_length': 3.279317697228145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4600104', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1298, 'n_words': 454}