<commit_before>package gforms

import (
	"bytes"
	"reflect"
)

type Field interface {
	Clean(Data) (*V, error)
	Validate(*V, CleanedData) error
	Html(RawData) string
	html(...string) string
	GetName() string
	GetWigdet() Widget
}

type ValidationError interface {
	Error() string
}

type BaseField struct {
	name       string
	validators Validators
	Widget     Widget
	Field
}

func (self *BaseField) GetName() string {
	return self.name
}

func (self *BaseField) GetWigdet() Widget {
	return self.Widget
}

func (self *BaseField) Clean(data Data) (*V, error) {
	m, hasField := data[self.GetName()]
	if hasField {
		v := m.rawValueAsString()
		m.Kind = reflect.String
		if v != nil {
			m.Value = *v
			m.IsNil = false
			return m, nil
		}
	}
	return nilV(), nil
}

func (self *BaseField) Validate(value *V, cleanedData CleanedData) error {
	if self.validators == nil {
		return nil
	}
	for _, v := range self.validators {
		err := v.Validate(value, cleanedData)
		if err != nil {
			return err
		}
	}
	return nil
}

func fieldToHtml(field Field, rd RawData) string {
	v, hasField := rd[field.GetName()]
	if field.GetWigdet() == nil {
		if hasField {
			return field.html(v)
		} else {
			return field.html()
		}
	} else {
		if hasField {
			return field.GetWigdet().html(field, v)
		} else {
			return field.GetWigdet().html(field)
		}
	}
}

type templateContext struct {
	Field Field
	Value string
}

func newTemplateContext(field Field, vs ...string) templateContext {
	ctx := templateContext{
		Field: field,
	}
	if len(vs) > 0 {
		ctx.Value = vs[0]
	}
	return ctx
}

func renderTemplate(name string, ctx interface{}) string {
	var buffer bytes.Buffer
	Template.ExecuteTemplate(&buffer, name, ctx)
	return buffer.String()
}
<commit_msg>Handle parsing error for field templates.<commit_after>package gforms

import (
	"bytes"
	"reflect"
)

type Field interface {
	Clean(Data) (*V, error)
	Validate(*V, CleanedData) error
	Html(RawData) string
	html(...string) string
	GetName() string
	GetWigdet() Widget
}

type ValidationError interface {
	Error() string
}

type BaseField struct {
	name       string
	validators Validators
	Widget     Widget
	Field
}

func (self *BaseField) GetName() string {
	return self.name
}

func (self *BaseField) GetWigdet() Widget {
	return self.Widget
}

func (self *BaseField) Clean(data Data) (*V, error) {
	m, hasField := data[self.GetName()]
	if hasField {
		v := m.rawValueAsString()
		m.Kind = reflect.String
		if v != nil {
			m.Value = *v
			m.IsNil = false
			return m, nil
		}
	}
	return nilV(), nil
}

func (self *BaseField) Validate(value *V, cleanedData CleanedData) error {
	if self.validators == nil {
		return nil
	}
	for _, v := range self.validators {
		err := v.Validate(value, cleanedData)
		if err != nil {
			return err
		}
	}
	return nil
}

func fieldToHtml(field Field, rd RawData) string {
	v, hasField := rd[field.GetName()]
	if field.GetWigdet() == nil {
		if hasField {
			return field.html(v)
		} else {
			return field.html()
		}
	} else {
		if hasField {
			return field.GetWigdet().html(field, v)
		} else {
			return field.GetWigdet().html(field)
		}
	}
}

type templateContext struct {
	Field Field
	Value string
}

func newTemplateContext(field Field, vs ...string) templateContext {
	ctx := templateContext{
		Field: field,
	}
	if len(vs) > 0 {
		ctx.Value = vs[0]
	}
	return ctx
}

func renderTemplate(name string, ctx interface{}) string {
	var buffer bytes.Buffer
	err := Template.ExecuteTemplate(&buffer, name, ctx)
	if err != nil {
		panic(err)
	}
	return buffer.String()
}

{'fraction_non_alphanumeric': 0.12485907553551297, 'fraction_numerical': 0.0011273957158962795, 'mean_word_length': 3.515267175572519, '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': '1611507', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1271, 'n_words': 356}