1
0

error.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. use serde::{Deserialize, Serialize};
  2. use crate::CodeLocation;
  3. /// An error produced when interperting the rsx
  4. #[derive(Debug, Serialize, Deserialize)]
  5. pub enum Error {
  6. ParseError(ParseError),
  7. RecompileRequiredError(RecompileReason),
  8. }
  9. #[derive(Debug, Serialize, Deserialize)]
  10. pub enum RecompileReason {
  11. CapturedVariable(String),
  12. CapturedExpression(String),
  13. CapturedComponent(String),
  14. CapturedListener(String),
  15. }
  16. #[derive(Debug, Serialize, Deserialize)]
  17. pub struct ParseError {
  18. pub message: String,
  19. pub location: CodeLocation,
  20. }
  21. impl ParseError {
  22. pub fn new(error: syn::Error, mut location: CodeLocation) -> Self {
  23. let message = error.to_string();
  24. let syn_call_site = error.span().start();
  25. location.line += syn_call_site.line as u32;
  26. if syn_call_site.line == 0 {
  27. location.column += syn_call_site.column as u32;
  28. } else {
  29. location.column = syn_call_site.column as u32;
  30. }
  31. location.column += 1;
  32. ParseError { message, location }
  33. }
  34. }