<commit_before>package ilium

import "encoding/json"
import "io/ioutil"

func ParseConfig(inputPath string) (
	config map[string]interface{}, err error) {
	configBytes, err := ioutil.ReadFile(inputPath)
	if err != nil {
		return
	}
	err = json.Unmarshal(configBytes, &config)
	if err != nil {
		config = nil
		return
	}
	return
}<commit_msg>Process include directives in config files<commit_after>package ilium

import "encoding/json"
import "errors"
import "io/ioutil"

func rawParseConfig(inputPath string) (
	config map[string]interface{}, err error) {
	configBytes, err := ioutil.ReadFile(inputPath)
	if err != nil {
		return
	}
	err = json.Unmarshal(configBytes, &config)
	if err != nil {
		config = nil
		return
	}
	return
}

func processIncludes(config interface{}, depth int) (
	newConfig interface{}, err error) {
	if depth >= 10 {
		err = errors.New("Include depth limit exceeded")
		return
	}

	switch typedConfig := config.(type) {
	case map[string]interface{}:
		if includeConfig, ok := typedConfig["_include"]; ok {
			includePath := includeConfig.(string)
			newConfig, err = parseConfigRecursively(
				includePath, depth+1)
			if err != nil {
				newConfig = nil
			}
			return
		}

		for k, v := range typedConfig {
			v, err = processIncludes(v, depth)
			if err != nil {
				return
			}
			typedConfig[k] = v
		}

	case []interface{}:
		for i, v := range typedConfig {
			v, err = processIncludes(v, depth)
			if err != nil {
				return
			}
			typedConfig[i] = v
		}
	}

	newConfig = config
	return
}

func parseConfigRecursively(inputPath string, depth int) (
	config map[string]interface{}, err error) {
	config, err = rawParseConfig(inputPath)
	if err != nil {
		return
	}
	var processedConfig interface{}
	processedConfig, err = processIncludes(config, 0)
	if err != nil {
		config = nil
		return
	}
	config = processedConfig.(map[string]interface{})
	return
}

func ParseConfig(inputPath string) (config map[string]interface{}, err error) {
	return parseConfigRecursively(inputPath, 0)
}
{'fraction_non_alphanumeric': 0.11823149528067561, 'fraction_numerical': 0.0024838549428713363, 'mean_word_length': 3.9484029484029484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5346603', 'n_tokens_mistral': 738, 'n_tokens_neox': 664, 'n_words': 185}