<commit_before>﻿using System;
using System.Collections.Generic;

namespace Ardenian.Libraries.CSharp.ExpressionParser.Data
{
    public abstract class ParserData<T> : IParserData<T>, IConvertible<T>
    {
        public abstract IDictionary<string, T> Variables { get; }
        public abstract IDictionary<string, Func<T, T, T>> Operators { get; }
        public abstract IDictionary<string, Func<T[], T>> Functions { get; }

        public T GetParameterOrParseString(string s)
        {
            if (Variables != null && Variables.Count > 0 && Variables.ContainsKey(s))
            {
                return Variables[s];
            }
            return Parse(s);
        }

        public abstract T Parse(string s);
        public abstract bool TryParse(string s, out T result);
    }
}<commit_msg>Throwing an exception when a string cannot be parsed, providing the string itself and some initial ideas<commit_after>﻿using System;
using System.Collections.Generic;

namespace Ardenian.Libraries.CSharp.ExpressionParser.Data
{
    public abstract class ParserData<T> : IParserData<T>, IConvertible<T>
    {
        public abstract IDictionary<string, T> Variables { get; }
        public abstract IDictionary<string, Func<T, T, T>> Operators { get; }
        public abstract IDictionary<string, Func<T[], T>> Functions { get; }

        public T GetParameterOrParseString(string s)
        {
            if (Variables != null && Variables.Count > 0 && Variables.ContainsKey(s))
            {
                return Variables[s];
            }
            if (!TryParse(s, out T result))
            {
                throw new ParserException($"Couldn't parse \"{s}\". Did you forget a bracket or are you missing a ParserData entry, like variables or functions?");
            }
            return result;
        }

        public abstract T Parse(string s);
        public abstract bool TryParse(string s, out T result);
    }
}
{'fraction_non_alphanumeric': 0.09757356737222508, 'fraction_numerical': 0.0010325245224574084, 'mean_word_length': 2.4731182795698925, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '5454710', 'n_tokens_mistral': 532, 'n_tokens_neox': 509, 'n_words': 163}