<commit_before>// Package jsonconfig is a super tiny (pseudo) JSON configuration parser for Go with support for comments.

// <NAME>, http://nadh.in/code/jsonconfig
// Jan 2015
// MIT License

package jsonconfig

import (
	"regexp"
	"encoding/json"
	"io/ioutil"
	"errors"
)

func Load(filename string, config interface{})  error {
	// read file
	data, err := ioutil.ReadFile(filename)
	if(err != nil) {
		return errors.New("Error reading file")
	}

	// regex monstrosity because of the lack of lookbehinds/aheads
	// stand alone comments
	r1, _ := regexp.Compile(`(?m)^(\s+)?//(.*)$`)

	// numbers and boolean
	r2, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?([0-9\.\-]+|true|false|null)(\s+)?,(\s+)?//(.*)$`)

	// strings
	r3, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?"(.+?)"(\s+)?,(\s+)?//(.*)$`)

	// arrays and objects
	r4, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?([\{\[])(.+?)([\}\]])(\s+)?,(\s+)?//(.*)$`)
	

	res := r1.ReplaceAllString(string(data), "")
	res = r2.ReplaceAllString(res, `"$1": $3,`)
	res = r3.ReplaceAllString(res, `"$1": "$3",`)
	res = r4.ReplaceAllString(res, `"$1": $3$4$5,`)

	// decode json
	if err := json.Unmarshal([]byte(res), &config); err != nil {
		return err
	}

	return nil
}<commit_msg>Idiomatic comments<commit_after>// Package jsonconfig is a super tiny (pseudo) JSON configuration parser for Go with support for comments.

// <NAME>, http://nadh.in/code/jsonconfig
// Jan 2015
// MIT License

package jsonconfig

import (
	"encoding/json"
	"errors"
	"io/ioutil"
	"regexp"
)

func Load(filename string, config interface{}) error {
	// Read the config file.
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return errors.New("Error reading file")
	}

	// Regex monstrosity because of the lack of lookbehinds/aheads.

	// Standalone comments.
	r1, _ := regexp.Compile(`(?m)^(\s+)?//(.*)$`)

	// Numbers and boolean.
	r2, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?([0-9\.\-]+|true|false|null)(\s+)?,(\s+)?//(.*)$`)

	// Strings.
	r3, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?"(.+?)"(\s+)?,(\s+)?//(.*)$`)

	// Arrays and objects.
	r4, _ := regexp.Compile(`(?m)"(.+?)":(\s+)?([\{\[])(.+?)([\}\]])(\s+)?,(\s+)?//(.*)$`)

	res := r1.ReplaceAllString(string(data), "")
	res = r2.ReplaceAllString(res, `"$1": $3,`)
	res = r3.ReplaceAllString(res, `"$1": "$3",`)
	res = r4.ReplaceAllString(res, `"$1": $3$4$5,`)

	// Decode json.
	if err := json.Unmarshal([]byte(res), &config); err != nil {
		return err
	}

	return nil
}
{'fraction_non_alphanumeric': 0.27480604328297265, 'fraction_numerical': 0.01796651694569212, 'mean_word_length': 3.738878143133462, 'pattern_counts': {'":': 12, '<': 5, '<?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': '4460032', 'n_tokens_mistral': 1036, 'n_tokens_neox': 973, 'n_words': 201}