| 130 | } |
| 131 | |
| 132 | pub fn unexpected_ident(diagnostic: &Diagnostic, source: &str) -> DiagnosticMeta { |
| 133 | let cursor = diagnostic.start_cursor; |
| 134 | let start = cursor.offset().0 as usize; |
| 135 | let len = cursor.token().len() as usize; |
| 136 | let message = if start + len <= source.len() { |
| 137 | let text = &source[start..start + len]; |
| 138 | format!("Unexpected identifier '{text}'") |
| 139 | } else { |
| 140 | "Unexpected identifier".to_string() |
| 141 | }; |
| 142 | DiagnosticMeta { |
| 143 | code: "UnexpectedIdent", |
| 144 | message, |
| 145 | help: "There is an extra word which shouldn't be in this position.".into(), |
| 146 | labels: vec![], |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | pub fn unexpected_delim(diagnostic: &Diagnostic, _source: &str) -> DiagnosticMeta { |
| 151 | let cursor = diagnostic.start_cursor; |