diff --git a/M6502/M6502.Symbols/Parser.cs b/M6502/M6502.Symbols/Parser.cs index 6d6bdbb..3bd51eb 100644 --- a/M6502/M6502.Symbols/Parser.cs +++ b/M6502/M6502.Symbols/Parser.cs @@ -57,10 +57,7 @@ public void AddLabel(Symbol symbol) { - if (symbol.Type != "lab") - { - throw new ArgumentOutOfRangeException(nameof(symbol), symbol, "Not a label"); - } + ArgumentOutOfRangeException.ThrowIfNotEqual("lab", symbol.Type, nameof(symbol)); this.Labels.Add(symbol); this.AddAddress(symbol); } @@ -108,10 +105,7 @@ public void AddEquate(Symbol symbol) { - if (symbol.Type != "equ") - { - throw new ArgumentOutOfRangeException(nameof(symbol), symbol, "Not an equate"); - } + ArgumentOutOfRangeException.ThrowIfNotEqual("equ", symbol.Type, nameof(symbol)); this.Equates.Add(symbol); this.AddConstant(symbol); } @@ -315,7 +309,7 @@ if (!this._parsed.TryGetValue(key, out var parsed)) { - throw new InvalidOperationException($"Debugging section: '{key}' is unavailable"); + throw new ArgumentOutOfRangeException(nameof(key), key, "Debugging section is unavailable"); } Debug.Assert(into.Count == 0); @@ -409,11 +403,8 @@ private void ParseLine(string[] elements) { - Debug.Assert(elements != null); - if (elements.Length != 2) - { - throw new InvalidOperationException("Invalid symbol file format (definition does not have section/values format)"); - } + ArgumentNullException.ThrowIfNull(elements, nameof(elements)); + ArgumentOutOfRangeException.ThrowIfNotEqual(elements.Length, 2, nameof(elements)); var key = elements[0]; var parts = elements[1].Split(','); diff --git a/M6502/M6502.Symbols/Section.cs b/M6502/M6502.Symbols/Section.cs index 2696795..34ec13c 100644 --- a/M6502/M6502.Symbols/Section.cs +++ b/M6502/M6502.Symbols/Section.cs @@ -95,10 +95,10 @@ protected string? MaybeTakeString(string key) => this._strings.TryGetValue(key, out var value) ? value : null; protected List? MaybeTakeMultiple(string key) => this._multiples.TryGetValue(key, out var value) ? value : null; - protected int TakeInteger(string key) => this.MaybeTakeInteger(key) ?? throw new InvalidOperationException($"Section is missing an integer entry named {key}"); - protected long TakeLong(string key) => this.MaybeTakeLong(key) ?? throw new InvalidOperationException($"Section is missing a long integer entry named {key}"); - protected string TakeString(string key) => this.MaybeTakeString(key) ?? throw new InvalidOperationException($"Section is missing a string entry named {key}"); - protected List TakeMultiple(string key) => this.MaybeTakeMultiple(key) ?? throw new InvalidOperationException($"Section is missing a multiple entry named {key}"); + protected int TakeInteger(string key) => this.MaybeTakeInteger(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing integer entry in section"); + protected long TakeLong(string key) => this.MaybeTakeLong(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing long integer entry in section"); + protected string TakeString(string key) => this.MaybeTakeString(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing string entry in section"); + protected List TakeMultiple(string key) => this.MaybeTakeMultiple(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing multiple entry in section"); protected static string ExtractString(string value) => value.Trim('"'); protected static string ExtractEnumeration(string value) => value; @@ -111,6 +111,7 @@ protected static int ExtractInteger(string value) => ExtractNumericValue(value); protected static long ExtractLong(string value) => ExtractNumericValue(value); protected static List ExtractCompoundString(string value) => new(value.Split('+')); + protected static List ExtractCompoundInteger(string value) { var elements = ExtractCompoundString(value);