| 113 | } |
| 114 | |
| 115 | pub(crate) fn unexpected_eof(span: SpanId, expected: SyntaxKindSet) -> LexerDiagnostic { |
| 116 | // Create a more specific label based on what was expected |
| 117 | let label = if expected.is_empty() || expected.is_complete() { |
| 118 | "Unexpected end of file".to_owned() |
| 119 | } else { |
| 120 | format!( |
| 121 | "Unexpected end of file, expected {}", |
| 122 | expected.display(Some(Conjunction::Or)) |
| 123 | ) |
| 124 | }; |
| 125 | |
| 126 | let mut diagnostic = Diagnostic::new(LexerDiagnosticCategory::UnexpectedEof, Critical::ERROR) |
| 127 | .primary(Label::new(span, label)); |
| 128 | |
| 129 | // Provide specific help based on what was expected |
| 130 | let help = if expected.contains_closing_delimiter() { |
| 131 | "Missing closing bracket. Make sure all opening brackets have matching closing brackets." |
| 132 | } else if expected.contains_separator() { |
| 133 | "The file ended while parsing an object or array. Make sure all structures are properly \ |
| 134 | closed." |
| 135 | } else if expected.contains_value() { |
| 136 | "The file ended where a value was expected. Add a valid JSON value (string, number, \ |
| 137 | object, array, true, false, or null)." |
| 138 | } else if expected.contains_opening_delimiter() { |
| 139 | "The file ended where an opening bracket was expected. Complete the expression structure." |
| 140 | } else { |
| 141 | "The file ended unexpectedly. Make sure all expressions, brackets, and string literals are \ |
| 142 | properly closed." |
| 143 | }; |
| 144 | |
| 145 | diagnostic.add_message(Message::help(Cow::Borrowed(help))); |
| 146 | |
| 147 | diagnostic |
| 148 | } |
| 149 | |
| 150 | pub(crate) fn unexpected_token( |
| 151 | span: SpanId, |