<commit_before>package mithril

import (
	"fmt"
	"regexp"
	"strings"
)

const (
	// Parser is the tags regex parser
	Parser = `(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])`
	// AttrParser is the attribute regex parser
	AttrParser = `\[(.+?)(?:=("|'|)(.*?)("|'|))?\]`
)

// M returns VirtualElement
func M(selector string, opts ...interface{}) *VirtualElement {
	// new VirtualElement channel
	c := make(chan *VirtualElement)
	// create element in go routine
	go func() {
		// declare query string
		query := "div"
		// replace query as div if selector does not existed
		if selector != "" {
			query = selector
		}
		// create virtual element
		element := &VirtualElement{"div", []Attribute{}, nil}
		// map options
		for i, opt := range opts {
			switch obj := opt.(type) {
			case []Attribute:
				if i == 0 {
					element.Attrs = obj
				}
			case string, bool, int, *VirtualElement, []interface{}:
				element.Children = obj
			}
		}
		// match all results
		matches := regexp.MustCompile(Parser)
		for _, res := range matches.FindAllStringSubmatch(query, -1) {
			if res[1] == "" && len(res[2]) > 0 {
				element.Tag = strings.ToLower(res[2])
			} else if res[1] == "#" {
				element.Attr("id", res[2])
			} else if res[1] == "." {
				if !element.HasAttr("class") {
					element.Attrs = append(element.Attrs, Class(res[2]))
				} else {
					element.Attr("class", res[2])
				}
			} else if string(res[3][0]) == "[" {
				matches := regexp.MustCompile(AttrParser)
				for _, pair := range matches.FindAllStringSubmatch(res[3], -1) {
					if len(pair[1]) > 0 {
						element.Attrs = append(element.Attrs, NewStringAttr(pair[1], pair[3]))
					}
				}
			}
		}
		c <- element
	}()
	// return virtual element
	return <-c
}

// Render returns HTML string
func Render(elements ...interface{}) string {
	html := ""
	for _, element := range elements {
		switch obj := element.(type) {
		case Component:
			obj.Controller()
			html += fmt.Sprintf("%s", obj.View())
		case []interface{}:
			for _, item := range obj {
				html += Render(item)
			}
		case *VirtualElement:
			html += obj.String()
		case string:
			html += obj
		case int, int8, int32, int64, uint:
			html += fmt.Sprintf("%d", obj)
		case float32, float64:
			html += fmt.Sprintf("%f", obj)
		}
	}
	return html
}<commit_msg>update pass-in data type list<commit_after>package mithril

import (
	"fmt"
	"regexp"
	"strings"
)

const (
	// Parser is the tags regex parser
	Parser = `(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])`
	// AttrParser is the attribute regex parser
	AttrParser = `\[(.+?)(?:=("|'|)(.*?)("|'|))?\]`
)

// M returns VirtualElement
func M(selector string, opts ...interface{}) *VirtualElement {
	// new VirtualElement channel
	c := make(chan *VirtualElement)
	// create element in go routine
	go func() {
		// declare query string
		query := "div"
		// replace query as div if selector does not existed
		if selector != "" {
			query = selector
		}
		// create virtual element
		element := &VirtualElement{"div", []Attribute{}, nil}
		// map options
		for i, opt := range opts {
			switch obj := opt.(type) {
			case []Attribute:
				if i == 0 {
					element.Attrs = obj
				}
			case string, bool, int, int8, int32, int64, uint, uint8, uint32, uint64, float32, float64, complex64, *VirtualElement, *Component, []interface{}:
				element.Children = obj
			}
		}
		// match all results
		matches := regexp.MustCompile(Parser)
		for _, res := range matches.FindAllStringSubmatch(query, -1) {
			if res[1] == "" && len(res[2]) > 0 {
				element.Tag = strings.ToLower(res[2])
			} else if res[1] == "#" {
				element.Attr("id", res[2])
			} else if res[1] == "." {
				if !element.HasAttr("class") {
					element.Attrs = append(element.Attrs, Class(res[2]))
				} else {
					element.Attr("class", res[2])
				}
			} else if string(res[3][0]) == "[" {
				matches := regexp.MustCompile(AttrParser)
				for _, pair := range matches.FindAllStringSubmatch(res[3], -1) {
					if len(pair[1]) > 0 {
						element.Attrs = append(element.Attrs, NewStringAttr(pair[1], pair[3]))
					}
				}
			}
		}
		c <- element
	}()
	// return virtual element
	return <-c
}

// Render returns HTML string
func Render(elements ...interface{}) string {
	html := ""
	for _, element := range elements {
		switch obj := element.(type) {
		case Component:
			obj.Controller()
			html += fmt.Sprintf("%s", obj.View())
		case []interface{}:
			for _, item := range obj {
				html += Render(item)
			}
		case *VirtualElement:
			html += obj.String()
		case string:
			html += obj
		case bool:
			html += fmt.Sprintf("%t", obj)
		case int, int8, int32, int64, uint, uint8, uint32, uint64:
			html += fmt.Sprintf("%d", obj)
		case float32, float64, complex64:
			html += fmt.Sprintf("%f", obj)
		}
	}
	return html
}
{'fraction_non_alphanumeric': 0.18448239510858105, 'fraction_numerical': 0.016656124815517606, 'mean_word_length': 2.9899074852817495, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '851654', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1620, 'n_words': 432}