Skip to content

Commit

Permalink
Add trimming support and dynamic access attributes.
Browse files Browse the repository at this point in the history
Also move to file-scoped namespaces everywhere.

Closes #49
  • Loading branch information
SamboyCoding committed Dec 22, 2024
1 parent 4393f63 commit 289d7ce
Show file tree
Hide file tree
Showing 72 changed files with 2,713 additions and 2,560 deletions.
11 changes: 5 additions & 6 deletions Tomlet/Attributes/TomlNonSerializedAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;

namespace Tomlet.Attributes
namespace Tomlet.Attributes;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class TomlNonSerializedAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class TomlNonSerializedAttribute : Attribute
{
}
}
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/InvalidTomlDateTimeException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class InvalidTomlDateTimeException : TomlExceptionWithLine
{
private readonly string _inputString;
namespace Tomlet.Exceptions;

public InvalidTomlDateTimeException(int lineNumber, string inputString) : base(lineNumber)
{
_inputString = inputString;
}
public class InvalidTomlDateTimeException : TomlExceptionWithLine
{
private readonly string _inputString;

public override string Message => $"Found an invalid TOML date/time string '{_inputString}' on line {LineNumber}";
public InvalidTomlDateTimeException(int lineNumber, string inputString) : base(lineNumber)
{
_inputString = inputString;
}

public override string Message => $"Found an invalid TOML date/time string '{_inputString}' on line {LineNumber}";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/InvalidTomlEscapeException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class InvalidTomlEscapeException : TomlExceptionWithLine
{
private readonly string _escapeSequence;
namespace Tomlet.Exceptions;

public InvalidTomlEscapeException(int lineNumber, string escapeSequence) : base(lineNumber)
{
_escapeSequence = escapeSequence;
}
public class InvalidTomlEscapeException : TomlExceptionWithLine
{
private readonly string _escapeSequence;

public override string Message => $"Found an invalid escape sequence '\\{_escapeSequence}' on line {LineNumber}";
public InvalidTomlEscapeException(int lineNumber, string escapeSequence) : base(lineNumber)
{
_escapeSequence = escapeSequence;
}

public override string Message => $"Found an invalid escape sequence '\\{_escapeSequence}' on line {LineNumber}";
}
13 changes: 6 additions & 7 deletions Tomlet/Exceptions/InvalidTomlInlineTableException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class InvalidTomlInlineTableException : TomlExceptionWithLine
{
public class InvalidTomlInlineTableException : TomlExceptionWithLine
public InvalidTomlInlineTableException(int lineNumber, TomlException cause) : base(lineNumber, cause)
{
public InvalidTomlInlineTableException(int lineNumber, TomlException cause) : base(lineNumber, cause)
{
}

public override string Message => $"Found an invalid inline TOML table on line {LineNumber}. See further down for cause.";
}

public override string Message => $"Found an invalid inline TOML table on line {LineNumber}. See further down for cause.";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/InvalidTomlKeyException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class InvalidTomlKeyException : TomlException
{
private readonly string _key;
namespace Tomlet.Exceptions;

public InvalidTomlKeyException(string key)
{
_key = key;
}
public class InvalidTomlKeyException : TomlException
{
private readonly string _key;

public override string Message => $"The string |{_key}| (between the two bars) contains at least one of both a double quote and a single quote, so it cannot be used for a TOML key.";
public InvalidTomlKeyException(string key)
{
_key = key;
}

public override string Message => $"The string |{_key}| (between the two bars) contains at least one of both a double quote and a single quote, so it cannot be used for a TOML key.";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/InvalidTomlNumberException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class InvalidTomlNumberException : TomlExceptionWithLine
{
private readonly string _input;
namespace Tomlet.Exceptions;

public InvalidTomlNumberException(int lineNumber, string input) : base(lineNumber)
{
_input = input;
}
public class InvalidTomlNumberException : TomlExceptionWithLine
{
private readonly string _input;

public override string Message => $"While reading input line {LineNumber}, found an invalid number literal '{_input}'";
public InvalidTomlNumberException(int lineNumber, string input) : base(lineNumber)
{
_input = input;
}

public override string Message => $"While reading input line {LineNumber}, found an invalid number literal '{_input}'";
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class MissingIntermediateInTomlTableArraySpecException : TomlExceptionWithLine
{
private readonly string _missing;
namespace Tomlet.Exceptions;

public MissingIntermediateInTomlTableArraySpecException(int lineNumber, string missing) : base(lineNumber)
{
_missing = missing;
}
public class MissingIntermediateInTomlTableArraySpecException : TomlExceptionWithLine
{
private readonly string _missing;

public override string Message => $"Missing intermediate definition for {_missing} in table-array specification on line {LineNumber}. This is undefined behavior, and I chose to define it as an error.";
public MissingIntermediateInTomlTableArraySpecException(int lineNumber, string missing) : base(lineNumber)
{
_missing = missing;
}

public override string Message => $"Missing intermediate definition for {_missing} in table-array specification on line {LineNumber}. This is undefined behavior, and I chose to define it as an error.";
}
13 changes: 6 additions & 7 deletions Tomlet/Exceptions/NewLineInTomlInlineTableException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class NewLineInTomlInlineTableException : TomlExceptionWithLine
{
public class NewLineInTomlInlineTableException : TomlExceptionWithLine
public NewLineInTomlInlineTableException(int lineNumber) : base(lineNumber)
{
public NewLineInTomlInlineTableException(int lineNumber) : base(lineNumber)
{
}

public override string Message => "Found a new-line character within a TOML inline table. This is not allowed.";
}

public override string Message => "Found a new-line character within a TOML inline table. This is not allowed.";
}
11 changes: 5 additions & 6 deletions Tomlet/Exceptions/NoTomlKeyException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class NoTomlKeyException : TomlExceptionWithLine
{
public class NoTomlKeyException : TomlExceptionWithLine
{
public NoTomlKeyException(int lineNumber) : base(lineNumber) { }
public NoTomlKeyException(int lineNumber) : base(lineNumber) { }

public override string Message => $"Expected a TOML key on line {LineNumber}, but found an equals sign ('=').";
}
public override string Message => $"Expected a TOML key on line {LineNumber}, but found an equals sign ('=').";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/TimeOffsetOnTomlDateOrTimeException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class TimeOffsetOnTomlDateOrTimeException : TomlExceptionWithLine
{
private readonly string _tzString;
namespace Tomlet.Exceptions;

public TimeOffsetOnTomlDateOrTimeException(int lineNumber, string tzString) : base(lineNumber)
{
_tzString = tzString;
}
public class TimeOffsetOnTomlDateOrTimeException : TomlExceptionWithLine
{
private readonly string _tzString;

public override string Message => $"Found a time offset string {_tzString} in a partial datetime on line {LineNumber}. This is not allowed - either specify both the date and the time, or remove the offset specifier.";
public TimeOffsetOnTomlDateOrTimeException(int lineNumber, string tzString) : base(lineNumber)
{
_tzString = tzString;
}

public override string Message => $"Found a time offset string {_tzString} in a partial datetime on line {LineNumber}. This is not allowed - either specify both the date and the time, or remove the offset specifier.";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/TomlArraySyntaxException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class TomlArraySyntaxException : TomlExceptionWithLine
{
private readonly char _charFound;
namespace Tomlet.Exceptions;

public TomlArraySyntaxException(int lineNumber, char charFound) : base(lineNumber)
{
_charFound = charFound;
}
public class TomlArraySyntaxException : TomlExceptionWithLine
{
private readonly char _charFound;

public override string Message => $"Expecting ',' or ']' after value in array on line {LineNumber}, found '{_charFound}'";
public TomlArraySyntaxException(int lineNumber, char charFound) : base(lineNumber)
{
_charFound = charFound;
}

public override string Message => $"Expecting ',' or ']' after value in array on line {LineNumber}, found '{_charFound}'";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/TomlContainsDottedKeyNonTableException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class TomlContainsDottedKeyNonTableException : TomlException
{
internal readonly string Key;
namespace Tomlet.Exceptions;

public TomlContainsDottedKeyNonTableException(string key)
{
Key = key;
}
public class TomlContainsDottedKeyNonTableException : TomlException
{
internal readonly string Key;

public override string Message => $"A call was made on a TOML table which attempted to access a sub-key of {Key}, but the value it refers to is not a table";
public TomlContainsDottedKeyNonTableException(string key)
{
Key = key;
}

public override string Message => $"A call was made on a TOML table which attempted to access a sub-key of {Key}, but the value it refers to is not a table";
}
13 changes: 6 additions & 7 deletions Tomlet/Exceptions/TomlDateTimeMissingSeparatorException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class TomlDateTimeMissingSeparatorException : TomlExceptionWithLine
{
public class TomlDateTimeMissingSeparatorException : TomlExceptionWithLine
public TomlDateTimeMissingSeparatorException(int lineNumber) : base(lineNumber)
{
public TomlDateTimeMissingSeparatorException(int lineNumber) : base(lineNumber)
{
}

public override string Message => $"Found a date-time on line {LineNumber} which is missing a separator (T, t, or a space) between the date and time.";
}

public override string Message => $"Found a date-time on line {LineNumber} which is missing a separator (T, t, or a space) between the date and time.";
}
13 changes: 6 additions & 7 deletions Tomlet/Exceptions/TomlDateTimeUnnecessarySeparatorException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class TomlDateTimeUnnecessarySeparatorException : TomlExceptionWithLine
{
public class TomlDateTimeUnnecessarySeparatorException : TomlExceptionWithLine
public TomlDateTimeUnnecessarySeparatorException(int lineNumber) : base(lineNumber)
{
public TomlDateTimeUnnecessarySeparatorException(int lineNumber) : base(lineNumber)
{
}

public override string Message => $"Found an unnecessary date-time separator (T, t, or a space) in a date or time on line {LineNumber}";
}

public override string Message => $"Found an unnecessary date-time separator (T, t, or a space) in a date or time on line {LineNumber}";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/TomlDottedKeyException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class TomlDottedKeyException : TomlException
{
private readonly string _key;
namespace Tomlet.Exceptions;

public TomlDottedKeyException(string key)
{
_key = key;
}
public class TomlDottedKeyException : TomlException
{
private readonly string _key;

public override string Message => $"Tried to redefine key {_key} as a table (by way of a dotted key) when it's already defined as not being a table.";
public TomlDottedKeyException(string key)
{
_key = key;
}

public override string Message => $"Tried to redefine key {_key} as a table (by way of a dotted key) when it's already defined as not being a table.";
}
19 changes: 9 additions & 10 deletions Tomlet/Exceptions/TomlDottedKeyParserException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Tomlet.Exceptions
{
public class TomlDottedKeyParserException : TomlExceptionWithLine
{
private readonly string _key;
namespace Tomlet.Exceptions;

public TomlDottedKeyParserException(int lineNumber, string key) : base(lineNumber)
{
_key = key;
}
public class TomlDottedKeyParserException : TomlExceptionWithLine
{
private readonly string _key;

public override string Message => $"Tried to redefine key {_key} as a table (by way of a dotted key on line {LineNumber}) when it's already defined as not being a table.";
public TomlDottedKeyParserException(int lineNumber, string key) : base(lineNumber)
{
_key = key;
}

public override string Message => $"Tried to redefine key {_key} as a table (by way of a dotted key on line {LineNumber}) when it's already defined as not being a table.";
}
13 changes: 6 additions & 7 deletions Tomlet/Exceptions/TomlEndOfFileException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Tomlet.Exceptions
namespace Tomlet.Exceptions;

public class TomlEndOfFileException : TomlExceptionWithLine
{
public class TomlEndOfFileException : TomlExceptionWithLine
public TomlEndOfFileException(int lineNumber) : base(lineNumber)
{
public TomlEndOfFileException(int lineNumber) : base(lineNumber)
{
}

public override string Message => $"Found unexpected EOF on line {LineNumber} when parsing TOML file";
}

public override string Message => $"Found unexpected EOF on line {LineNumber} when parsing TOML file";
}
Loading

0 comments on commit 289d7ce

Please sign in to comment.