package syntax

import (
	
	
)

type ReplacerData struct {
	Rep     string
	Strings []string
	Rules   []int
}

const (
	replaceSpecials     = 4
	replaceLeftPortion  = -1
	replaceRightPortion = -2
	replaceLastGroup    = -3
	replaceWholeString  = -4
)

//ErrReplacementError is a general error during parsing the replacement text
var ErrReplacementError = errors.New("Replacement pattern error.")

// NewReplacerData will populate a reusable replacer data struct based on the given replacement string
// and the capture group data from a regexp
func ( string,  map[int]int,  int,  map[string]int,  RegexOptions) (*ReplacerData, error) {
	 := parser{
		options:  ,
		caps:     ,
		capsize:  ,
		capnames: ,
	}
	.setPattern()
	,  := .scanReplacement()
	if  != nil {
		return nil, 
	}

	if .t != ntConcatenate {
		panic(ErrReplacementError)
	}

	 := &bytes.Buffer{}
	var (
		 []string
		   []int
	)

	for ,  := range .children {
		switch .t {
		case ntMulti:
			.writeStrToBuf()

		case ntOne:
			.WriteRune(.ch)

		case ntRef:
			if .Len() > 0 {
				 = append(, len())
				 = append(, .String())
				.Reset()
			}
			 := .m

			if len() > 0 &&  >= 0 {
				 = []
			}

			 = append(, -replaceSpecials-1-)

		default:
			panic(ErrReplacementError)
		}
	}

	if .Len() > 0 {
		 = append(, len())
		 = append(, .String())
	}

	return &ReplacerData{
		Rep:     ,
		Strings: ,
		Rules:   ,
	}, nil
}