using System; namespace LLama.Exceptions; /// /// Base class for all grammar exceptions /// public abstract class GrammarFormatException : Exception { internal GrammarFormatException(string message) : base(message) { } } /// /// An incorrect number of characters were encountered while parsing a hex literal /// public class GrammarUnexpectedHexCharsCount : GrammarFormatException { internal GrammarUnexpectedHexCharsCount(int size, string source) : base($"Expecting {size} hex chars at {source}") { } } /// /// Failed to parse a "name" element when one was expected /// public class GrammarExpectedName : GrammarFormatException { internal GrammarExpectedName(string source) : base($"Expecting name at {source}") { } } /// /// An unexpected character was encountered after an escape sequence /// public class GrammarUnknownEscapeCharacter : GrammarFormatException { internal GrammarUnknownEscapeCharacter(string source) : base($"Unknown escape at {source}") { } } /// /// End-of-file was encountered while parsing /// public class GrammarUnexpectedEndOfInput : GrammarFormatException { internal GrammarUnexpectedEndOfInput() : base($"Unexpected end of input") { } } /// /// A specified string was expected when parsing /// public class GrammarExpectedNext : GrammarFormatException { internal GrammarExpectedNext(string expected, string source) : base($"Expected '{expected}' at {source}") { } } /// /// A specified character was expected to preceded another when parsing /// public class GrammarExpectedPrevious : GrammarFormatException { internal GrammarExpectedPrevious(string expected, string source) : base($"Expecting preceding item to be '{expected}' at {source}") { } } /// /// A CHAR_ALT was created without a preceding CHAR element /// public class GrammarUnexpectedCharAltElement : GrammarFormatException { internal GrammarUnexpectedCharAltElement(string ruleId, int index) : base($"LLamaGrammarElementType.CHAR_ALT without preceding char: {ruleId},{index}") { } } /// /// A CHAR_RNG was created without a preceding CHAR element /// public class GrammarUnexpectedCharRngElement : GrammarFormatException { internal GrammarUnexpectedCharRngElement(string ruleId, int index) : base($"LLamaGrammarElementType.CHAR_RNG_UPPER without preceding char: {ruleId},{index}") { } } /// /// An END was encountered before the last element /// public class GrammarUnexpectedEndElement : GrammarFormatException { internal GrammarUnexpectedEndElement(string ruleId, int index) : base($"Unexpected LLamaGrammarElementType.END: {ruleId},{index}") { } }