Skip to main content

arity_parser/parser/
diagnostics.rs

1use crate::parser::lexer::Token;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct ParseDiagnostic {
5    pub message: String,
6    pub start: usize,
7    pub end: usize,
8}
9
10/// Reported when two expressions sit side by side in a statement list with no
11/// newline or `;` between them. R calls this "unexpected <constant>"; the
12/// wording here names the missing separator instead, matching the parser's
13/// other "expected ..." messages.
14pub(crate) const MISSING_STATEMENT_SEPARATOR: &str = "expected a newline or ';' between statements";
15
16pub(crate) fn push_diagnostic(
17    diagnostics: &mut Vec<ParseDiagnostic>,
18    message: &str,
19    start: usize,
20    end: usize,
21) {
22    diagnostics.push(ParseDiagnostic {
23        message: message.to_string(),
24        start,
25        end,
26    });
27}
28
29pub(crate) fn push_token_diagnostic(
30    diagnostics: &mut Vec<ParseDiagnostic>,
31    message: &str,
32    token: &Token,
33) {
34    push_diagnostic(diagnostics, message, token.start, token.end);
35}