<commit_before>package astgen

import (
	"strconv"
	"fmt"
)

type parser struct {
	file []byte
	line int
}


func Load(data []byte) (def *LangDef, e error) {
	var p parser
	p.line = 0
	p.file = data

	defer func() {
		err := recover()
		if err != nil {
			def = nil
			e = fmt.Errorf("Error on line %d: %s\n", p.line, err)
		}
	}()
	
	def = new(LangDef)
	def.Types = make(map[string]Type)
	
	for !p.finished() {
		t := p.parse_type()
		def.Types[t.Common().Name] = t
	}
	
	return def, nil
}
<commit_msg>Improve error reporting.<commit_after>package astgen

import (
	"strconv"
	"fmt"
)

type parser struct {
	file []byte
	line int
}


func Load(data []byte) (def *LangDef, e error) {
	var p parser
	p.line = 0
	p.file = data

	defer func() {
		err := recover()
		if err != nil {
			def = nil
			e = fmt.Errorf("Error on line %d: %s\nNext 20 bytes: %s\n", p.line, err, string(p.file[:20]))
		}
	}()
	
	def = new(LangDef)
	def.Types = make(map[string]Type)
	
	for !p.finished() {
		t := p.parse_type()
		def.Types[t.Common().Name] = t
	}
	
	return def, nil
}

{'fraction_non_alphanumeric': 0.1693472090823084, 'fraction_numerical': 0.005676442762535478, 'mean_word_length': 2.9185185185185185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1288655', 'n_tokens_mistral': 474, 'n_tokens_neox': 433, 'n_words': 118}