2022-07-01 14:01:15 +00:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
2022-09-30 19:03:06 +00:00
|
|
|
use dioxus_core::OwnedCodeLocation;
|
2022-05-31 17:03:04 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
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 {
|
2022-10-02 21:12:24 +00:00
|
|
|
Variable(String),
|
|
|
|
Expression(String),
|
|
|
|
Component(String),
|
|
|
|
Listener(String),
|
|
|
|
Attribute(String),
|
2022-05-29 13:04:08 +00:00
|
|
|
}
|
2022-06-15 17:58:08 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct ParseError {
|
|
|
|
pub message: String,
|
2022-09-30 19:03:06 +00:00
|
|
|
pub location: OwnedCodeLocation,
|
2022-06-15 17:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ParseError {
|
2022-09-30 19:03:06 +00:00
|
|
|
pub fn new(error: syn::Error, mut location: OwnedCodeLocation) -> Self {
|
2022-06-15 17:58:08 +00:00
|
|
|
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 }
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 14:01:15 +00:00
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2022-07-03 03:45:32 +00:00
|
|
|
Error::ParseError(error) => writeln!(
|
2022-07-01 14:01:15 +00:00
|
|
|
f,
|
2022-07-03 03:45:32 +00:00
|
|
|
"parse error:\n--> at {}:{}:{}\n\t{:?}",
|
2022-07-01 14:01:15 +00:00
|
|
|
error.location.file_path, error.location.line, error.location.column, error.message
|
|
|
|
),
|
|
|
|
Error::RecompileRequiredError(reason) => {
|
2022-07-03 03:45:32 +00:00
|
|
|
writeln!(f, "recompile required: {:?}", reason)
|
2022-07-01 14:01:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|