<commit_before>package compiler

import (
	"bytes"
	"regexp"
	"strings"
)

var stringModifierRe = regexp.MustCompile(`((\[(LSHIFT|LCTRL|LALT|LMETA|RSHIFT|RCTRL|RALT|RMETA)\]>)+(\w+))+`)
var charModifierRe = regexp.MustCompile(`((\w+)+(\[(LSHIFT|LCTRL|LALT|LMETA|RSHIFT|RCTRL|RALT|RMETA)\]:)+(\w+))+`)

func Compile(s string) string {
	l := newLinkedList()

	for _, word := range strings.Split(s, " ") {
		l.insertToken(tokenize(word))
	}

	node := l.getFirst()
	var buf bytes.Buffer
	for node.Next != nil {
		d := node.Data
		if d.StringModifier.Modifier != NOMOD {
			buf.WriteString(generateHIDPayloadForString(d.StringModifier))
		} else if d.CharacterModifier.Modifier != NOMOD {
			buf.WriteString(generateHIDPayloadForCharacter(d.CharacterModifier))
		} else {
			buf.WriteString(generateHIDPayloadForStandardString(d.RealString))
		}
		node = *node.Next
	}

	return buf.String()
}

func tokenize(s string) token {
	if matchStringModifier(s) {
		return tokenizeStringModifier(s)
	}

	if matchCharModifier(s) {
		return tokenizeCharModifier(s)
	}

	return token{
		RawString:         s,
		RealString:        s,
		StringModifier:    stringModifier{StringRef: "", Modifier: NOMOD},
		CharacterModifier: characterModifier{CharRef: ' ', Modifier: NOMOD},
	}
}<commit_msg>add a space for every string, minus the last one<commit_after>package compiler

import (
	"bytes"
	"regexp"
	"strings"
)

var stringModifierRe = regexp.MustCompile(`((\[(LSHIFT|LCTRL|LALT|LMETA|RSHIFT|RCTRL|RALT|RMETA)\]>)+(\w+))+`)
var charModifierRe = regexp.MustCompile(`((\w+)+(\[(LSHIFT|LCTRL|LALT|LMETA|RSHIFT|RCTRL|RALT|RMETA)\]:)+(\w+))+`)

func Compile(s string) string {
	l := newLinkedList()

	for _, word := range strings.Split(s, " ") {
		l.insertToken(tokenize(word))
	}

	node := l.getFirst()
	var buf bytes.Buffer
	for node.Next != nil {
		d := node.Data
		if d.StringModifier.Modifier != NOMOD {
			buf.WriteString(generateHIDPayloadForString(d.StringModifier))
		} else if d.CharacterModifier.Modifier != NOMOD {
			buf.WriteString(generateHIDPayloadForCharacter(d.CharacterModifier))
		} else {
			buf.WriteString(generateHIDPayloadForStandardString(d.RealString))
		}

		if node.Next != nil {
			buf.WriteString(generateHIDPayloadForSpace())
		}
		node = *node.Next
	}

	return buf.String()
}

func tokenize(s string) token {
	if matchStringModifier(s) {
		return tokenizeStringModifier(s)
	}

	if matchCharModifier(s) {
		return tokenizeCharModifier(s)
	}

	return token{
		RawString:         s,
		RealString:        s,
		StringModifier:    stringModifier{StringRef: "", Modifier: NOMOD},
		CharacterModifier: characterModifier{CharRef: ' ', Modifier: NOMOD},
	}
}
{'fraction_non_alphanumeric': 0.14866390666164847, 'fraction_numerical': 0.0, 'mean_word_length': 4.790849673202614, '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': '5679349', 'n_tokens_mistral': 1017, 'n_tokens_neox': 979, 'n_words': 161}