You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GrammarFormatExceptions.cs 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. namespace LLama.Exceptions;
  3. /// <summary>
  4. /// Base class for all grammar exceptions
  5. /// </summary>
  6. public abstract class GrammarFormatException
  7. : Exception
  8. {
  9. internal GrammarFormatException(string message)
  10. : base(message)
  11. {
  12. }
  13. }
  14. /// <summary>
  15. /// An incorrect number of characters were encountered while parsing a hex literal
  16. /// </summary>
  17. public class GrammarUnexpectedHexCharsCount
  18. : GrammarFormatException
  19. {
  20. internal GrammarUnexpectedHexCharsCount(int size, string source)
  21. : base($"Expecting {size} hex chars at {source}")
  22. {
  23. }
  24. }
  25. /// <summary>
  26. /// Failed to parse a "name" element when one was expected
  27. /// </summary>
  28. public class GrammarExpectedName
  29. : GrammarFormatException
  30. {
  31. internal GrammarExpectedName(string source)
  32. : base($"Expecting name at {source}")
  33. {
  34. }
  35. }
  36. /// <summary>
  37. /// An unexpected character was encountered after an escape sequence
  38. /// </summary>
  39. public class GrammarUnknownEscapeCharacter
  40. : GrammarFormatException
  41. {
  42. internal GrammarUnknownEscapeCharacter(string source)
  43. : base($"Unknown escape at {source}")
  44. {
  45. }
  46. }
  47. /// <summary>
  48. /// End-of-file was encountered while parsing
  49. /// </summary>
  50. public class GrammarUnexpectedEndOfInput
  51. : GrammarFormatException
  52. {
  53. internal GrammarUnexpectedEndOfInput()
  54. : base($"Unexpected end of input")
  55. {
  56. }
  57. }
  58. /// <summary>
  59. /// A specified string was expected when parsing
  60. /// </summary>
  61. public class GrammarExpectedNext
  62. : GrammarFormatException
  63. {
  64. internal GrammarExpectedNext(string expected, string source)
  65. : base($"Expected '{expected}' at {source}")
  66. {
  67. }
  68. }
  69. /// <summary>
  70. /// A specified character was expected to preceded another when parsing
  71. /// </summary>
  72. public class GrammarExpectedPrevious
  73. : GrammarFormatException
  74. {
  75. internal GrammarExpectedPrevious(string expected, string source)
  76. : base($"Expecting preceding item to be '{expected}' at {source}")
  77. {
  78. }
  79. }
  80. /// <summary>
  81. /// A CHAR_ALT was created without a preceding CHAR element
  82. /// </summary>
  83. public class GrammarUnexpectedCharAltElement
  84. : GrammarFormatException
  85. {
  86. internal GrammarUnexpectedCharAltElement(string ruleId, int index)
  87. : base($"LLamaGrammarElementType.CHAR_ALT without preceding char: {ruleId},{index}")
  88. {
  89. }
  90. }
  91. /// <summary>
  92. /// A CHAR_RNG was created without a preceding CHAR element
  93. /// </summary>
  94. public class GrammarUnexpectedCharRngElement
  95. : GrammarFormatException
  96. {
  97. internal GrammarUnexpectedCharRngElement(string ruleId, int index)
  98. : base($"LLamaGrammarElementType.CHAR_RNG_UPPER without preceding char: {ruleId},{index}")
  99. {
  100. }
  101. }
  102. /// <summary>
  103. /// An END was encountered before the last element
  104. /// </summary>
  105. public class GrammarUnexpectedEndElement
  106. : GrammarFormatException
  107. {
  108. internal GrammarUnexpectedEndElement(string ruleId, int index)
  109. : base($"Unexpected LLamaGrammarElementType.END: {ruleId},{index}")
  110. {
  111. }
  112. }