From a8e85be303effe8bce9e2f4fba6022f453af4003 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Sch=C3=BCtt?=
Date: Fri, 15 Nov 2024 18:34:52 +0100
Subject: [PATCH] Add *Owned to CSS error types
---
azul-core/src/xml.rs | 147 ++--
azul-css-parser/src/css.rs | 321 ++++++++-
azul-css-parser/src/css_parser.rs | 1094 +++++++++++++++++++++++++++++
azul-css/src/css.rs | 22 +
4 files changed, 1486 insertions(+), 98 deletions(-)
diff --git a/azul-core/src/xml.rs b/azul-core/src/xml.rs
index 20a6ac6fc..9aec01411 100644
--- a/azul-core/src/xml.rs
+++ b/azul-core/src/xml.rs
@@ -6,11 +6,15 @@ use crate::styled_dom::StyledDom;
use crate::window::{AzStringPair, StringPairVec};
use alloc::collections::BTreeMap;
use azul_css::{
- AzString, Css, CssDeclaration, CssPath, CssPathPseudoSelector, CssPathSelector, CssProperty, CssRuleBlock, NodeTypeTag, NormalizedLinearColorStopVec, NormalizedRadialColorStopVec, OptionAzString, StyleBackgroundContentVec, StyleBackgroundPositionVec, StyleBackgroundRepeatVec, StyleBackgroundSizeVec, StyleFontFamilyVec, StyleTransformVec, U8Vec
+ AzString, Css, CssDeclaration, CssPath, CssPathPseudoSelector,
+ CssPathSelector, CssProperty, CssRuleBlock, NodeTypeTag, NormalizedLinearColorStopVec,
+ NormalizedRadialColorStopVec, OptionAzString, StyleBackgroundContentVec,
+ StyleBackgroundPositionVec, StyleBackgroundRepeatVec, StyleBackgroundSizeVec,
+ StyleFontFamilyVec, StyleTransformVec, U8Vec
};
use azul_css_parser::ErrorLocation;
#[cfg(feature = "css_parser")]
-use azul_css_parser::{CssApiWrapper, CssParseError};
+use azul_css_parser::{CssApiWrapper, CssParseErrorOwned};
use core::fmt;
/// Error that can happen during hot-reload -
@@ -438,17 +442,24 @@ impl ComponentArguments {
/// Specifies a component that reacts to a parsed XML node
pub trait XmlComponentTrait {
+ /// Returns the type ID of this component, default = `div`
+ fn get_type_id(&self) -> String {
+ "div".to_string()
+ }
+
/// Given a root node and a list of possible arguments, returns a DOM or a syntax error
- fn render_dom<'a>(
- &'a self,
- components: &'a XmlComponentMap,
+ fn render_dom(
+ &self,
+ components: &XmlComponentMap,
arguments: &FilteredComponentArguments,
content: &XmlTextContent,
- ) -> Result>;
+ ) -> Result;
/// Returns the XML node for this component, used in the `get_html_string` debugging code
/// (necessary to compile the component into a function during the Rust compilation stage)
- fn get_xml_node<'a>(&'a self) -> &'a XmlNode;
+ fn get_xml_node(&self) -> XmlNode {
+ XmlNode::new(self.get_type_id())
+ }
/// (Optional): Should return all arguments that this component can take - for example if you have a
/// component called `Calendar`, which can take a `selectedDate` argument:
@@ -537,10 +548,10 @@ impl DomXml {
/// ```
#[cfg(test)]
pub fn assert_eq(self, other: StyledDom) {
- let fixed = StyledDom::body().append(other);
+ let fixed = Dom::body().style(CssApiWrapper::empty()).append(other);
if self.parsed_dom != fixed {
panic!("\r\nExpected DOM did not match:\r\n\r\nexpected: ----------\r\n{}\r\ngot: ----------\r\n{}\r\n",
- expected.get_html_string(), fixed.get_html_string()
+ self.parsed_dom.get_html_string("", "", true), fixed.get_html_string("", "", true)
);
}
}
@@ -648,7 +659,7 @@ impl XmlComponentMap {
}
#[derive(Debug, Clone, PartialEq)]
-pub enum DomXmlParseError<'a> {
+pub enum DomXmlParseError {
/// No `` node component present
NoHtmlNode,
/// Multiple `` nodes
@@ -665,33 +676,33 @@ pub enum DomXmlParseError<'a> {
/// Invalid hierarchy close tags, i.e `
`
MalformedHierarchy(AzString, AzString),
/// A component raised an error while rendering the DOM - holds the component name + error string
- RenderDom(RenderDomError<'a>),
+ RenderDom(RenderDomError),
/// Something went wrong while parsing an XML component
- Component(ComponentParseError<'a>),
+ Component(ComponentParseError),
/// Error parsing global CSS in head node
- Css(CssParseError<'a>),
+ Css(CssParseErrorOwned),
}
-impl<'a> From for DomXmlParseError<'a> {
+impl From for DomXmlParseError {
fn from(e: XmlError) -> Self {
Self::Xml(e)
}
}
-impl<'a> From> for DomXmlParseError<'a> {
- fn from(e: ComponentParseError<'a>) -> Self {
+impl From for DomXmlParseError {
+ fn from(e: ComponentParseError) -> Self {
Self::Component(e)
}
}
-impl<'a> From> for DomXmlParseError<'a> {
- fn from(e: RenderDomError<'a>) -> Self {
+impl From for DomXmlParseError {
+ fn from(e: RenderDomError) -> Self {
Self::RenderDom(e)
}
}
-impl<'a> From> for DomXmlParseError<'a> {
- fn from(e: CssParseError<'a>) -> Self {
+impl From for DomXmlParseError {
+ fn from(e: CssParseErrorOwned) -> Self {
Self::Css(e)
}
}
@@ -699,43 +710,43 @@ impl<'a> From> for DomXmlParseError<'a> {
/// Error that can happen from the translation from XML code to Rust code -
/// stringified, since it is only used for printing and is not exposed in the public API
#[derive(Debug, Clone, PartialEq)]
-pub enum CompileError<'a> {
- Dom(RenderDomError<'a>),
- Xml(DomXmlParseError<'a>),
- Css(CssParseError<'a>),
+pub enum CompileError {
+ Dom(RenderDomError),
+ Xml(DomXmlParseError),
+ Css(CssParseErrorOwned),
}
-impl<'a> From for CompileError<'a> {
+impl From for CompileError {
fn from(e: ComponentError) -> Self {
CompileError::Dom(RenderDomError::Component(e))
}
}
-impl<'a> From> for CompileError<'a> {
- fn from(e: CssParseError<'a>) -> Self {
+impl From for CompileError {
+ fn from(e: CssParseErrorOwned) -> Self {
CompileError::Css(e)
}
}
-impl<'a> fmt::Display for CompileError<'a> {
+impl<'a> fmt::Display for CompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::CompileError::*;
match self {
Dom(d) => write!(f, "{}", d),
Xml(s) => write!(f, "{}", s),
- Css(s) => write!(f, "{}", s),
+ Css(s) => write!(f, "{}", s.to_shared()),
}
}
}
-impl<'a> From> for CompileError<'a> {
- fn from(e: RenderDomError<'a>) -> Self {
+impl From for CompileError {
+ fn from(e: RenderDomError) -> Self {
CompileError::Dom(e)
}
}
-impl<'a> From> for CompileError<'a> {
- fn from(e: DomXmlParseError<'a>) -> Self {
+impl From for CompileError {
+ fn from(e: DomXmlParseError) -> Self {
CompileError::Xml(e)
}
}
@@ -753,26 +764,26 @@ pub enum ComponentError {
}
#[derive(Debug, Clone, PartialEq)]
-pub enum RenderDomError<'a> {
+pub enum RenderDomError {
Component(ComponentError),
/// Error parsing the CSS on the component style
- CssError(CssParseError<'a>),
+ CssError(CssParseErrorOwned),
}
-impl<'a> From for RenderDomError<'a> {
+impl From for RenderDomError {
fn from(e: ComponentError) -> Self {
Self::Component(e)
}
}
-impl<'a> From> for RenderDomError<'a> {
- fn from(e: CssParseError<'a>) -> Self {
+impl From for RenderDomError {
+ fn from(e: CssParseErrorOwned) -> Self {
Self::CssError(e)
}
}
#[derive(Debug, Clone, PartialEq)]
-pub enum ComponentParseError<'a> {
+pub enum ComponentParseError {
/// Given XmlNode is not a `` node.
NotAComponent,
/// A `` node does not have a `name` attribute.
@@ -789,10 +800,10 @@ pub enum ComponentParseError<'a> {
/// (probably missing a `,` between the type and the next name)
WhiteSpaceInComponentType(usize, AzString, AzString),
/// Error parsing the