diff --git a/ConfigParser.cs b/ConfigParser.cs index 2727fb8e70422a1d1c45aebdd115f5de95e7cecc..ffae239bccefb6dc56c7eb1d78b6ad6d9d2ceb69 100644 --- a/ConfigParser.cs +++ b/ConfigParser.cs @@ -71,8 +71,8 @@ class ConfigDuplicitKeyException: ConfigDuplicitException } class ConfigNoAmenException: ConfigException { - public ConfigKeyValue Value; - public ConfigNoAmenException(ConfigKeyValue value):base(value.Section.Root) + public ConfigOption Value; + public ConfigNoAmenException(ConfigOption value):base(value.Section.Root) { Value = value; } @@ -83,9 +83,9 @@ class ConfigNoAmenException: ConfigException } class ConfigMixedTabException: ConfigException { - public ConfigKeyValue Value; + public ConfigOption Value; public int Line; - public ConfigMixedTabException(ConfigKeyValue value, int line):base(value.Section.Root) + public ConfigMixedTabException(ConfigOption value, int line):base(value.Section.Root) { Value = value; Line = line; @@ -97,9 +97,9 @@ class ConfigMixedTabException: ConfigException } class ConfigWrongIndentException: ConfigException { - public ConfigKeyValue? Value; + public ConfigOption? Value; public int Line; - public ConfigWrongIndentException(ConfigSection section, ConfigKeyValue? value, int line):base(section.Root) + public ConfigWrongIndentException(ConfigSection section, ConfigOption? value, int line):base(section.Root) { Value = value; Line = line; @@ -153,8 +153,8 @@ class ConfigNoValueException: ConfigException } class ConfigUnusedOptionException: ConfigException { - public ConfigKeyValue Value; - public ConfigUnusedOptionException(ConfigKeyValue value):base(value.Root) + public ConfigOption Value; + public ConfigUnusedOptionException(ConfigOption value):base(value.Root) { Value = value; } @@ -311,14 +311,14 @@ abstract class ConfigValue } public static implicit operator string(ConfigValue v) => v.AsString(); } -class ConfigKeyValue: ConfigValue +class ConfigOption: ConfigValue { public ConfigSection Section {get; init;} internal string? amen; internal string? tabs; public string Key {get; init;} public bool Used = false; - public ConfigKeyValue Use() + public ConfigOption Use() { Used = true; return this; @@ -327,7 +327,7 @@ class ConfigKeyValue: ConfigValue { get => Section.SectionName != null ? $"{Section.SectionName}: {Key}" : Key; } - internal ConfigKeyValue(ConfigSection _Section, string _Key, int _line):base(_Section.Root) + internal ConfigOption(ConfigSection _Section, string _Key, int _line):base(_Section.Root) { Section = _Section; Key = _Key; @@ -342,7 +342,7 @@ class ConfigKeyAsValue: ConfigValue { get => (Section.SectionName != null ? $"{Section.SectionName}: " : "") + $"Key {Value}"; } - internal ConfigKeyAsValue(ConfigKeyValue keyValue):base(keyValue.Root) + internal ConfigKeyAsValue(ConfigOption keyValue):base(keyValue.Root) { Line = keyValue.Line; Value = keyValue.Key; @@ -375,13 +375,13 @@ class ConfigSectionNameAsDefaultValue: ConfigSectionNameAsValue get => base.FullName + $" as default for \"{defaultFor}\" option"; } } -class ConfigSection: IReadOnlyList<ConfigKeyValue> +class ConfigSection: IReadOnlyList<ConfigOption> { public ConfigParser Root {get; init;} public string? SectionName {get; init;} public int Line; - List<ConfigKeyValue> values = new(); - Dictionary<string, ConfigKeyValue> valueByName = new(); + List<ConfigOption> values = new(); + Dictionary<string, ConfigOption> valueByName = new(); public bool Used = false; public ConfigSection Use() { @@ -394,14 +394,14 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue> SectionName = _SectionName; Line = _line; } - internal void Add(ConfigKeyValue v) + internal void Add(ConfigOption v) { if(valueByName.ContainsKey(v.Key)) throw new ConfigDuplicitKeyException(this, v.Key, v.Line, valueByName[v.Key].Line); valueByName[v.Key] = v; values.Add(v); } - public IEnumerator<ConfigKeyValue> GetEnumerator() + public IEnumerator<ConfigOption> GetEnumerator() { foreach(var s in values) yield return s; @@ -409,15 +409,15 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue> System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public int Count{ get{return values.Count;}} - public ConfigKeyValue this[int i] + public ConfigOption this[int i] { get { return values[i]; } } - public ConfigKeyValue? this[string key] + public ConfigOption? this[string key] { get { return Optional(key); } } - public ConfigKeyValue? Optional(string key) + public ConfigOption? Optional(string key) { if(!valueByName.TryGetValue(key, out var r)) return null; @@ -427,7 +427,7 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue> { return (ConfigValue?)Optional(key) ?? new ConfigSectionNameAsDefaultValue(this, key); } - public ConfigKeyValue Mandatory(string key) + public ConfigOption Mandatory(string key) { if(!valueByName.TryGetValue(key, out var r)) throw new ConfigNotDefinedException(this, key); @@ -448,7 +448,7 @@ class ConfigSection: IReadOnlyList<ConfigKeyValue> public ConfigSectionNameAsValue SectionNameAsValue() => new(this); public void CheckUnused() { - foreach(ConfigKeyValue it in this) + foreach(ConfigOption it in this) { if(it.Used == false) throw new ConfigUnusedOptionException(it); @@ -466,7 +466,7 @@ class ConfigParser: IReadOnlyList<ConfigSection> FileName = _FileName; string[] lines = s.Split("\n"); var currentSection = MainSection = new(this, null, 0); - ConfigKeyValue? lastVal = null; + ConfigOption? lastVal = null; for(int i=0;i<lines.Count();i++) { string l = lines[i]; @@ -519,12 +519,12 @@ class ConfigParser: IReadOnlyList<ConfigSection> int indexArrow = l.IndexOf("<<"); if(indexIs == -1 && indexArrow == -1) { - currentSection.Add(lastVal = new ConfigKeyValue(currentSection, tl, firstLineIndex + i)); + currentSection.Add(lastVal = new ConfigOption(currentSection, tl, firstLineIndex + i)); continue; } int index = indexIs == -1 ? indexArrow : indexArrow == -1 ? indexIs : Math.Min(indexIs, indexArrow); string key = l[0..index].Trim(); - currentSection.Add(lastVal = new ConfigKeyValue(currentSection, key, firstLineIndex + i)); + currentSection.Add(lastVal = new ConfigOption(currentSection, key, firstLineIndex + i)); if(indexIs != -1 && (indexArrow == -1 || indexIs < indexArrow)) { string val = l[(indexIs+1)..].Trim();