@@ -25,74 +25,135 @@ use crate::token::Token;
2525pub type ParseResult < T > = Result < T , ParseError > ;
2626
2727#[ derive( Debug , PartialEq ) ]
28+ /// Errors encountered during the lexical and syntactic analysis of Clarity source code
29+ /// when constructing the abstract syntax tree (AST).
2830pub enum ParseErrorKind {
29- // Cost errors
31+ // Cost-related errors
32+ /// Arithmetic overflow in cost computation during AST construction, exceeding the maximum threshold.
3033 CostOverflow ,
34+ /// Cumulative parsing cost exceeds the allocated budget, indicating budget depletion rather than an overflow.
3135 CostBalanceExceeded ( ExecutionCost , ExecutionCost ) ,
36+ /// Memory usage during AST construction exceeds the allocated memory budget.
3237 MemoryBalanceExceeded ( u64 , u64 ) ,
38+ /// Failure in the cost-tracking mechanism due to an unexpected condition or invalid state.
3339 CostComputationFailed ( String ) ,
40+ /// Parsing time exceeds the allowed budget, halting AST construction to ensure responsiveness.
3441 ExecutionTimeExpired ,
3542
43+ // Structural errors
44+ /// Number of expressions exceeds the maximum allowed limit.
3645 TooManyExpressions ,
46+ /// Nesting depth of expressions exceeds the allowed stack depth limit.
3747 ExpressionStackDepthTooDeep ,
48+ /// Nesting depth of expressions exceeds the allowed stack depth limit.
3849 VaryExpressionStackDepthTooDeep ,
50+
51+ // Semantic errors
52+ /// Failed to parse a string into an integer literal.
3953 FailedParsingIntValue ( String ) ,
54+ /// Circular reference detected in interdependent function definitions.
4055 CircularReference ( Vec < String > ) ,
56+ /// Variable name is already in use within the same scope.
4157 NameAlreadyUsed ( String ) ,
58+ /// Attempt to store a trait reference, which is prohibited to ensure type safety and deterministic execution.
4259 TraitReferenceNotAllowed ,
60+ /// Invalid or malformed signature in a `(use-trait ...)` expression.
4361 ImportTraitBadSignature ,
62+ /// Invalid or malformed signature in a `(define-trait ...)` expression.
4463 DefineTraitBadSignature ,
64+ /// Invalid or malformed signature in a `(impl-trait ...)` expression.
4565 ImplTraitBadSignature ,
66+ /// Referenced trait does not exist or cannot be found.
4667 TraitReferenceUnknown ( String ) ,
4768
48- // V1 errors
69+ // V1 Errors
70+ /// Failed to capture an expected substring or value during pattern matching in lexical analysis.
4971 FailedCapturingInput ,
72+ /// Expected a whitespace or a close parentheses but found an unexpected token or character.
5073 SeparatorExpected ( String ) ,
74+ /// Expected a whitespace after a colon, but found an unexpected token.
5175 SeparatorExpectedAfterColon ( String ) ,
76+ /// Input program exceeds the maximum allowed number of lines.
5277 ProgramTooLarge ,
78+ /// Variable name contains invalid characters or violates naming rules.
5379 IllegalVariableName ( String ) ,
80+ /// Failed to parse a string into a buffer literal.
5481 FailedParsingBuffer ( String ) ,
82+ /// Failed to parse a string into a hexadecimal value, with the input string and error details.
5583 FailedParsingHexValue ( String , String ) ,
84+ /// Failed to parse a string into a principal literal (e.g., invalid principal format).
5685 FailedParsingPrincipal ( String ) ,
86+ /// Failed to parse a string into a valid field literal.
5787 FailedParsingField ( String ) ,
88+ /// Failed to parse the remaining input after processing a construct, leaving invalid or unexpected tokens.
5889 FailedParsingRemainder ( String ) ,
90+ /// Unexpected closing parenthesis encountered in the input.
5991 ClosingParenthesisUnexpected ,
92+ /// Expected a closing parenthesis but found another token or end of input.
6093 ClosingParenthesisExpected ,
94+ /// Unexpected closing brace for a tuple literal encountered in the input.
6195 ClosingTupleLiteralUnexpected ,
96+ /// Expected a closing brace for a tuple literal but it was missing.
6297 ClosingTupleLiteralExpected ,
98+ /// Expected a colon in a tuple literal at the specified position, but it was missing.
6399 TupleColonExpected ( usize ) ,
100+ /// Expected a comma in a tuple literal at the specified position, but it was missing.
64101 TupleCommaExpected ( usize ) ,
102+ /// Expected a tuple item (e.g., key-value pair) at the specified position, but it was missing or invalid.
65103 TupleItemExpected ( usize ) ,
104+ /// Unexpected comma separator encountered outside a valid list or tuple context.
66105 CommaSeparatorUnexpected ,
106+ /// Unexpected colon separator encountered.
67107 ColonSeparatorUnexpected ,
108+ /// Input contains invalid or disallowed characters.
68109 InvalidCharactersDetected ,
110+ /// Invalid escape sequence in a string literal (e.g., incorrect use of `\`).
69111 InvalidEscaping ,
70112
71- // V2 Errors
113+ // V2 Errors
114+ /// Lexical analysis failed due to an underlying lexer error.
72115 Lexer ( LexerError ) ,
116+ /// Contract name exceeds the maximum allowed length.
73117 ContractNameTooLong ( String ) ,
118+ /// Expected a specific closing token (e.g., parenthesis or brace) but found another token.
74119 ExpectedClosing ( Token ) ,
120+ /// Expected a contract identifier (e.g., `.contract-name`) but found an invalid or missing token.
75121 ExpectedContractIdentifier ,
122+ /// Expected a trait identifier (e.g., `.trait-name`) but found an invalid or missing token.
76123 ExpectedTraitIdentifier ,
124+ /// Expected whitespace to separate tokens but found an unexpected token or character.
77125 ExpectedWhitespace ,
126+ /// Failed to parse a string into an unsigned integer literal.
78127 FailedParsingUIntValue ( String ) ,
128+ /// Trait name contains invalid characters or violates naming rules.
79129 IllegalTraitName ( String ) ,
130+ /// Invalid principal literal format, preventing parsing into a valid principal.
80131 InvalidPrincipalLiteral ,
132+ /// Invalid buffer literal format, preventing parsing into a valid buffer.
81133 InvalidBuffer ,
134+ /// Name (e.g., variable or function) exceeds the maximum allowed length.
82135 NameTooLong ( String ) ,
136+ /// Encountered an unexpected token during parsing.
83137 UnexpectedToken ( Token ) ,
138+ /// Expected a colon in a tuple literal (version 2 syntax) but it was missing.
84139 TupleColonExpectedv2 ,
140+ /// Expected a comma in a tuple literal (version 2 syntax) but it was missing.
85141 TupleCommaExpectedv2 ,
142+ /// Expected a value in a tuple literal but it was missing or invalid.
86143 TupleValueExpected ,
144+ /// Clarity name (e.g., variable, function, or trait) contains invalid characters or violates naming rules.
87145 IllegalClarityName ( String ) ,
146+ /// ASCII string literal contains invalid characters or violates format rules.
88147 IllegalASCIIString ( String ) ,
148+ /// Contract name contains invalid characters or violates naming rules.
89149 IllegalContractName ( String ) ,
150+
90151 // Notes
152+ /// Indicates a token mismatch, used for internal parser diagnostics to match a specific token.
91153 NoteToMatchThis ( Token ) ,
92- /// Should be an unreachable error
154+ /// Unreachable error indicating an unexpected parser failure; should never occur in valid execution.
93155 UnexpectedParserFailure ,
94-
95- /// Should be an unreachable failure which invalidates the transaction
156+ /// Unreachable failure indicating an invalid transaction due to an unexpected interpreter error.
96157 InterpreterFailure ,
97158}
98159
0 commit comments