2022-07-01 09:01:15 -05:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
2022-05-31 12:03:04 -05:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-06-15 12:58:08 -05:00
|
|
|
use crate::CodeLocation;
|
|
|
|
|
2022-06-11 20:06:50 -05:00
|
|
|
/// An error produced when interperting the rsx
|
2022-06-15 12:58:08 -05:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2022-05-29 08:04:08 -05:00
|
|
|
pub enum Error {
|
2022-06-15 12:58:08 -05:00
|
|
|
ParseError(ParseError),
|
2022-05-29 08:04:08 -05:00
|
|
|
RecompileRequiredError(RecompileReason),
|
|
|
|
}
|
|
|
|
|
2022-05-31 12:03:04 -05:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2022-05-29 08:04:08 -05:00
|
|
|
pub enum RecompileReason {
|
|
|
|
CapturedVariable(String),
|
|
|
|
CapturedExpression(String),
|
|
|
|
CapturedComponent(String),
|
|
|
|
CapturedListener(String),
|
2022-07-01 10:51:11 -05:00
|
|
|
CapturedAttribute(String),
|
2022-05-29 08:04:08 -05:00
|
|
|
}
|
2022-06-15 12:58:08 -05:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct ParseError {
|
|
|
|
pub message: String,
|
|
|
|
pub location: CodeLocation,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ParseError {
|
|
|
|
pub fn new(error: syn::Error, mut location: CodeLocation) -> Self {
|
|
|
|
let message = error.to_string();
|
|
|
|
let syn_call_site = error.span().start();
|
|
|
|
location.line += syn_call_site.line as u32;
|
2022-06-15 13:36:18 -05:00
|
|
|
if syn_call_site.line == 0 {
|
2022-06-15 12:58:08 -05:00
|
|
|
location.column += syn_call_site.column as u32;
|
2022-06-15 13:36:18 -05:00
|
|
|
} else {
|
2022-06-15 12:58:08 -05:00
|
|
|
location.column = syn_call_site.column as u32;
|
|
|
|
}
|
2022-06-15 13:36:18 -05:00
|
|
|
location.column += 1;
|
2022-06-15 12:58:08 -05:00
|
|
|
ParseError { message, location }
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 09:01:15 -05:00
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2022-07-02 23:45:32 -04:00
|
|
|
Error::ParseError(error) => writeln!(
|
2022-07-01 09:01:15 -05:00
|
|
|
f,
|
2022-07-02 23:45:32 -04:00
|
|
|
"parse error:\n--> at {}:{}:{}\n\t{:?}",
|
2022-07-01 09:01:15 -05:00
|
|
|
error.location.file_path, error.location.line, error.location.column, error.message
|
|
|
|
),
|
|
|
|
Error::RecompileRequiredError(reason) => {
|
2022-07-02 23:45:32 -04:00
|
|
|
writeln!(f, "recompile required: {:?}", reason)
|
2022-07-01 09:01:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|