2022-05-31 17:03:04 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-06-15 17:58:08 +00:00
|
|
|
use crate::CodeLocation;
|
|
|
|
|
2022-06-12 01:06:50 +00:00
|
|
|
/// An error produced when interperting the rsx
|
2022-06-15 17:58:08 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2022-05-29 13:04:08 +00:00
|
|
|
pub enum Error {
|
2022-06-15 17:58:08 +00:00
|
|
|
ParseError(ParseError),
|
2022-05-29 13:04:08 +00:00
|
|
|
RecompileRequiredError(RecompileReason),
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:03:04 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2022-05-29 13:04:08 +00:00
|
|
|
pub enum RecompileReason {
|
|
|
|
CapturedVariable(String),
|
|
|
|
CapturedExpression(String),
|
|
|
|
CapturedComponent(String),
|
|
|
|
CapturedListener(String),
|
|
|
|
}
|
2022-06-15 17:58:08 +00: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 18:36:18 +00:00
|
|
|
if syn_call_site.line == 0 {
|
2022-06-15 17:58:08 +00:00
|
|
|
location.column += syn_call_site.column as u32;
|
2022-06-15 18:36:18 +00:00
|
|
|
} else {
|
2022-06-15 17:58:08 +00:00
|
|
|
location.column = syn_call_site.column as u32;
|
|
|
|
}
|
2022-06-15 18:36:18 +00:00
|
|
|
location.column += 1;
|
2022-06-15 17:58:08 +00:00
|
|
|
ParseError { message, location }
|
|
|
|
}
|
|
|
|
}
|