MCPcopy Create free account
hub / github.com/hashintel/hash / unexpected_eof

Function unexpected_eof

libs/@local/hashql/syntax-jexpr/src/lexer/error.rs:115–148  ·  view source on GitHub ↗
(span: SpanId, expected: SyntaxKindSet)

Source from the content-addressed store, hash-verified

113}
114
115pub(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
150pub(crate) fn unexpected_token(
151 span: SpanId,

Callers 4

advanceMethod · 0.85
peek_expectMethod · 0.85
error_in_callbackFunction · 0.85
error_in_callbackFunction · 0.85

Calls 9

is_completeMethod · 0.80
primaryMethod · 0.80
contains_separatorMethod · 0.80
contains_valueMethod · 0.80
add_messageMethod · 0.80
is_emptyMethod · 0.45
to_ownedMethod · 0.45

Tested by 2

error_in_callbackFunction · 0.68
error_in_callbackFunction · 0.68